示例#1
0
 public static void ConvertToStates(Node p, Symbol sym)
 {
     curGraph = p; curSy = sym;
     if (Node.DelGraph(curGraph))
     {
         Parser.SemErr("token might be empty");
     }
     NumberNodes(curGraph, firstState);
     FindTrans(curGraph, true, new BitArray(Node.nodes.Count));
 }
示例#2
0
        static void NumberNodes(Node p, State state)
        {
            /* Assigns a state n.state to every node n. There will be a transition from
             * n.state to n.next.state triggered by n.val. All nodes in an alternative
             * chain are represented by the same state.
             */
            if (p == null)
            {
                return;
            }
            if (p.state != null)
            {
                return;              // already visited;
            }
            if (state == null)
            {
                state = NewState();
            }
            p.state = state;
            if (Node.DelGraph(p))
            {
                state.endOf = curSy;
            }
            switch (p.typ)
            {
            case Node.clas:
            case Node.chr:
            {
                NumberNodes(p.next, null);
                break;
            }

            case Node.opt:
            {
                NumberNodes(p.next, null);
                NumberNodes(p.sub, state);
                break;
            }

            case Node.iter:
            {
                NumberNodes(p.next, state);
                NumberNodes(p.sub, state);
                break;
            }

            case Node.alt:
            {
                NumberNodes(p.sub, state);
                NumberNodes(p.down, state);
                break;
            }
            }
        }
示例#3
0
	static void GetSingles(Node p, ArrayList singles) {
		if (p == null) return;  // end of graph
		if (p.typ == Node.nt) {
			if (p.up || Node.DelGraph(p.next)) singles.Add(p.sym);
		} else if (p.typ == Node.alt || p.typ == Node.iter || p.typ == Node.opt) {
			if (p.up || Node.DelGraph(p.next)) {
				GetSingles(p.sub, singles);
				if (p.typ == Node.alt) GetSingles(p.down, singles);
			}
		}
		if (!p.up && Node.DelNode(p)) GetSingles(p.next, singles);
	}
示例#4
0
	public static void CompDeletableSymbols() {
		bool changed;
		do {
			changed = false;
			foreach (Symbol sym in Symbol.nonterminals)
				if (!sym.deletable && sym.graph != null && Node.DelGraph(sym.graph)) {
					sym.deletable = true; changed = true;
				}
		} while (changed);
		foreach (Symbol sym in Symbol.nonterminals)
			if (sym.deletable) Console.WriteLine("  {0} deletable", sym.name);
	}
示例#5
0
	static void CompFollow(Node p) {
		while (p != null && !visited[p.n]) {
			visited[p.n] = true;
			if (p.typ == Node.nt) {
				BitArray s = First(p.next);
				p.sym.follow.Or(s);
				if (Node.DelGraph(p.next))
					p.sym.nts[curSy.n] = true;
			} else if (p.typ == Node.opt || p.typ == Node.iter) {
				CompFollow(p.sub);
			} else if (p.typ == Node.alt) {
				CompFollow(p.sub); CompFollow(p.down);
			}
			p = p.next;
		}
	}
示例#6
0
	public static BitArray Expected(Node p, Symbol curSy, int outmost) {
		BitArray s = First(p);
		if (Node.DelGraph(p)) s.Or(curSy.follow);
		return s;
	}