public SymbolType(SymbolsGen yyp,string name,bool defined) { Lexer yyl = yyp.m_lexer; yyl.yytext = name; CSymbol s = (new CSymbol(yyp)).Resolve(); m_name = name; m_next=yyp.stypes; yyp.stypes=this; if (defined) s.m_defined = true; }
public SymbolType(SymbolsGen yyp,string name,bool defined) { Lexer yyl = yyp.m_lexer; int p = name.IndexOf("+"); int num = 0; if (p>0) { num = int.Parse(name.Substring(p+1)); if (num> yyp.LastSymbol) yyp.LastSymbol = num; name = name.Substring(0,p); } yyl.yytext = name; CSymbol s = new CSymbol(yyp); if (num>0) s.m_yynum = num; s = s.Resolve(); if (defined) s.m_defined = true; m_name = name; m_next=yyp.stypes; yyp.stypes=this; }
// 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; SymbolType st = (stypes==null)?null:stypes._Find(lhs.yytext); if (st == null) st = new SymbolType(this,lhs.yytext); 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("public class "+lhs.yytext+" : SYMBOL {"); m_outFile.WriteLine(" public "+lhs.yytext+"(Parser yyq):base(yyq) { }"); m_outFile.WriteLine(" public override string yyname { get { return \""+lhs.yytext+"\"; }}"); m_outFile.WriteLine(" public override int yynum { get { return "+lhs.m_yynum+"; }}}"); } 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"); }