Пример #1
0
		static void TokenTerm(out Graph g) {
			Graph g2;
			TokenFactor(out g);
			while (StartOf(16)) {
				TokenFactor(out g2);
				Graph.MakeSequence(g, g2);
			}
			if (la.kind == 37) {
				Get();
				Expect(28);
				TokenExpr(out g2);
				Graph.SetContextTrans(g2.l); Graph.MakeSequence(g, g2);
				Expect(29);
			}
		}
Пример #2
0
        void Term(out Graph g)
        {
            Graph g2; Node rslv = null; g = null;
            if (StartOf(19)) {
            if (la.kind == 44 || la.kind == 45) {
                if (la.kind == 44) {
                    rslv = tab.NewNode(Node.rslv, null, la.line, la.col);
                    Resolver(out rslv.pos);
                    g = new Graph(rslv);
                } else {
                    rslv = tab.NewNode(Node.expectedConflict, null, la.line, la.col);
                    ExpectedConflict(out rslv.pos, out rslv.conflictSymbols);
                    g = new Graph(rslv);
                }
            }
            Factor(out g2);
            if (rslv != null) tab.MakeSequence(g, g2);
              else g = g2;

            while (StartOf(20)) {
                Factor(out g2);
                tab.MakeSequence(g, g2);
            }
            } else if (StartOf(21)) {
            g = new Graph(tab.NewNode(Node.eps));
            } else SynErr(58);
            if (g == null) // invalid start of Term
            g = new Graph(tab.NewNode(Node.eps));
        }
Пример #3
0
        void TokenFactor(out Graph g)
        {
            string name; int kind; g = null;
            if (la.kind == 1 || la.kind == 3 || la.kind == 5) {
            Sym(out name, out kind);
            if (kind == isIdent) {
                CharClass c = tab.FindCharClass(name);
                if (c == null) {
                  SemErr("undefined name");
                  c = tab.NewCharClass(name, new CharSet());
                }
                Node p = tab.NewNode(Node.clas); p.val = c.n;
                g = new Graph(p);
                tokenString = noString;
              } else { // str
                g = tab.StrToGraph(name);
                if (tokenString == null) tokenString = name;
                else tokenString = noString;
              }

            } else if (la.kind == 37) {
            Get();
            TokenExpr(out g);
            Expect(38);
            } else if (la.kind == 39) {
            Get();
            TokenExpr(out g);
            Expect(40);
            tab.MakeOption(g, t.line, 0); tokenString = noString;
            } else if (la.kind == 41) {
            Get();
            TokenExpr(out g);
            Expect(42);
            tab.MakeIteration(g, t.line, 0); tokenString = noString;
            } else SynErr(61);
            if (g == null) // invalid start of TokenFactor
             g = new Graph(tab.NewNode(Node.eps));
        }
Пример #4
0
Файл: Tab.cs Проект: ggrov/tacny
	public void Finish(Graph g) {
		Node p = g.r;
		while (p != null) {
			Node q = p.next; p.next = null;
			p = q;
		}
	}
Пример #5
0
        void Expression(out Graph g)
        {
            Graph g2;
            Term(out g);
            bool first = true;
            while (WeakSeparator(34,17,18) ) {
            Term(out g2);
            if (first) { tab.MakeFirstAlt(g); first = false; }
              tab.MakeAlternative(g, g2);

            }
        }
Пример #6
0
Файл: Tab.cs Проект: ggrov/tacny
	// The result will be in g1
	public void MakeAlternative(Graph g1, Graph g2) {
		g2.l = NewNode(Node.alt, g2.l); g2.l.line = g2.l.sub.line;
		g2.l.up = true;
		g2.r.up = true;
		Node p = g1.l; while (p.down != null) p = p.down;
		p.down = g2.l;
		p = g1.r; while (p.next != null) p = p.next;
		// append alternative to g1 end list
		p.next = g2.l;
		// append g2 end list to g1 end list
		g2.l.next = g2.r;
	}
Пример #7
0
Файл: Tab.cs Проект: ggrov/tacny
	public void MakeIteration(Graph g) {
		g.l = NewNode(Node.iter, g.l);
		g.r.up = true;
		Node p = g.r;
		g.r = g.l;
		while (p != null) {
			Node q = p.next; p.next = g.l;
			p = q;
		}
	}
Пример #8
0
 public void MakeIteration(Graph g, int line, int col)
 {
     g.l = NewNode(Node.iter, g.l);
     g.l.line = line; g.l.col = col;
     g.r.up = true;
     Node p = g.r;
     g.r = g.l;
     while (p != null) {
     Node q = p.next; p.next = g.l;
     p = q;
     }
 }
Пример #9
0
 public void MakeOption(Graph g, int line, int col)
 {
     g.l = NewNode(Node.opt, g.l);
     g.l.line = line; g.l.col = col;
     g.r.up = true;
     g.l.next = g.r;
     g.r = g.l;
 }
Пример #10
0
	public static void MakeOption(Graph g) {
		g.l = new Node(Node.opt, g.l);
		g.l.next = g.r;
		g.r = g.l;
	}
Пример #11
0
	public static Graph StrToGraph(string str) {
		string s = DFA.Unescape(str.Substring(1, str.Length-2));
		if (s.IndexOf('\0') >= 0) Parser.SemErr("\\0 not allowed here. Used as eof character");
		if (s.Length == 0) Parser.SemErr("empty token not allowed");
		Graph g = new Graph();
		g.r = dummyNode;
		for (int i = 0; i < s.Length; i++) {
			Node p = new Node(Node.chr, (int)s[i], 0);
			g.r.next = p; g.r = p;
		}
		g.l = dummyNode.next; dummyNode.next = null;
		return g;
	}
Пример #12
0
	public static void MakeAlternative(Graph g1, Graph g2) {
		g2.l = new Node(Node.alt, g2.l); g2.l.line = g2.l.sub.line;
		Node p = g1.l; while (p.down != null) p = p.down;
		p.down = g2.l;
		p = g1.r; while (p.next != null) p = p.next;
		p.next = g2.r;
	}
Пример #13
0
	public static void MakeFirstAlt(Graph g) {
		g.l = new Node(Node.alt, g.l); g.l.line = g.l.sub.line; /* AW 2002-03-07 make line available for error handling */
		g.l.next = g.r;
		g.r = g.l;
	}
Пример #14
0
		static void TokenFactor(out Graph g) {
			string name; int kind;
			g = new Graph();
			if (la.kind == 1 || la.kind == 3 || la.kind == 5) {
				Sym(out name, out kind);
				if (kind == id) {
					CharClass c = CharClass.Find(name);
					if (c == null) {
						SemErr("undefined name");
						c = new CharClass(name, new BitArray(CharClass.charSetSize));
					}
					Node p = new Node(Node.clas, null, 0); p.val = c.n;
					g = new Graph(p);
				} else g = Graph.StrToGraph(name);  // str
				
			} else if (la.kind == 28) {
				Get();
				TokenExpr(out g);
				Expect(29);
			} else if (la.kind == 30) {
				Get();
				TokenExpr(out g);
				Expect(31);
				Graph.MakeOption(g);
			} else if (la.kind == 32) {
				Get();
				TokenExpr(out g);
				Expect(33);
				Graph.MakeIteration(g);
			} else SynErr(54);
		}
Пример #15
0
	void Factor(
#line 341 "Coco.atg" //SOURCE beg=14902,len=11,col=8
								out Graph g
#line default //END SOURCE
) {

#line 341 "Coco.atg" //SOURCE beg=14930,len=137,col=36
																																				string name; int kind; Position pos; bool weak = false; 
                                   g = null;
                                 
#line default //END SOURCE
		switch (la.kind) {
		case _ident: case _string: case _char: case 30: {
			if (la.kind == 30) {
				Get();

#line 345 "Coco.atg" //SOURCE beg=15109,len=13,col=36
																																				weak = true; 
#line default //END SOURCE
			}
			Sym(
#line 347 "Coco.atg" //SOURCE beg=15137,len=18,col=7
							out name, out kind
#line default //END SOURCE
);

#line 347 "Coco.atg" //SOURCE beg=15166,len=1542,col=36
																																				Symbol sym = tab.FindSym(name);
                                   if (sym == null && kind == str)
                                     sym = tab.literals[name] as Symbol;
                                   bool undef = sym == null;
                                   if (undef) {
                                     if (kind == id)
                                       sym = tab.NewSym(Node.nt, name, 0);  // forward nt
                                     else if (genScanner) { 
                                       sym = tab.NewSym(Node.t, name, t.line);
                                       dfa.MatchLiteral(sym.name, 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)
                                     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 = tab.NewNode(typ, sym, t.line);
                                   g = new Graph(p);
                                 
#line default //END SOURCE
			if (la.kind == 25 || la.kind == 27) {
				Attribs(
#line 371 "Coco.atg" //SOURCE beg=16724,len=1,col=13
													p
#line default //END SOURCE
);

#line 371 "Coco.atg" //SOURCE beg=16747,len=62,col=36
																																				if (kind != id) SemErr("a literal must not have attributes"); 
#line default //END SOURCE
			}

#line 372 "Coco.atg" //SOURCE beg=16848,len=312,col=36
																																				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");
                                 
#line default //END SOURCE
			break;
		}
		case 31: {
			Get();
			Expression(
#line 377 "Coco.atg" //SOURCE beg=17181,len=5,col=18
																		out g
#line default //END SOURCE
);
			Expect(32);
			break;
		}
		case 33: {
			Get();
			Expression(
#line 378 "Coco.atg" //SOURCE beg=17210,len=5,col=18
																		out g
#line default //END SOURCE
);
			Expect(34);

#line 378 "Coco.atg" //SOURCE beg=17228,len=19,col=36
																																				tab.MakeOption(g); 
#line default //END SOURCE
			break;
		}
		case 35: {
			Get();
			Expression(
#line 379 "Coco.atg" //SOURCE beg=17268,len=5,col=18
																		out g
#line default //END SOURCE
);
			Expect(36);

#line 379 "Coco.atg" //SOURCE beg=17286,len=22,col=36
																																				tab.MakeIteration(g); 
#line default //END SOURCE
			break;
		}
		case 40: {
			SemText(
#line 380 "Coco.atg" //SOURCE beg=17322,len=7,col=11
											out pos
#line default //END SOURCE
);

#line 380 "Coco.atg" //SOURCE beg=17347,len=178,col=36
																																				Node p = tab.NewNode(Node.sem, null, 0);
                                   p.pos = pos;
                                   g = new Graph(p);
                                 
#line default //END SOURCE
			break;
		}
		case 24: {
			Get();

#line 384 "Coco.atg" //SOURCE beg=17564,len=163,col=36
																																				Node p = tab.NewNode(Node.any, null, 0);  // p.set is set in tab.SetupAnys
                                   g = new Graph(p);
                                 
#line default //END SOURCE
			break;
		}
		case 37: {
			Get();

#line 387 "Coco.atg" //SOURCE beg=17766,len=130,col=36
																																				Node p = tab.NewNode(Node.sync, null, 0);
                                   g = new Graph(p);
                                 
#line default //END SOURCE
			break;
		}
		default: SynErr(52); break;
		}

#line 390 "Coco.atg" //SOURCE beg=17935,len=161,col=36
																																				if (g == null) // invalid start of Factor
                                     g = new Graph(tab.NewNode(Node.eps, null, 0));
                                 
#line default //END SOURCE
	}
Пример #16
0
	void Term(out Graph g) {
		Graph g2; Node rslv = null; g = null; 
		if (StartOf(17)) {
			if (la.kind == 37) {
				rslv = tab.NewNode(Node.rslv, null, la.line); 
				Resolver(out rslv.pos);
				g = new Graph(rslv); 
			}
			Factor(out g2);
			if (rslv != null) tab.MakeSequence(g, g2);
			else g = g2;
			
			while (StartOf(18)) {
				Factor(out g2);
				tab.MakeSequence(g, g2); 
			}
		} else if (StartOf(19)) {
			g = new Graph(tab.NewNode(Node.eps, null, 0)); 
		} else SynErr(48);
		if (g == null) // invalid start of Term
		 g = new Graph(tab.NewNode(Node.eps, null, 0));
		
	}
Пример #17
0
Файл: Tab.cs Проект: ggrov/tacny
	public void MakeFirstAlt(Graph g) {
		g.l = NewNode(Node.alt, g.l); g.l.line = g.l.sub.line;
		g.r.up = true;
		g.l.next = g.r;
		g.r = g.l;
	}
Пример #18
0
	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 29: {
			if (la.kind == 29) {
				Get();
				weak = true; 
			}
			Sym(out name, out kind);
			Symbol sym = tab.FindSym(name);
			if (sym == null && kind == str)
			  sym = tab.literals[name] as Symbol;
			bool undef = sym == null;
			if (undef) {
			  if (kind == id)
			    sym = tab.NewSym(Node.nt, name, 0);  // forward nt
			  else if (genScanner) { 
			    sym = tab.NewSym(Node.t, name, t.line);
			    dfa.MatchLiteral(sym.name, 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)
			  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 = tab.NewNode(typ, sym, t.line);
			g = new Graph(p);
			
			if (la.kind == 24 || la.kind == 26) {
				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 30: {
			Get();
			Expression(out g);
			Expect(31);
			break;
		}
		case 32: {
			Get();
			Expression(out g);
			Expect(33);
			tab.MakeOption(g); 
			break;
		}
		case 34: {
			Get();
			Expression(out g);
			Expect(35);
			tab.MakeIteration(g); 
			break;
		}
		case 39: {
			SemText(out pos);
			Node p = tab.NewNode(Node.sem, null, 0);
			p.pos = pos;
			g = new Graph(p);
			
			break;
		}
		case 23: {
			Get();
			Node p = tab.NewNode(Node.any, null, 0);  // p.set is set in tab.SetupAnys
			g = new Graph(p);
			
			break;
		}
		case 36: {
			Get();
			Node p = tab.NewNode(Node.sync, null, 0);
			g = new Graph(p);
			
			break;
		}
		default: SynErr(49); break;
		}
		if (g == null) // invalid start of Factor
		 g = new Graph(tab.NewNode(Node.eps, null, 0));
		
	}
Пример #19
0
Файл: Tab.cs Проект: ggrov/tacny
	// The result will be in g1
	public void MakeSequence(Graph g1, Graph g2) {
		Node p = g1.r.next; g1.r.next = g2.l; // link head node
		while (p != null) {  // link substructure
			Node q = p.next; p.next = g2.l;
			p = q;
		}
		g1.r = g2.r;
	}
Пример #20
0
	void TokenTerm(
#line 422 "Coco.atg" //SOURCE beg=19117,len=11,col=11
											out Graph g
#line default //END SOURCE
) {

#line 422 "Coco.atg" //SOURCE beg=19142,len=10,col=36
																																				Graph g2; 
#line default //END SOURCE
		TokenFactor(
#line 424 "Coco.atg" //SOURCE beg=19173,len=5,col=15
															out g
#line default //END SOURCE
);
		while (StartOf(7)) {
			TokenFactor(
#line 425 "Coco.atg" //SOURCE beg=19197,len=6,col=17
																	out g2
#line default //END SOURCE
);

#line 425 "Coco.atg" //SOURCE beg=19216,len=25,col=36
																																				tab.MakeSequence(g, g2); 
#line default //END SOURCE
		}
		if (la.kind == 39) {
			Get();
			Expect(31);
			TokenExpr(
#line 428 "Coco.atg" //SOURCE beg=19283,len=6,col=19
																			out g2
#line default //END SOURCE
);

#line 428 "Coco.atg" //SOURCE beg=19300,len=112,col=36
																																				tab.SetContextTrans(g2.l); dfa.hasCtxMoves = true;
                                   tab.MakeSequence(g, g2); 
#line default //END SOURCE
			Expect(32);
		}
	}
Пример #21
0
Файл: Tab.cs Проект: ggrov/tacny
	public void MakeOption(Graph g) {
		g.l = NewNode(Node.opt, g.l);
		g.r.up = true;
		g.l.next = g.r;
		g.r = g.l;
	}
Пример #22
0
	void TokenFactor(
#line 436 "Coco.atg" //SOURCE beg=19539,len=11,col=13
													out Graph g
#line default //END SOURCE
) {

#line 436 "Coco.atg" //SOURCE beg=19562,len=23,col=36
																																				string name; int kind; 
#line default //END SOURCE

#line 438 "Coco.atg" //SOURCE beg=19627,len=10,col=36
																																				g = null; 
#line default //END SOURCE
		if (la.kind == _ident || la.kind == _string || la.kind == _char) {
			Sym(
#line 439 "Coco.atg" //SOURCE beg=19647,len=18,col=7
							out name, out kind
#line default //END SOURCE
);

#line 439 "Coco.atg" //SOURCE beg=19676,len=888,col=36
																																				if (kind == id) {
                                     CharClass c = tab.FindCharClass(name);
                                     if (c == null) {
                                       SemErr("undefined name");
                                       c = tab.NewCharClass(name, new CharSet());
                                     }
                                     Node p = tab.NewNode(Node.clas, null, 0); p.val = c.n;
                                     g = new Graph(p);
                                     tokenString = noString;
                                   } else { // str
                                     g = tab.StrToGraph(name);
                                     if (tokenString == null) tokenString = name;
                                     else tokenString = noString;
                                   }
                                 
#line default //END SOURCE
		} else if (la.kind == 31) {
			Get();
			TokenExpr(
#line 454 "Coco.atg" //SOURCE beg=20584,len=5,col=17
																	out g
#line default //END SOURCE
);
			Expect(32);
		} else if (la.kind == 33) {
			Get();
			TokenExpr(
#line 455 "Coco.atg" //SOURCE beg=20612,len=5,col=17
																	out g
#line default //END SOURCE
);
			Expect(34);

#line 455 "Coco.atg" //SOURCE beg=20631,len=19,col=36
																																				tab.MakeOption(g); 
#line default //END SOURCE
		} else if (la.kind == 35) {
			Get();
			TokenExpr(
#line 456 "Coco.atg" //SOURCE beg=20670,len=5,col=17
																	out g
#line default //END SOURCE
);
			Expect(36);

#line 456 "Coco.atg" //SOURCE beg=20689,len=22,col=36
																																				tab.MakeIteration(g); 
#line default //END SOURCE
		} else SynErr(54);

#line 457 "Coco.atg" //SOURCE beg=20750,len=132,col=36
																																				if (g == null) // invalid start of TokenFactor
                                     g = new Graph(tab.NewNode(Node.eps, null, 0)); 
#line default //END SOURCE
	}
Пример #23
0
Файл: Tab.cs Проект: ggrov/tacny
	public Graph StrToGraph(string str) {
		string s = Unescape(str.Substring(1, str.Length-2));
		if (s.Length == 0) parser.SemErr("empty token not allowed");
		Graph g = new Graph();
		g.r = dummyNode;
		for (int i = 0; i < s.Length; i++) {
			Node p = NewNode(Node.chr, (int)s[i], 0);
			g.r.next = p; g.r = p;
		}
		g.l = dummyNode.next; dummyNode.next = null;
		return g;
	}
Пример #24
0
	void TokenExpr(
#line 409 "Coco.atg" //SOURCE beg=18670,len=11,col=11
											out Graph g
#line default //END SOURCE
) {

#line 409 "Coco.atg" //SOURCE beg=18695,len=10,col=36
																																				Graph g2; 
#line default //END SOURCE
		TokenTerm(
#line 411 "Coco.atg" //SOURCE beg=18724,len=5,col=13
													out g
#line default //END SOURCE
);

#line 411 "Coco.atg" //SOURCE beg=18747,len=19,col=36
																																				bool first = true; 
#line default //END SOURCE
		while (WeakSeparator(29,7,8) ) {
			TokenTerm(
#line 414 "Coco.atg" //SOURCE beg=18831,len=6,col=15
															out g2
#line default //END SOURCE
);

#line 414 "Coco.atg" //SOURCE beg=18852,len=149,col=36
																																				if (first) { tab.MakeFirstAlt(g); first = false; }
                                   tab.MakeAlternative(g, g2);
                                 
#line default //END SOURCE
		}
	}
Пример #25
0
        void Factor(out Graph g)
        {
            string name; int kind; Position pos; bool weak = false; bool greedy = false;
            g = null;

            switch (la.kind) {
            case 1: case 3: case 5: case 35: case 36: {
            if (la.kind == 35) {
                Get();
                weak = true;
            }
            if (la.kind == 36) {
                Get();
                greedy = true;
            }
            Sym(out name, out kind);
            Symbol sym = tab.FindSym(name);
              if (sym == null && kind == isLiteral)
                sym = tab.literals[name] as Symbol;
              bool undef = (sym == null);
              if (undef) {
                sym = ForwardDeclare(name, kind);
              }
              int typ = sym.typ;
              if (typ != Node.t && typ != Node.nt)
                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");
              if (greedy && typ != Node.nt)
              	SemErr("only nonterminals may be greedy");
              Node p = tab.NewNode(typ, sym, t.line, t.col);
              p.greedy = greedy;
              g = new Graph(p);

            if (la.kind == 30 || la.kind == 32) {
                Attribs(p);
            }
            if (undef)
                sym.attrPos = p.pos;  // dummy
              else if (kind != isLiteral && (p.pos == null) != (sym.attrPos == null || sym.isAuto))
                SemErr("attribute mismatch between declaration and use of this symbol");

            break;
            }
            case 37: {
            Get();
            Expression(out g);
            Expect(38);
            break;
            }
            case 39: {
            Get();
            int line = t.line; int col = t.col;
            Expression(out g);
            tab.MakeOption(g, line, col);
            Expect(40);
            break;
            }
            case 41: {
            Get();
            int line = t.line; int col = t.col;
            Expression(out g);
            tab.MakeIteration(g, line, col);
            Expect(42);
            break;
            }
            case 48: {
            SemText(out pos);
            Node p = tab.NewNode(Node.sem);
              p.pos = pos;
              g = new Graph(p);

            break;
            }
            case 28: {
            Get();
            Node p = tab.NewNode(Node.any, null, t.line, t.col);  // p.set is set in tab.SetupAnys
              g = new Graph(p);

            break;
            }
            case 43: {
            Get();
            Node p = tab.NewNode(Node.sync, null, t.line, t.col);
              g = new Graph(p);

            break;
            }
            default: SynErr(59); break;
            }
            if (g == null) // invalid start of Factor
            g = new Graph(tab.NewNode(Node.eps));
        }
Пример #26
0
	void Expression(
#line 310 "Coco.atg" //SOURCE beg=13613,len=11,col=12
												out Graph g
#line default //END SOURCE
) {

#line 310 "Coco.atg" //SOURCE beg=13637,len=10,col=36
																																				Graph g2; 
#line default //END SOURCE
		Term(
#line 312 "Coco.atg" //SOURCE beg=13662,len=5,col=8
								out g
#line default //END SOURCE
);

#line 312 "Coco.atg" //SOURCE beg=13690,len=19,col=36
																																				bool first = true; 
#line default //END SOURCE
		while (WeakSeparator(29,15,16) ) {
			Term(
#line 315 "Coco.atg" //SOURCE beg=13769,len=6,col=10
										out g2
#line default //END SOURCE
);

#line 315 "Coco.atg" //SOURCE beg=13795,len=149,col=36
																																				if (first) { tab.MakeFirstAlt(g); first = false; }
                                   tab.MakeAlternative(g, g2);
                                 
#line default //END SOURCE
		}
	}
Пример #27
0
        void TokenExpr(out Graph g)
        {
            Graph g2;
            TokenTerm(out g);
            bool first = true;
            while (WeakSeparator(34,9,10) ) {
            TokenTerm(out g2);
            if (first) { tab.MakeFirstAlt(g); first = false; }
              tab.MakeAlternative(g, g2);

            }
        }
Пример #28
0
	void Term(
#line 323 "Coco.atg" //SOURCE beg=14055,len=11,col=6
						out Graph g
#line default //END SOURCE
) {

#line 323 "Coco.atg" //SOURCE beg=14085,len=38,col=36
																																				Graph g2; Node rslv = null; g = null; 
#line default //END SOURCE
		if (StartOf(17)) {
			if (la.kind == 38) {

#line 325 "Coco.atg" //SOURCE beg=14165,len=46,col=36
																																				rslv = tab.NewNode(Node.rslv, null, la.line); 
#line default //END SOURCE
				Resolver(
#line 326 "Coco.atg" //SOURCE beg=14228,len=12,col=14
														out rslv.pos
#line default //END SOURCE
);

#line 326 "Coco.atg" //SOURCE beg=14250,len=21,col=36
																																				g = new Graph(rslv); 
#line default //END SOURCE
			}
			Factor(
#line 328 "Coco.atg" //SOURCE beg=14289,len=6,col=10
										out g2
#line default //END SOURCE
);

#line 328 "Coco.atg" //SOURCE beg=14315,len=126,col=36
																																				if (rslv != null) tab.MakeSequence(g, g2);
                                   else g = g2;
                                 
#line default //END SOURCE
			while (StartOf(18)) {
				Factor(
#line 331 "Coco.atg" //SOURCE beg=14456,len=6,col=12
												out g2
#line default //END SOURCE
);

#line 331 "Coco.atg" //SOURCE beg=14480,len=25,col=36
																																				tab.MakeSequence(g, g2); 
#line default //END SOURCE
			}
		} else if (StartOf(19)) {

#line 333 "Coco.atg" //SOURCE beg=14549,len=47,col=36
																																				g = new Graph(tab.NewNode(Node.eps, null, 0)); 
#line default //END SOURCE
		} else SynErr(51);

#line 334 "Coco.atg" //SOURCE beg=14635,len=159,col=36
																																				if (g == null) // invalid start of Term
                                     g = new Graph(tab.NewNode(Node.eps, null, 0));
                                 
#line default //END SOURCE
	}
Пример #29
0
 void TokenTerm(out Graph g)
 {
     Graph g2;
     TokenFactor(out g);
     while (StartOf(9)) {
     TokenFactor(out g2);
     tab.MakeSequence(g, g2);
     }
     if (la.kind == 47) {
     Get();
     Expect(37);
     TokenExpr(out g2);
     tab.SetContextTrans(g2.l);
     dfa.hasCtxMoves = true;
     tab.MakeSequence(g, g2);
     Expect(38);
     }
 }
Пример #30
0
		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;
			}
		}