// parsing routines internal void ParseProduction() { TOKEN tok = m_tok; CSymbol lhs = null; try { lhs = ((CSymbol)m_tok).Resolve(); } catch(Exception e) { erh.Error(new CSToolsFatalException(45,tok,string.Format("Syntax error in Parser script - possibly extra semicolon?",e.Message))); } m_tok = lhs; if (m_tok.IsTerminal()) Error(39,m_tok.pos,string.Format("Illegal left hand side <{0}> for production",m_tok.yytext)); if (m_symbols.m_startSymbol==null) m_symbols.m_startSymbol = lhs; if (lhs.m_symtype==CSymbol.SymType.unknown) lhs.m_symtype = CSymbol.SymType.nonterminal; if ((!lhs.m_defined) && lhs.m_prods.Count==0) { // lhs not defined in %symbol statement and not previously a lhs // so declare it as a new symbol m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine("public class "+lhs.yytext+" : SYMBOL {"); m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine(@"/// <param name='yyq'></param>"); m_outFile.WriteLine(" public "+lhs.yytext+"(Parser yyq):base(yyq) { }"); m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine(" public override string yyname() { return \""+lhs.yytext+"\"; }}"); } if (!Find(lhs)) new SymbolType(this,lhs.yytext); m_prod = new Production(this,lhs); m_lexer.yy_begin("rhs"); Advance(); if (!m_tok.Matches(":")) Error(40,m_tok.pos,String.Format("Colon expected for production {0}",lhs.yytext)); Advance(); RhSide(m_prod); while(m_tok!=null && m_tok.Matches("|")) { Advance(); m_prod = new Production(this,lhs); RhSide(m_prod); } if (m_tok==null || !m_tok.Matches(";")) Error(41,m_lexer.m_pch,"Semicolon expected"); Advance(); m_prod = null; m_lexer.yy_begin("YYINITIAL"); }