public override void SimpleAction(ParserSimpleAction a) { string str = a.yytext.Substring(1, a.yytext.Length - 1); if (str == "null") { m_lexer.yytext = "Null"; a.m_sym = (new CSymbol(this)).Resolve(); NewConstructor(ref a.m_sym, ",\"" + m_prod.m_lhs.yytext + "\"){}"); return; } if (str.Length == 0) { str = m_prod.m_lhs.yytext; } CSymbol s = (CSymbol)m_symbols.symbols[str]; if (s == null) { // not there: define a new node type //Console.WriteLine("Symbol {0} needs defining",str); m_lexer.yytext = str; s = new CSymbol(this); m_symbols.symbols[str] = s; s.m_symtype = CSymbol.SymType.nodesymbol; s.m_refSymbol = (CSymbol)m_prod.m_lhs; s.m_emitted = true; m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine("public class " + str + " : " + s.m_refSymbol.yytext + " { "); m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine(@"/// <param name='yyq'></param>"); m_outFile.WriteLine(" public " + str + "(Parser yyq):base(yyq) { }}"); } a.m_sym = s; int ch; str = ")"; NextNonWhite(out ch); if (ch == '(') { ch = m_lexer.GetChar(); str = "," + GetBracketedSeq(ref ch, ')').Substring(1); NextNonWhite(out ch); } if (str == ",)") // 4.0d { str = ")"; } string init = "{}"; if (ch == '{') { ch = m_lexer.GetChar(); init = "yyp=(" + m_outname + ")yyq;\n" + GetBracketedSeq(ref ch, '}'); NextNonWhite(out ch); } init = str + init; NewConstructor(ref a.m_sym, init); }
public override void OldAction(ParserOldAction a) { int ch = '{'; a.m_symtype = CSymbol.SymType.oldaction; a.m_action = ++action; a.m_initialisation = GetBracketedSeq(ref ch, '}'); a.m_sym = (CSymbol)m_prod.m_lhs; NextNonWhite(out ch); if (ch == ';' || ch == '|') { // an old action at the end is converted into a simple action m_lexer.yytext = "%"; ParserSimpleAction sa = new ParserSimpleAction(this); SimpleAction(sa); NewConstructor(ref sa.m_sym, ")" + a.m_initialisation); a.m_sym = (CSymbol)sa; sa.yytext += sa.m_sym.yytext; a.yytext = "#" + sa.yytext; a.m_action = -1; // mark the old action for deletion } }
public override void SimpleAction(ParserSimpleAction a) { string str = a.yytext.Substring(1, a.yytext.Length - 1); if (str == "null") { m_lexer.yytext = "Null"; a.m_sym = (new CSymbol(this)).Resolve(); NewConstructor(ref a.m_sym, ", " + m_prod.m_lhs.m_yynum + "){}"); return; } if (str.Length == 0) { str = m_prod.m_lhs.yytext; } CSymbol s = (CSymbol)m_symbols.symbols[str]; if (s == null) { // not there: define a new node type //Console.WriteLine("Symbol {0} needs defining",str); m_lexer.yytext = str; s = new CSymbol(this); m_symbols.symbols[str] = s; s.m_symtype = CSymbol.SymType.nodesymbol; s.m_refSymbol = (CSymbol)m_prod.m_lhs; s.m_emitted = true; m_outFile.WriteLine("public class " + str + " : " + s.m_refSymbol.yytext + " { "); m_outFile.WriteLine(" public " + str + "(Parser yyq):base(yyq) { }}"); } else if (s.m_refSymbol != null) // 4.5c { CSymbol t = s; // 4.5d while (t != null && t != (CSymbol)m_prod.m_lhs) { t = t.m_refSymbol; } if (t == null) { Error(46, m_lexer.m_pch, "Simple action " + s.yytext + " does not match symbol type " + m_prod.m_lhs.yytext); // 4.5d } } // 4.5c else { s.m_refSymbol = (CSymbol)m_prod.m_lhs; } a.m_sym = s; int ch; str = ")"; NextNonWhite(out ch); if (ch == '(') { ch = m_lexer.GetChar(); str = "," + GetBracketedSeq(ref ch, ')').Substring(1); NextNonWhite(out ch); } if (str == ",)") // 4.0d { str = ")"; } string init = "{}"; if (ch == '{') { ch = m_lexer.GetChar(); string ts = GetBracketedSeq(ref ch, '}'); // 4.5g init = "{ " + m_outname + " yyp=(" + m_outname + ")yyq;\n" + ts.Substring(1); // 4.5g 4.5h NextNonWhite(out ch); } init = str + init; NewConstructor(ref a.m_sym, init); }
public void RhSide(Production p) { CSymbol s; ParserOldAction a = null; // last old action seen while (m_tok != null) { if (m_tok.Matches(";")) { break; } if (m_tok.Matches("|")) { break; } if (m_tok.Matches(":")) { Advance(); p.m_alias[m_tok.yytext] = p.m_rhs.Count; Advance(); } else if (m_tok is PrecReference) { if (p.m_rhs.Count == 0) { erh.Error(new CSToolsException(21, "%prec cannot be at the start of a right hand side")); } PrecReference pr = (PrecReference)m_tok; CSymbol r = (CSymbol)p.m_rhs[p.m_rhs.Count - 1]; r.m_prec = pr.precref.m_prec; Advance(); } else { s = (CSymbol)m_tok; if (s.m_symtype == CSymbol.SymType.oldaction) { if (a != null) { Error(42, s.pos, "adjacent actions"); } a = (ParserOldAction)s; if (a.m_action < 0) { // an OldAction that has been converted to a SimpleAction: discard it s = a.m_sym; // add the SimpleAction instead s.m_symtype = CSymbol.SymType.simpleaction; ParserSimpleAction sa = (ParserSimpleAction)s; } else // add it to the Actions function { m_actions += String.Format("\ncase {0} : {1} break;", a.m_action, a.m_initialisation); } a = null; } else if (s.m_symtype != CSymbol.SymType.simpleaction) { s = ((CSymbol)m_tok).Resolve(); } p.AddToRhs(s); Advance(); } } Precedence.Check(p); }
public abstract void SimpleAction(ParserSimpleAction a);