public nonterminalState parse(System.IO.TextWriter err) { nonterminalState _current = null; InputElement cur = yylex.Current; InputElement prev = null; while (wl.Count > 0) { foreach (state s in wl) { s.end = cur.coord; } while (wl.Count > 0) { state s = (state)wl.Dequeue(); if (s.below != null && s.below.checkRejected()) { continue; } if (s.accepting) { System.Diagnostics.Debug.Assert(_current == null); _current = ((acceptingState)s).root; } else { s.transitions(wl_next, cur, count); } } if (yylex.MoveNext()) { count++; prev = cur; cur = yylex.Current; } System.Collections.Queue tmp = wl; wl = wl_next; wl_next = tmp; } if (_current == null) { err.WriteLine("\"" + prev.coord.file + "\" (" + prev.coord.line + "," + prev.coord.column + "): Syntax error on \"" + prev.str + "\""); } return(_current); }
public virtual void add(nonterminalState state, int count) { if (!this.rejected) { if (state.rejected) { this.rejected = state.rejected; // true; this.rightmost = state.rightmost; this.rule = state.rule; this.queue = null; } else { if (queue == null) { queue = new System.Collections.Queue(); } queue.Enqueue(state); } } }
public static object resolve(nonterminalState node, string nonterm) { System.Collections.Queue q; expression e1; expression e2; switch (nonterm) { default: if (node.queue != null) { node.report(); //System.Console.WriteLine("{0}", node.ToString("")); throw new System.Exception("ambiguous"); } node.report(); return(null); case "argument-list": q = node.queue; node.queue = null; argumentList a = (argumentList)parse2AST.rewrite_argument_list(node); foreach (nonterminalState s in q) { argumentList a2 = (argumentList)parse2AST.rewrite_argument_list(s); if (a2.Count < a.Count) { a = a2; } } return(a); case "relational-expression": q = node.queue; node.queue = null; e1 = parse2AST.rewrite_relational_expression(node); int n = TypeArgumentCount(e1); foreach (nonterminalState s in q) { e2 = parse2AST.rewrite_relational_expression(s); int m = TypeArgumentCount(e2); if (m > n) { n = m; e1 = e2; } } return(e1); case "if-statement": q = node.queue; node.queue = null; // by picking the short production int count = 0; for (state p = node.rightmost; p != node.below; p = p.below) { count++; } bool ties = false; foreach (nonterminalState node1 in q) { int c = 0; for (state p = node1.rightmost; p != node1.below; p = p.below) { c++; } if (c < count) { node = node1; ties = false; count = c; } else if (c == count) { ties = true; } } System.Diagnostics.Debug.Assert(!ties); return(parse2AST.rewrite_if_statement(node)); case "and-expression": // (e1) & e2 ambiguity q = node.queue; node.queue = null; e1 = parse2AST.rewrite_and_expression(node); System.Diagnostics.Debug.Assert(q.Count == 1); e2 = parse2AST.rewrite_and_expression((nonterminalState)q.Dequeue()); return(fix_cast(e1, e2)); case "additive-expression": // (e1) + e2 ambiguity q = node.queue; node.queue = null; e1 = parse2AST.rewrite_additive_expression(node); System.Diagnostics.Debug.Assert(q.Count == 1); e2 = parse2AST.rewrite_additive_expression((nonterminalState)q.Dequeue()); return(fix_cast(e1, e2)); case "unary-expression": // q = node.queue; node.queue = null; e1 = parse2AST.rewrite_unary_expression(node); System.Diagnostics.Debug.Assert(q.Count == 1); e2 = parse2AST.rewrite_unary_expression((nonterminalState)q.Dequeue()); return(fix_cast(e1, e2)); case "multiplicative-expression": // (e1) * e2 ambiguity q = node.queue; node.queue = null; e1 = parse2AST.rewrite_multiplicative_expression(node); System.Diagnostics.Debug.Assert(q.Count == 1); e2 = parse2AST.rewrite_multiplicative_expression((nonterminalState)q.Dequeue()); return(fix_cast(e1, e2)); } }
protected acceptingState(state below, string rule, state rightmost, Coordinate end, bool rejected, int serial) : base(below, rule, rightmost, end, false, serial) { System.Diagnostics.Debug.Assert(!rejected); this.root = (nonterminalState)rightmost; }
private void update(int count) { if (this.count != count) { this.count = count; memo1 = null; } }
private void update(int count) { if (this.count != count) { this.count = count; memo1 = null; memo2 = null; memo3 = null; memo4 = null; memo5 = null; memo6 = null; memo7 = null; memo8 = null; } }
private void update(int count) { if (this.count != count) { this.count = count; memo1 = null; memo2 = null; memo3 = null; memo4 = null; memo5 = null; memo6 = null; memo7 = null; memo8 = null; memo9 = null; memo10 = null; memo11 = null; memo12 = null; memo13 = null; memo14 = null; memo15 = null; memo16 = null; memo17 = null; memo18 = null; memo19 = null; memo20 = null; memo21 = null; memo22 = null; memo23 = null; memo24 = null; memo25 = null; memo26 = null; memo27 = null; memo28 = null; memo29 = null; memo30 = null; memo31 = null; memo32 = null; memo33 = null; memo34 = null; memo35 = null; memo36 = null; memo37 = null; memo38 = null; memo39 = null; memo40 = null; memo41 = null; } }
private void update(int count) { if (this.count != count) { this.count = count; memo1 = null; memo2 = null; memo3 = null; memo4 = null; memo5 = null; memo6 = null; memo7 = null; memo8 = null; memo9 = null; memo10 = null; memo11 = null; memo12 = null; memo13 = null; memo14 = null; memo15 = null; memo16 = null; memo17 = null; memo18 = null; memo19 = null; memo20 = null; memo21 = null; memo22 = null; memo23 = null; } }