72 assert(
false &&
"kind not found!");
83 if ( attributeStr ==
"")
return symbol;
85 if ( (attributeStr.size() == 1) && (std::isalpha(attributeStr[attributeStr.size()-1])) )
91 for(
char &c : attributeStr)
93 if ( std::isdigit(c) ==
false )
96 <<
" Attribute:" << attributeStr <<
" (only number or single alphabet.)";
97 assert(
false &&
"grammar loading failed!");
100 symbol.
attribute = std::stoi(attributeStr);
108 std::string key =
"";
111 if (i.second == kind)
118 std::string nkey =
"";
121 if (ni.second == kind)
128 std::string signs =
"";
131 if (i.second == kind)
146 std::string key =
"";
149 if (i.second == kind)
155 key.append(std::to_string(attribute));
161 std::string nkey =
"";
164 if (ni.second == kind)
170 nkey.append(std::to_string(attribute));
213 auto underscorePosition = symbolStr.find_last_of(
"_", symbolStr.size()-1);
214 if (underscorePosition == std::string::npos)
218 return symbolStr.substr(0, underscorePosition);
223 std::string attributeStr;
225 auto underscorePosition = symbolStr.find_last_of(
"_", symbolStr.size()-1);
226 if (underscorePosition == std::string::npos)
230 return symbolStr.substr(underscorePosition+1);
236 if ((symbolStr.size() == 1) && (!
isalpha(symbolStr[0])))
240 else if (
isupper(symbolStr[0]))
258 if ( attributeStr ==
"")
return symbol;
260 if ( (attributeStr.size() == 1) && (std::isalpha(attributeStr[attributeStr.size()-1])) )
267 for(
char &c : attributeStr)
269 if ( std::isdigit(c) ==
false )
272 <<
" Attribute:" << attributeStr <<
" (only number or single alphabet.)";
273 assert(
false &&
"grammar loading failed!");
277 symbol.
attribute = std::stoi(attributeStr);
289 if ( attributeStr ==
"")
return symbol;
291 if ( (attributeStr.size() == 1) && (std::isalpha(attributeStr[attributeStr.size()-1])) )
298 for(
char &c : attributeStr)
300 if ( std::isdigit(c) ==
false )
303 <<
" Attribute:" << attributeStr <<
" (only number or single alphabet.)";
304 assert(
false &&
"grammar loading failed!");
308 symbol.
attribute = std::stoi(attributeStr);
350 dump(
"Normailized_Grammar.txt");
355 std::ofstream gramFile(fileName);
356 gramFile <<
"Start Kind:\n";
359 gramFile <<
"Epsilon Production:\n";
360 std::vector<std::string> strV;
363 std::stringstream ss;
370 ss <<
symToStrDump(sym) <<
'(' << sym.kind <<
')' <<
' ';
372 strV.insert(strV.begin(), ss.str());
374 std::sort(strV.begin(), strV.end());
383 gramFile <<
"Single Production:\n";
387 for (
auto pro: symProPair.second)
389 std::stringstream ss;
398 ss <<
symToStrDump(sym) <<
'(' << sym.kind <<
')' <<
' ';
400 strV.insert(strV.begin(), ss.str());
403 std::sort(strV.begin(), strV.end());
412 gramFile <<
"Binary Production:\n";
416 for (
auto pro: symProPair.second)
418 std::stringstream ss;
428 ss <<
symToStrDump(sym) <<
'(' << sym.kind <<
')' <<
' ';
430 strV.insert(strV.begin(), ss.str());
433 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
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)
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< Key, Value, Hash, KeyEqual, Allocator > SymbolMap
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.
void setKindToAttrsMap(const Map< Kind, Set< Attribute > > &kindToAttrsMap)
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_set< Key, Hash, KeyEqual, Allocator > Set
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
VariableAttribute variableAttribute