/// <summary> /// Sets up the parser to the purpose of a custom parse request (e.g. to support code-completion). /// </summary> /// <param name="srcPath">The path of the source-file.</param> /// <param name="frameDir">The directory where the frames are stored.</param> /// <param name="outDir">The output directory.</param> /// <param name="line">The line (one-based) of the target position.</param> /// <param name="col">The column (one-based) of the target position.</param> public virtual void InitateCustomParseRequest(string srcPath, int line, int col) { generateCode = false; //suppose is to build symbol-table trace = new StreamWriter(new MemoryStream()); //we are not interested tab = new Tab(this); dfa = new DFA(this); pgen = new ParserGen(this); tab.srcName = srcPath; tab.srcDir = Path.GetDirectoryName(srcPath); tab.nsName = "at.jku.ssw.Coco.VSPlugin.TempNS"; //doesn't matter, no code is generated tab.frameDir = string.Empty; //won't be needed because no code-generation is done tab.outDir = string.Empty; // wont't be needed because no code-generation is done //indicate that initialization occured customizedParsing = true; //set the target position TargetLine = line; TargetCol = col; DeterminedGrammarPos = -1; //initialize to error position //clear (initialize) collected lists of charsets, tokens, productions, braces UserCharSets = new List <AddTokenInfo>(); UserTokens = new List <AddTokenInfo>(); UserProductions = new List <AddTokenInfo>(); OpenedBraces = new List <long>(); References = new Dictionary <string, List <AddTokenInfo> >(); }
static void Coco() { Symbol sym; Graph g; string gramName; if (la.kind == 40) { UsingDecl(out ParserGen.usingPos); } Expect(6); int gramLine = t.line; genScanner = true; bool ok = true; Tab.ignored = null; Expect(1); gramName = t.val; int beg = la.pos; while (StartOf(1)) { Get(); } Tab.semDeclPos = new Position(beg, la.pos - beg, 0); while (StartOf(2)) { Declaration(); } while (!(la.kind == 0 || la.kind == 7)) { SynErr(43); Get(); } Expect(7); if (genScanner) { DFA.MakeDeterministic(); } Graph.DeleteNodes(); while (la.kind == 1) { Get(); sym = Symbol.Find(t.val); bool undef = sym == null; if (undef) { sym = new Symbol(Node.nt, t.val, t.line); } else { if (sym.typ == Node.nt) { if (sym.graph != null) { SemErr("name declared twice"); } } else { SemErr("this symbol kind not allowed on left side of production"); } sym.line = t.line; } bool noAttrs = sym.attrPos == null; sym.attrPos = null; if (la.kind == 24) { AttrDecl(sym); } if (!undef) { if (noAttrs != (sym.attrPos == null)) { SemErr("attribute mismatch between declaration and use of this symbol"); } } if (la.kind == 38) { SemText(out sym.semPos); } ExpectWeak(8, 3); Expression(out g); sym.graph = g.l; Graph.Finish(g); ExpectWeak(9, 4); } Expect(10); Expect(1); if (gramName != t.val) { SemErr("name does not match grammar name"); } Tab.gramSy = Symbol.Find(gramName); if (Tab.gramSy == null) { SemErr("missing production for grammar name"); } else { sym = Tab.gramSy; if (sym.attrPos != null) { SemErr("grammar symbol must not have attributes"); } } Tab.noSym = new Symbol(Node.t, "???", 0); // noSym gets highest number Tab.SetupAnys(); Tab.RenumberPragmas(); if (Tab.ddt[2]) { Node.PrintNodes(); } if (Errors.count == 0) { Console.WriteLine("checking"); Tab.CompSymbolSets(); ok = ok && Tab.GrammarOk(); if (Tab.ddt[7]) { Tab.XRef(); } if (ok) { Console.Write("parser"); ParserGen.WriteParser(); if (genScanner) { Console.Write(" + scanner"); DFA.WriteScanner(); if (Tab.ddt[0]) { DFA.PrintStates(); } } Console.WriteLine(" generated"); if (Tab.ddt[8]) { ParserGen.WriteStatistics(); } } } if (Tab.ddt[6]) { Tab.PrintSymbolTable(); } Expect(9); }
public static void Main(string[] arg) { Console.WriteLine("Coco/R (Aug 4, 2003)"); string ATGName = null; for (int i = 0; i < arg.Length; i++) { if (arg[i] == "-nonamespace") { Tab.nsName = null; } else if (arg[i] == "-namespace") { Tab.nsName = arg[++i]; } else if (arg[i] == "-trace") { Tab.SetDDT(arg[++i]); } else { ATGName = arg[i]; } } if (arg.Length > 0 && ATGName != null) { int pos = ATGName.LastIndexOf('/'); if (pos < 0) { pos = ATGName.LastIndexOf('\\'); } string file = ATGName; string dir = ATGName.Substring(0, pos + 1); Scanner.Init(file); Trace.Init(dir); Tab.Init(); DFA.Init(dir); ParserGen.Init(file, dir); Parser.Parse(); Trace.Close(); Console.WriteLine(); Console.WriteLine("{0} errors detected", Errors.count); } else { Console.WriteLine("Usage: Coco {{Option}} Grammar.ATG {{Option}}{0}" + "Options:{0}" + " -nonamespace{0}" + " -namespace <packageName>{0}" + " -trace <traceString>{0}" + "Valid characters in the trace string:{0}" + " A trace automaton{0}" + " F list first/follow sets{0}" + " G print syntax graph{0}" + " I trace computation of first sets{0}" + " P print statistics{0}" + " S list symbol table{0}" + " X list cross reference table{0}" + "Scanner.frame and Parser.frame files needed in ATG directory{0}" + "or in a directory referenced by the environment variable CRFRAMES.", Environment.NewLine); } }