示例#1
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 == 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;
                    }
                }
            }
            else if (la.kind == 30)
            {
                Get();
                TokenExpr(out g);
                Expect(31);
            }
            else if (la.kind == 32)
            {
                Get();
                TokenExpr(out g);
                Expect(33);
                tab.MakeOption(g); tokenString = noString;
            }
            else if (la.kind == 34)
            {
                Get();
                TokenExpr(out g);
                Expect(35);
                tab.MakeIteration(g); tokenString = noString;
            }
            else
            {
                SynErr(51);
            }
            if (g == null)     // invalid start of TokenFactor
            {
                g = new Graph(tab.NewNode(Node.eps, null, 0));
            }
        }
示例#2
0
文件: Tab.cs 项目: ggrov/tacny
	public CharClass NewCharClass(string name, CharSet s) {
		if (name == "#") name = "#" + (char)dummyName++;
		CharClass c = new CharClass(name, s);
		c.n = classes.Count;
		classes.Add(c);
		return c;
	}
示例#3
0
        void SimSet(out CharSet s)
        {
            int n1, n2;

            s = new CharSet();
            Notify(6); // Coco-Plugin: notify parsercustomization
            if (la.kind == 1)
            {
                Get();
                CharClass c = tab.FindCharClass(t.val);
                Notify(7); // Coco-Plugin: notify parsercustomization
                if (c == null)
                {
                    SemErr("undefined name");
                }
                else
                {
                    s.Or(c.set);
                }
            }
            else if (la.kind == 3)
            {
                Get();
                string name = t.val;
                name = tab.Unescape(name.Substring(1, name.Length - 2));
                foreach (char ch in name)
                {
                    if (dfa.ignoreCase)
                    {
                        s.Set(char.ToLower(ch));
                    }
                    else
                    {
                        s.Set(ch);
                    }
                }
                Notify(7); // Coco-Plugin: notify parsercustomization
            }
            else if (la.kind == 5)
            {
                Char(out n1);
                s.Set(n1);
                if (la.kind == 22)
                {
                    Get();
                    Notify(8); // Coco-Plugin: notify parsercustomization
                    Char(out n2);
                    for (int i = n1; i <= n2; i++)
                    {
                        s.Set(i);
                    }
                }
                Notify(7); // Coco-Plugin: notify parsercustomization
            }
            else if (la.kind == 23)
            {
                Get();
                s = new CharSet(); s.Fill();
                Notify(7); // Coco-Plugin: notify parsercustomization
            }
            else
            {
                SynErr(46);
            }
        }
示例#4
0
        static void WriteState(State state)
        {
            Symbol endOf = state.endOf;

            gen.WriteLine("\t\t\tcase {0}:", state.nr);
            bool ctxEnd = state.ctx;

            for (Action action = state.firstAction; action != null; action = action.next)
            {
                if (action == state.firstAction)
                {
                    gen.Write("\t\t\t\tif (");
                }
                else
                {
                    gen.Write("\t\t\t\telse if (");
                }
                if (action.typ == Node.chr)
                {
                    gen.Write(ChCond((char)action.sym));
                }
                else
                {
                    PutRange(CharClass.Set(action.sym));
                }
                gen.Write(") {");
                if (action.tc == Node.contextTrans)
                {
                    gen.Write("apx++; "); ctxEnd = false;
                }
                else if (state.ctx)
                {
                    gen.Write("apx = 0; ");
                }
                gen.Write("buf.Append(ch); NextCh(); goto case {0};", action.target.state.nr);
                gen.WriteLine("}");
            }
            if (state.firstAction == null)
            {
                gen.Write("\t\t\t\t{");
            }
            else
            {
                gen.Write("\t\t\t\telse {");
            }
            if (ctxEnd)       // final context state: cut appendix
            {
                gen.WriteLine();
                gen.WriteLine("\t\t\t\t\tbuf.Length = buf.Length - apx;");
                gen.WriteLine("\t\t\t\t\tpos = pos - apx - 1; line = t.line;");
                gen.WriteLine("\t\t\t\t\tBuffer.Pos = pos+1; NextCh();");
                gen.Write("\t\t\t\t\t");
            }
            if (endOf == null)
            {
                gen.WriteLine("t.kind = noSym; goto done;}");
            }
            else
            {
                gen.Write("t.kind = {0}; ", endOf.n);
                if (endOf.tokenKind == Symbol.classLitToken)
                {
                    gen.WriteLine("t.val = buf.ToString(); CheckLiteral(); return t;}");
                }
                else
                {
                    gen.WriteLine("goto done;}");
                }
            }
        }
示例#5
0
	public void ShiftWith(BitArray s) {
		if (Sets.Elements(s) == 1) {
			typ = Node.chr; sym = Sets.First(s);
		} else {
			CharClass c = CharClass.Find(s);
			if (c == null) c = new CharClass("#", s); // class with dummy name
			typ = Node.clas; sym = c.n;
		}
	}
示例#6
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);
		}
示例#7
0
		static void SetDecl() {
			BitArray s;
			Expect(1);
			string name = t.val;
			CharClass c = CharClass.Find(name);
			if (c != null) SemErr("name declared twice");
			
			Expect(8);
			Set(out s);
			if (Sets.Elements(s) == 0) SemErr("character set must not be empty");
			c = new CharClass(name, s);
			
			Expect(9);
		}