public override void SetAltAssoc(AltAST t, int alt) { ASSOC assoc = ASSOC.left; if (t.GetOptions() != null) { string a = t.GetOptionString("assoc"); if (a != null) { if (a.Equals(ASSOC.right.ToString())) { assoc = ASSOC.right; } else if (a.Equals(ASSOC.left.ToString())) { assoc = ASSOC.left; } else { tool.errMgr.GrammarError(ErrorType.ILLEGAL_OPTION_VALUE, t.g.fileName, t.GetOptionAST("assoc").Token, "assoc", assoc); } } } if (altAssociativity.ContainsKey(alt) && altAssociativity[alt] != assoc) { tool.errMgr.ToolError(ErrorType.INTERNAL_ERROR, "all operators of alt " + alt + " of left-recursive rule must have same associativity"); } altAssociativity[alt] = assoc; // System.out.println("setAltAssoc: op " + alt + ": " + t.getText()+", assoc="+assoc); }
public override void SetTokenPrec(GrammarAST t, int alt) { int ttype = g.GetTokenType(t.Text); //tokenToPrec.Add(ttype, alt); tokenToPrec[ttype] = alt; ASSOC assoc = ASSOC.left; if (t.terminalOptions != null) { object o; t.terminalOptions.TryGetValue("assoc", out o); string a = o as string; if (a != null) { if (a.Equals(ASSOC.right.ToString())) { assoc = ASSOC.right; } else { ErrorManager.Error(ErrorManager.MSG_ILLEGAL_OPTION_VALUE, "assoc", assoc); } } } ASSOC currentAssociativity; if (altAssociativity.TryGetValue(alt, out currentAssociativity)) { if (currentAssociativity != assoc) { ErrorManager.Error(ErrorManager.MSG_ALL_OPS_NEED_SAME_ASSOC, alt); } } else { altAssociativity.Add(alt, assoc); } //System.out.println("op " + alt + ": " + t.getText()+", assoc="+assoc); }