70 assert(
false &&
"kind not found!");
81 if ( attributeStr ==
"")
return symbol;
83 if ( (attributeStr.size() == 1) && (
std::isalpha(attributeStr[attributeStr.size()-1])) )
89 for(
char &c : attributeStr)
94 <<
" Attribute:" << attributeStr <<
" (only number or single alphabet.)";
95 assert(
false &&
"grammar loading failed!");
98 symbol.
attribute = std::stoi(attributeStr);
109 if (i.second == kind)
119 if (ni.second == kind)
129 if (i.second == kind)
147 if (i.second == kind)
153 key.append(std::to_string(attribute));
162 if (ni.second == kind)
168 nkey.append(std::to_string(attribute));
211 auto underscorePosition = symbolStr.find_last_of(
"_", symbolStr.size()-1);
212 if (underscorePosition == std::string::npos)
216 return symbolStr.substr(0, underscorePosition);
223 auto underscorePosition = symbolStr.find_last_of(
"_", symbolStr.size()-1);
224 if (underscorePosition == std::string::npos)
228 return symbolStr.substr(underscorePosition+1);
234 if ((symbolStr.size() == 1) && (!
isalpha(symbolStr[0])))
238 else if (
isupper(symbolStr[0]))
256 if ( attributeStr ==
"")
return symbol;
258 if ( (attributeStr.size() == 1) && (
std::isalpha(attributeStr[attributeStr.size()-1])) )
265 for(
char &c : attributeStr)
270 <<
" Attribute:" << attributeStr <<
" (only number or single alphabet.)";
271 assert(
false &&
"grammar loading failed!");
275 symbol.
attribute = std::stoi(attributeStr);
287 if ( attributeStr ==
"")
return symbol;
289 if ( (attributeStr.size() == 1) && (
std::isalpha(attributeStr[attributeStr.size()-1])) )
296 for(
char &c : attributeStr)
301 <<
" Attribute:" << attributeStr <<
" (only number or single alphabet.)";
302 assert(
false &&
"grammar loading failed!");
306 symbol.
attribute = std::stoi(attributeStr);
348 dump(
"Normailized_Grammar.txt");
353 std::ofstream gramFile(fileName);
354 gramFile <<
"Start Kind:\n";
357 gramFile <<
"Epsilon Production:\n";
358 std::vector<std::string> strV;
361 std::stringstream ss;
368 ss <<
symToStrDump(sym) <<
'(' << sym.kind <<
')' <<
' ';
370 strV.insert(strV.begin(), ss.str());
372 std::sort(strV.begin(), strV.end());
381 gramFile <<
"Single Production:\n";
385 for (
auto pro: symProPair.second)
387 std::stringstream ss;
396 ss <<
symToStrDump(sym) <<
'(' << sym.kind <<
')' <<
' ';
398 strV.insert(strV.begin(), ss.str());
401 std::sort(strV.begin(), strV.end());
410 gramFile <<
"Binary Production:\n";
414 for (
auto pro: symProPair.second)
416 std::stringstream ss;
426 ss <<
symToStrDump(sym) <<
'(' << sym.kind <<
')' <<
' ';
428 strV.insert(strV.begin(), ss.str());
431 std::sort(strV.begin(), strV.end());
SymbolMap< Symbol, Productions > firstRHSToProds
SymbolSet< Production > epsilonProds
SymbolMap< Symbol, Productions > singleRHSToProds
u32_t newTerminalSubscript
Map< std::string, Kind > terminals
void setKindToAttrsMap(const Map< Kind, Set< Attribute >> &kindToAttrsMap)
std::string extractAttributeStrFromSymbolStr(const std::string &symbolStr) const
void setAttributeKinds(const Set< Kind > &attributeKind)
Symbol insertEBNFSigns(std::string strLit)
void setRawProductions(SymbolMap< Symbol, Productions > &rawProductions)
std::string extractKindStrFromSymbolStr(const std::string &symbolStr) const
Kind strToKind(std::string str) const
Symbol insertSymbol(std::string strLit)
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > SymbolMap
Symbol strToSymbol(const std::string str) const
std::string symToStrDump(Symbol sym) const
SymbolMap< Symbol, Productions > rawProductions
Symbol insertNonTerminalSymbol(std::string strLit)
Symbol insertTerminalSymbol(std::string strLit)
Map< Kind, Set< Attribute > > kindToAttrsMap
Map< std::string, Kind > EBNFSigns
void insertAttribute(Kind kind, Attribute a)
Map< std::string, Kind > nonterminals
Kind insertNonterminalKind(std::string const kindStr)
Insert kind to nonterminal and return kind.
Set< Kind > attributeKinds
Map contains Signs' String and associated Symbols.
std::string kindToStr(Kind kind) const
Kind insertTerminalKind(std::string strLit)
int isalpha(int character)
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
std::ostream & errs()
Overwrite llvm::errs()
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
VariableAttribute variableAttribute