public void ReduceStates() { for (ProdItemList prodItemList = this.m_items; prodItemList.m_pi != null; prodItemList = prodItemList.m_next) { ProdItem pi = prodItemList.m_pi; if (pi.Next() == null) { Production prod = pi.m_prod; if (prod.m_pno != 0) { int count = prod.m_rhs.Count; CSymbol rh; ParserReduce parserReduce; if (count > 0 && (rh = (CSymbol)prod.m_rhs[count - 1]) != null && rh.IsAction()) { ParserAction action = (ParserAction)rh; action.m_len = count; parserReduce = new ParserReduce(action, count - 1, prod); } else { this.m_sgen.m_lexer.yytext = "%" + prod.m_lhs.yytext; this.m_sgen.m_prod = prod; ParserSimpleAction parserSimpleAction = new ParserSimpleAction(this.m_sgen); parserSimpleAction.m_sym = prod.m_lhs; parserSimpleAction.m_len = count; parserReduce = new ParserReduce((ParserAction)parserSimpleAction, count, prod); } foreach (CSymbol key in (IEnumerable)pi.m_prod.m_lhs.m_follow.Keys) { this.GetTransition(key).m_reduce[(object)prod] = (object)parserReduce; } } } } }
public void ReduceStates() { ProdItemList pil; for (pil=m_items; pil.m_pi!=null; pil=pil.m_next) { ProdItem item = pil.m_pi; CSymbol s = item.Next(); if (s==null) { // item is a reducing item Production rp = item.m_prod; if (rp.m_pno==0) // except for production 0: S'->S-| continue; // reduce item: deal with it int n = rp.m_rhs.Count; CSymbol a; ParserReduce pr; if (n>0 && (a=(CSymbol)rp.m_rhs[n-1])!=null && a.IsAction()) { ParserAction pa = (ParserAction)a; pa.m_len = n; pr = new ParserReduce(pa,n-1,rp); } else { m_sgen.m_lexer.yytext = "%"+rp.m_lhs.yytext; m_sgen.m_prod = rp; ParserSimpleAction sa = new ParserSimpleAction(m_sgen); sa.m_sym = (CSymbol)rp.m_lhs; sa.m_len = n; pr = new ParserReduce(sa,n,rp); } foreach (CSymbol ss in item.m_prod.m_lhs.m_follow.Keys) GetTransition(ss).m_reduce[rp]=pr; } } }
public abstract void SimpleAction(ParserSimpleAction a);
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.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 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); }