CVersionInfoPÍÒDr. Detlef Meyer-EltzP©úÀParsergenerator and Interpreter1.6.0.1 Tetra.exe+Copyright © 2002 - 08 Dr. Detlef Meyer-Eltz Tetra.exeTextTransformer1.6.0EscapeCToken¸Ý¢EscapeS\\( \ [bfnrt'\\] \ // special |[0-7]{1,3} \ // octal ) IDENTIFIERCToken¨Ñ¡ IDENTIFIER\w+ IGNORABLECToken„Ò¡ IGNORABLEC(\s \// spaces |/\*[^*]*\*+([^/*][^*]*\*+)*/ \// block comment )+LCURLCToken`Ó¡LCURL%\{LEFTCTokenLÔ¡LEFT%leftLITERALCToken8Õ¡LITERAL ''([^'\\\r\n]*(({Escape})[^'\\\r\n]*)*)'MARKCToken$Ö¡MARK%%NONASSOCCToken סNONASSOC %nonassocNUMBERCToken,Ø¡NUMBER\d+PRECCTokenÙ¡PREC%precRCURLCTokenÚ¡RCURL%\}RIGHTCTokenðÚ¡RIGHT%rightRULENAMECTokenìÛ¡RULENAME([[:alpha:]._][\w._]*)\s*:STARTCTokenÝ¡START%startTOKENCTokenôÝ¡TOKEN%tokenTYPECTokenàÞ¡TYPE%typeUNIONCTokenÌß¡UNION%unionActionCProduction_LINKá¡Action!Copy Actionion translate $$ etc. '"{" ( Action | SKIP )* "}" AlternativeCProduction_LINKÜâ¡ Alternative€{{ dnode n; }} ( ( {{ dnode n1 = }} Element {{ if(!n1.value().empty()) { if(!n.value().empty()) n.addChildLast(n1); n = n1; } }} )+ Precedence? | Precedence {{ n.setLabel("SEM"); n.setValue("{{ }}"); }} ) {{ while(n.parent() != dnode::npos) n = n.parent(); return n; }} dnodeCodeCProduction_LINKüê¡CodeSKIP DeclarationCProduction_LINK€í¡ DeclarationCCopy union Declarationinition to output Copy C code to output file? StartDef | UnionDef | DefCode | TokenDecl | TypeDecl DeclarationsCProduction_LINK<ð¡ DeclarationsDeclaration+ DefCodeCProduction_LINKÌò¡DefCodeLCURL SKIP? RCURL ElementCProduction_LINK@õ¡Element¦{{ dnode n("SEM", "{{ }}"); }} ( IDENTIFIER {{ if(m_mTTKeyword.findKey(xState.str())) { if(m_mTokenList.findKey(m_mTTKeyword.value())) n.setLabel("T"); else n.setLabel("NT"); n.setValue(m_mTTKeyword.value()); } else { if(m_mTokenList.findKey(xState.str())) n.setLabel("T"); else n.setLabel("NT"); n.setValue(xState.str()); } }} | LITERAL {{ n.setLabel("T"); str s = "\""; s += xState.str(1); s += "\""; n.setValue(s); }} | "error" {{ n.setLabel("EXIT"); n.setValue("EXIT"); }} | Action ) {{ return n; }} dnode PrecedenceCProduction_LINKý¡ Precedence PREC IDENTIFIER Action? RuleCProduction_LINK,a¦Rule'{{ dnode n("Rule"); str sName; }} RULENAME {{sName = xState.str(1);}} ( {{ dnode n1 = }} Alternative {{ n.addChildLast(n1);}} )? ( "|" ( {{ dnode n1 = }} Alternative {{ n.addChildLast(n1);}} )? )* ";" {{ n.setValue(sName); m_nRules[sName] = n; }} RulesCProduction_LINKu£Rules Rule+ StartDefCProduction_LINK¸v£StartDef8START IDENTIFIER {{ m_sStartrule = xState.str(); }} TagCProduction_LINK4{£TagUnion member name"<" IDENTIFIER ">" TokenCProduction_LINKØ|£TokennIDENTIFIER // Note: literal invalid with % type | IDENTIFIER NUMBER // Note: invalid with % type õ( IDENTIFIER {{ if(m_mTTKeyword.findKey(xState.str())) m_mTokenList[m_mTTKeyword.value()] = ""; else m_mTokenList[xState.str()] = ""; }} | LITERAL ) NUMBER? TokenDeclCProduction_LINK\•£ TokenDeclB( TOKEN | LEFT | RIGHT | NONASSOC ) Tag? Tokens TokensCProduction_LINK¬—£Tokens,Token ( Token | "," Token )* TypeCProduction_LINK䙣TypeIDENTIFIER IGNORABLETypeDeclCProduction_LINKœ£TypeDeclTYPE Tag? Types TypesCProduction_LINKž£Types)Type ( Type | "," Type )* IGNORABLEUnionDefCProduction_LINKL £UnionDef UNION SKIP YaccCProduction_LINK\¢£Yacc¼Declarations? MARK Rules ( MARK Code )? {{LeftFactoringAll(); }} {{GroupAll(); }} {{RemoveAllLeftRecursion(); }} {{RemoveAllEmptyAlts(); }} {{WriteTetraImportFile(); }} GroupCElementScript¤¯£Groupw{{ dnode pos = xn.firstChild(); while(pos != dnode::npos) { GroupInner(pos); pos = pos.nextSibling(); } }} dnode& xnGroupAllCElementScript˜°£GroupAllU{{ m_nRules.reset(); while(m_nRules.gotoNext()) Group(m_nRules.value()); }} GroupInnerCElementScriptܱ£ GroupInner{{ if(xn == dnode::npos) return; dnode pos = xn.firstChild(); while(pos != dnode::npos) { GroupInner(pos); pos = pos.nextSibling(); } if(xn.childCount() >= 2 ) { xn.addChildFirst(dnode("ALT_BEGIN", "")); xn.add("ALT_END", ""); } }} dnode& xn LeftFactorCElementScriptÈ LeftFactor {{ //log << "RestructureRule " << xn.value() << endl; if(xn == dnode::npos) return; dnode pos = xn.firstChild(); while(pos != dnode::npos) { str sName = pos.value(); dnode pos2 = pos.nextSibling(); while(pos2 != dnode::npos) { if(pos2.value() == sName) { if(!pos.hasChildren()) pos.add("SEM", "{{ }}"); if(!pos2.hasChildren()) pos.add("SEM", "{{ }}"); else pos.addChildLast(pos2.firstChild()); dnode pos3 = pos2.nextSibling(); xn.removeChild(pos2); pos2 = pos3; } else pos2 = pos2.nextSibling(); } pos = pos.nextSibling(); } pos = xn.firstChild(); while(pos != dnode::npos) { LeftFactor(pos); pos = pos.nextSibling(); } }} dnode& xnLeftFactoringAllCElementScript6|LeftFactoringAllZ{{ m_nRules.reset(); while(m_nRules.gotoNext()) LeftFactor(m_nRules.value()); }} RemoveAllEmptyAltsCElementScript¶£RemoveAllEmptyAlts_{{ m_nRules.reset(); while(m_nRules.gotoNext()) RemoveEmptyAlts(m_nRules.value()); }} RemoveAllLeftRecursionCElementScript|·£RemoveAllLeftRecursionc{{ m_nRules.reset(); while(m_nRules.gotoNext()) RemoveLeftRecursion(m_nRules.value()); }} RemoveEmptyAltsCElementScriptܸ£RemoveEmptyAltsÌ{{ if(xn == dnode::npos) return; bool bFound = false; bool bIsGroup = false; dnode nEmpty = dnode::npos; dnode pos = xn.firstChild(); if(pos != dnode::npos) { if(pos.label() == "ALT_BEGIN" || pos.label() == "OREP_BEGIN" ) bIsGroup = true; } while(pos != dnode::npos) { RemoveEmptyAlts(pos); if(pos.label() == "SEM") { if(xn.childCount() == 1 || (bIsGroup && xn.childCount() == 3) ) { log << "cannot remove empty alt of: " << xn.value() << endl; } else { bFound = true; dnode pos2 = pos.nextSibling(); xn.removeChild(pos); pos = pos2; } } else pos = pos.nextSibling(); } if(bFound) { str sType = xn.lastChild().label(); if(sType == "ALT_END") { if(xn.childCount() == 3 && !xn.firstChild().nextSibling().hasChildren()) { xn.removeChild(xn.firstChild()); xn.lastChild().setLabel("OPT"); } else { xn.firstChild().setLabel("OPT_BEGIN"); xn.lastChild().setLabel("OPT_END"); } } else if(sType == "OREP_END") { if(xn.childCount() == 3 && !xn.firstChild().nextSibling().hasChildren()) { xn.removeChild(xn.firstChild()); xn.lastChild().setLabel("OREP"); } } else if(sType == "OPT_END") // cannot happen until now { if(xn.childCount() == 3 && !xn.firstChild().nextSibling().hasChildren()) { xn.removeChild(xn.firstChild()); xn.lastChild().setLabel("OPT"); } } else if(xn.childCount() > 1) { xn.addChildFirst(dnode("OPT_BEGIN", "")); xn.add("OPT_END", ""); } else { xn.add("OPT", ""); } } // bFound == true }} dnode& xnRemoveLeftRecursionCElementScriptä¹£RemoveLeftRecursiona = a C | B => a = B C* {{ if(xn == dnode::npos || xn.childCount() < 2) return; dnode nSame = dnode::npos, nOther; str sName = xn.value(); dnode pos = xn.firstChild(); if(xn.childCount() == 2) { if(pos.value() == sName) { nSame = pos; nOther = pos.nextSibling(); } else if(pos.nextSibling().value() == sName) { nSame = pos.nextSibling(); nOther = pos; } if(nSame == dnode::npos) return; // no left recursion } else { while(pos != dnode::npos) { if(pos.value() == sName) { nSame = pos; break; } pos = pos.nextSibling(); } if(nSame == dnode::npos) return; // no left recursion xn.addChildFirst(dnode("ALT_BEGIN", "")); nOther = xn.add("ALT_END", ""); } //log << "RemoveLeftRecursion " << xn.value() << endl; if(nSame.firstChild().label() == "ALT_BEGIN") { dnode pos2 = nSame.firstChild(); pos2.setLabel("OREP_BEGIN"); while(pos2 != dnode::npos) { dnode pos3 = pos2.nextSibling(); if(pos2.label() == "ALT_END") pos2.setLabel("OREP_END"); nOther.addChildLast(pos2); pos2 = pos3; } } else { dnode pos2 = nOther.bottomLastChild(); if(!nSame.firstChild().hasChildren()) { pos2.addChildLast( nSame.firstChild() ); pos2.addChildLast( dnode("OREP", "")); } else { pos2.addChildLast( dnode("OREP_BEGIN", "") ); pos2.addChildLast( nSame.firstChild() ); pos2.addChildLast( dnode("OREP_END", "") ); } } xn.removeChild(nSame); }} dnode& xn RestructureCElementScript$»£ Restructurea{{ LeftFactoringAll(); GroupAll(); RemoveAllLeftRecursion(); RemoveAllEmptyAlts(); }} WriteDefaultCElementScriptd¼£ WriteDefault®{{ //out << "WriteDefault " << xn.value() << endl; bool bOr = xbOr; dnode pos = xn.firstChild(); while(pos != dnode::npos) { m_ftWrite.visit(xState, pos, bOr); if(!bOr) bOr = true; if(pos.label() == "ALT_BEGIN" || pos.label() == "OREP_BEGIN" || pos.label() == "OPT_BEGIN" || pos.label() == "OREP" || pos.label() == "OPT" ) bOr = false; pos = pos.nextSibling(); } }} const dnode& xn, bool xbOr WriteLParenCElementScript@¿£ WriteLParen›{{ IncrIndent(2); if(xbOr) out << indent << "|(" << endl; else out << indent << "(" << endl; IncrIndent(2); WriteDefault(xn, false); }} const dnode& xn, bool xbOr WriteORepCElementScriptØá¢ WriteORep_{{ PopIndent(); out << indent << "*" << endl; PopIndent(); WriteDefault(xn, false); }} const dnode& xn, bool xbOrWriteOptCElementScript|ï¡WriteOpt_{{ PopIndent(); out << indent << "?" << endl; PopIndent(); WriteDefault(xn, false); }} const dnode& xn, bool xbOrWriteProductionsCElementScript fœWriteProductionsž{{ out << "PRODUCTIONS" << endl << endl; bool bOr = false; m_nRules.reset(); while(m_nRules.gotoNext()) m_ftWrite.visit(m_nRules.value(), bOr); }} WriteRParenCElementScriptŒ› WriteRParen_{{ PopIndent(); out << indent << ")" << endl; PopIndent(); WriteDefault(xn, false); }} const dnode& xn, bool xbOrWriteRParenORepCElementScriptØS›WriteRParenORep`{{ PopIndent(); out << indent << ")*" << endl; PopIndent(); WriteDefault(xn, false); }} const dnode& xn, bool xbOrWriteRParenOptCElementScriptÄ’›WriteRParenOpt`{{ PopIndent(); out << indent << ")?" << endl; PopIndent(); WriteDefault(xn, false); }} const dnode& xn, bool xbOr WriteRuleCElementScript4Ø› WriteRule„{{ out << xn.value() << "()" << endl << "(>" << endl; WriteDefault(xn, xbOr); out << endl << "<)" << endl << endl; }} const dnode& xn, bool xbOr WriteSymbolCElementScript„D WriteSymbol‘{{ if(xbOr) out << indent << "| " << xn.value(); else out << indent << " " << xn.value(); /* if(xn.nextSibling() == dnode::npos) out << endl; else if(xn.nextSibling().label() != "OPT" && xn.nextSibling().label() != "OREP" ) out << endl; */ if(xn.next().label() != "OPT" && xn.next().label() != "OREP" ) out << endl; WriteDefault(xn, false); }} const dnode& xn, bool xbOrWriteTetraImportFileCElementScriptè—¢WriteTetraImportFile´{{ out << "TextTransformer" << endl << endl; out << "[ProjectOptions]" << endl; out << "Startrule=" << m_sStartrule << endl << endl; WriteTokens(); WriteProductions(); }} WriteTokensCElementScript˜›¢ WriteTokenså{{ out << "TOKENS" << endl << endl; m_mTokenList.reset(); while(m_mTokenList.gotoNext()) { out << m_mTokenList.key() << "()" << endl << "(>" << endl << "dummy" << endl << "<)" << endl << endl; } }} m_ftWriteCElementScript ¢ m_ftWrite{{ m_ftWrite.add("", WriteDefault); m_ftWrite.add("Rule", WriteRule); m_ftWrite.add("NT", WriteSymbol); m_ftWrite.add("T", WriteSymbol); m_ftWrite.add("EXIT", WriteSymbol); m_ftWrite.add("SEM", WriteSymbol); m_ftWrite.add("ALT_BEGIN", WriteLParen); m_ftWrite.add("ALT_END", WriteRParen); m_ftWrite.add("OREP_BEGIN", WriteLParen); m_ftWrite.add("OREP_END", WriteRParenORep); m_ftWrite.add("OREP", WriteORep); m_ftWrite.add("OPT_BEGIN", WriteLParen); m_ftWrite.add("OPT_END", WriteRParenOpt); m_ftWrite.add("OPT", WriteOpt); }} const dnode& xn, bool xbOrmstrfun m_mTTKeywordCElementScript”¥¢ m_mTTKeywordH{{ m_mTTKeyword["IF"] = "IF_"; m_mTTKeyword["WHILE"] = "WHILE_"; m_mTTKeyword["BREAK"] = "BREAK_"; m_mTTKeyword["ELSE"] = "ELSE_"; m_mTTKeyword["END"] = "END_"; m_mTTKeyword["EXIT"] = "EXIT_"; m_mTTKeyword["OK"] = "OK_"; m_mTTKeyword["EOF"] = "EOF_"; m_mTTKeyword["SKIP"] = "SKIP_"; m_mTTKeyword["ANY"] = "ANY_"; }} mstrstr m_mTokenListCElementScriptЫ¢ m_mTokenListmstrstrm_nRulesCElementScript¸¬¢m_nRules mstrdnode m_sStartruleCElementScriptЭ¢ m_sStartrulestrCOptionsProjectÜ»ÑProjectOptionsProjectOptionsCOptionSectioncÉProjectOptions CaseSensitiveCScript¬ù¡ CaseSensitive1 CommentToCodeCScript°¢ CommentToCode0 ConfigParamCScriptˆ°¢ ConfigParam""CreateInterfaceCScript±¢CreateInterface0DOMDefaultLabelCScriptøŸ£DOMDefaultLabel default_labelDOMDocTypeNameCScriptر¢DOMDocTypeName DOMPublicIDCScriptP²¢ DOMPublicID DOMRootLabelCScriptز¢ DOMRootLabelroot DOMSystemIDCScriptP³¢ DOMSystemID ExportableCScript´³¢ Exportable1 ExtraParamCScript8´¢ ExtraParam""GlobalLiteralScannerCScriptÈ´¢GlobalLiteralScanner1GlobalRegexScannerCScriptHµ¢GlobalRegexScanner0 IgnoreCharsCScriptœµ¢ IgnoreChars IGNORABLEIgnoreWhiteSpaceCScript ¶¢IgnoreWhiteSpace0 InterpretableCScriptœ¶¢ Interpretable1IsNullableWarningCScript·¢IsNullableWarning1 LATokenBufferCScript„·¢ LATokenBuffer0 MaxStackSizeCScript¸¢ MaxStackSize100NeatlessCScript˜¸¢Neatless1 NoSkipFailAltCScript ¹¢ NoSkipFailAlt0 SeparatedCScript¨¹¢ Separated1StartSuccNullableWarningCScript<º¢StartSuccNullableWarning1 StartruleCScriptÀº¢ StartruleYaccTestAllLiteralsCScript4»¢TestAllLiterals0UseIgnoreRegexCScriptÀ»¢UseIgnoreRegex1UseLocalOptionsCScript<¼¢UseLocalOptions0