public virtual void AssignTokenTypes() { // ASSIGN TOKEN TYPES for all delegates (same walker) //System.Console.Out.WriteLine( "### assign types" ); //ttypesWalker.setASTNodeClass( "org.antlr.tool.GrammarAST" ); IList <Grammar> grammars = delegateGrammarTreeRoot.GetPostOrderedGrammarList(); for (int i = 0; grammars != null && i < grammars.Count; i++) { Grammar g = (Grammar)grammars[i]; AssignTokenTypesWalker ttypesWalker = new AssignTokenTypesBehavior(new Antlr.Runtime.Tree.CommonTreeNodeStream(g.Tree)); try { //System.Console.Out.WriteLine( " walking " + g.name ); ttypesWalker.grammar_(g); // the walker has filled literals, tokens, and alias tables. // now tell it to define them in the root grammar ttypesWalker.DefineTokens(delegateGrammarTreeRoot.grammar); } catch (RecognitionException re) { ErrorManager.Error(ErrorManager.MSG_BAD_AST_STRUCTURE, re); } } }
public static void InternalError(Object error, Exception e) { StackFrame location = GetLastNonErrorManagerCodeLocation(e); String msg = "Exception " + e + "@" + location + ": " + error; ErrorManager.Error(MSG_INTERNAL_ERROR, msg); }
public virtual void Error(String s, Exception e) { if (e is TargetInvocationException) { e = e.InnerException ?? e; } ErrorManager.Error(ErrorManager.MSG_INTERNAL_ERROR, s, e); }
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); }
private static TemplateGroup LoadPrecRuleTemplates(AntlrTool tool) { string templateDirs = tool.TemplatesDirectory; TemplateGroup group; if (!recRuleTemplatesCache.TryGetValue(templateDirs, out group)) { string fileName = CodeGenerator.FindTemplateFile(templateDirs.Split(':'), "LeftRecursiveRules.stg"); group = new ToolTemplateGroupFile(fileName); if (!group.IsDefined("recRuleName")) { recRuleTemplatesCache[templateDirs] = group; } else { ErrorManager.Error(ErrorManager.MSG_MISSING_CODE_GEN_TEMPLATES, "PrecRules"); return(null); } } return(group); }
public string Text(GrammarAST t) { if (t == null) { return(null); } try { ITreeNodeStream input = new CommonTreeNodeStream(new ANTLRParser.grammar_Adaptor(null), t); ANTLRTreePrinter printer = new ANTLRTreePrinter(input); return(printer.toString(grammar, true)); } catch (Exception e) { if (e.IsCritical()) { throw; } ErrorManager.Error(ErrorManager.MSG_BAD_AST_STRUCTURE, e); return(null); } }
public void InternalError(TemplateMessage msg) { ErrorManager.Error(ErrorManager.MSG_INTERNAL_ERROR, msg.ToString(), msg.Cause); }
public void CompiletimeError(TemplateMessage msg) { ErrorManager.Error(ErrorManager.MSG_INTERNAL_ERROR, msg.ToString(), msg.Cause); }
/** For decls like "String foo" or "char *foo32[3]" compute the ID * and type declarations. Also handle "int x=3" and 'T t = new T("foo")' * but if the separator is ',' you cannot use ',' in the initvalue. * AttributeScope.addAttributes takes care of the separation so we are * free here to use from '=' to end of string as the expression. * * Set name, type, initvalue, and full decl instance vars. */ protected virtual void ExtractAttribute(string decl) { if (decl == null) { return; } bool inID = false; int start = -1; int rightEdgeOfDeclarator = decl.Length - 1; int equalsIndex = decl.IndexOf('='); if (equalsIndex > 0) { // everything after the '=' is the init value this.InitValue = decl.Substring(equalsIndex + 1); rightEdgeOfDeclarator = equalsIndex - 1; } // walk backwards looking for start of an ID for (int i = rightEdgeOfDeclarator; i >= 0; i--) { // if we haven't found the end yet, keep going if (!inID && (char.IsLetterOrDigit(decl[i]) || decl[i] == '_' || decl[i] == '@')) { inID = true; } else if (inID && !(char.IsLetterOrDigit(decl[i]) || decl[i] == '_' || decl[i] == '@')) { start = i + 1; break; } } if (start < 0 && inID) { start = 0; } if (start < 0) { ErrorManager.Error(ErrorManager.MSG_CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL, decl); } // walk forwards looking for end of an ID int stop = -1; for (int i = start; i <= rightEdgeOfDeclarator; i++) { // if we haven't found the end yet, keep going if (!(char.IsLetterOrDigit(decl[i]) || decl[i] == '_' || decl[i] == '@')) { stop = i; break; } if (i == rightEdgeOfDeclarator) { stop = i + 1; } } // the name is the last ID this.Name = decl.Substring(start, stop - start); // the type is the decl minus the ID (could be empty) this.Type = decl.Substring(0, start); if (stop <= rightEdgeOfDeclarator) { this.Type += decl.Substring(stop, rightEdgeOfDeclarator + 1 - stop); } this.Type = Type.Trim(); if (this.Type.Length == 0) { this.Type = null; } this.Decl = decl; }