static void TokenDecl(int typ) { string name; int kind; Symbol sym; Graph g; Sym(out name, out kind); sym = Symbol.Find(name); if (sym != null) { SemErr("name declared twice"); } else { sym = new Symbol(typ, name, t.line); sym.tokenKind = Symbol.classToken; } while (!(StartOf(13))) { SynErr(46); Get(); } if (la.kind == 8) { Get(); TokenExpr(out g); Expect(9); if (kind != id) { SemErr("a literal must not be declared with a structure"); } Graph.Finish(g); DFA.ConvertToStates(g.l, sym); } else if (la.kind == 9) { Get(); if (typ != Node.rslv) { SemErr("resolver is only allowed in RESOLVERS section"); } } else if (StartOf(14)) { if (kind == id) { genScanner = false; } else { DFA.MatchLiteral(sym); } } else { SynErr(47); } if (la.kind == 38) { SemText(out sym.semPos); if (typ == Node.t) { SemErr("semantic action not allowed here"); } } else if (StartOf(15)) { if (typ == Node.rslv) { SemErr("resolvers must have a semantic action"); } } else { SynErr(48); } }
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); }