static void Factor(out Graph g) { string name; int kind; Position pos; bool weak = false; g = null; switch (la.kind) { case 1: case 3: case 5: case 27: { if (la.kind == 27) { Get(); weak = true; } Sym(out name, out kind); Symbol sym = Symbol.Find(name); bool undef = sym == null; if (undef) { if (kind == id) { sym = new Symbol(Node.nt, name, 0); // forward nt } else if (genScanner) { sym = new Symbol(Node.t, name, t.line); DFA.MatchLiteral(sym); } else // undefined string in production { SemErr("undefined string in production"); sym = Tab.eofSy; // dummy } } int typ = sym.typ; if (typ != Node.t && typ != Node.nt && typ != Node.rslv) /* ML */ { SemErr("this symbol kind is not allowed in a production"); } if (weak) { if (typ == Node.t) { typ = Node.wt; } else { SemErr("only terminals may be weak"); } } Node p = new Node(typ, sym, t.line); g = new Graph(p); if (la.kind == 24) { Attribs(p); if (kind != id) { SemErr("a literal must not have attributes"); } } if (undef) { sym.attrPos = p.pos; // dummy } else if ((p.pos == null) != (sym.attrPos == null)) { SemErr("attribute mismatch between declaration and use of this symbol"); } break; } case 28: { Get(); Expression(out g); Expect(29); break; } case 30: { Get(); Expression(out g); Expect(31); Graph.MakeOption(g); break; } case 32: { Get(); Expression(out g); Expect(33); Graph.MakeIteration(g); break; } case 38: { SemText(out pos); Node p = new Node(Node.sem, null, 0); p.pos = pos; g = new Graph(p); break; } case 23: { Get(); Node p = new Node(Node.any, null, 0); // p.set is set in Tab.SetupAnys g = new Graph(p); break; } case 34: { Get(); Node p = new Node(Node.sync, null, 0); g = new Graph(p); break; } default: SynErr(53); break; } }
void TokenDecl(int typ) { string name; int kind; Symbol sym; Graph g; Sym(out name, out kind); sym = tab.FindSym(name); if (sym != null) { SemErr("name declared twice"); } else { sym = tab.NewSym(typ, name, t.line); sym.tokenKind = Symbol.fixedToken; } tokenString = null; while (!(StartOf(5))) { SynErr(43); Get(); } if (la.kind == 17) { Get(); TokenExpr(out g); Expect(18); if (kind == str) { SemErr("a literal must not be declared with a structure"); } tab.Finish(g); if (tokenString == null || tokenString.Equals(noString)) { dfa.ConvertToStates(g.l, sym); } else // TokenExpr is a single string { if (tab.literals[tokenString] != null) { SemErr("token string declared twice"); } tab.literals[tokenString] = sym; dfa.MatchLiteral(tokenString, sym); } } else if (StartOf(6)) { if (kind == id) { genScanner = false; } else { dfa.MatchLiteral(sym.name, sym); } } else { SynErr(44); } if (la.kind == 39) { SemText(out sym.semPos); if (typ != Node.pr) { SemErr("semantic action not allowed here"); } } }
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); } }