示例#1
0
文件: DFA.cs 项目: omaragb/tlp182
        void MeltStates(State state)
        {
            bool     ctx;
            BitArray targets;
            Symbol   endOf;

            for (Action action = state.firstAction; action != null; action = action.next)
            {
                if (action.target.next != null)
                {
                    GetTargetStates(action, out targets, out endOf, out ctx);
                    Melted melt = StateWithSet(targets);
                    if (melt == null)
                    {
                        State s = NewState(); s.endOf = endOf; s.ctx = ctx;
                        for (Target targ = action.target; targ != null; targ = targ.next)
                        {
                            s.MeltWith(targ.state);
                        }
                        MakeUnique(s);
                        melt = NewMelted(targets, s);
                    }
                    action.target.next  = null;
                    action.target.state = melt.state;
                }
            }
        }
示例#2
0
文件: DFA.cs 项目: omaragb/tlp182
        Melted firstMelted;     // head of melted state list

        Melted NewMelted(BitArray set, State state)
        {
            Melted m = new Melted(set, state);

            m.next = firstMelted; firstMelted = m;
            return(m);
        }
示例#3
0
 public Melted(BitArray set, State state)
 {
     this.set   = set;
     this.state = state;
     this.next  = first;
     first      = this;
 }
示例#4
0
文件: DFA.cs 项目: omaragb/tlp182
 Melted StateWithSet(BitArray s)
 {
     for (Melted m = firstMelted; m != null; m = m.next)
     {
         if (Sets.Equals(s, m.set))
         {
             return(m);
         }
     }
     return(null);
 }
示例#5
0
文件: DFA.cs 项目: omaragb/tlp182
 public DFA(Parser parser)
 {
     this.parser = parser;
     tab         = parser.tab;
     errors      = parser.errors;
     trace       = parser.trace;
     firstState  = null; lastState = null; lastStateNr = -1;
     firstState  = NewState();
     firstMelted = null; firstComment = null;
     ignoreCase  = false;
     dirtyDFA    = false;
     hasCtxMoves = false;
 }
示例#6
0
文件: DFA.cs 项目: omaragb/tlp182
        BitArray MeltedSet(int nr)
        {
            Melted m = firstMelted;

            while (m != null)
            {
                if (m.state.nr == nr)
                {
                    return(m.set);
                }
                else
                {
                    m = m.next;
                }
            }
            throw new FatalError("compiler error in Melted.Set");
        }
示例#7
0
        public static BitArray Set(int nr)
        {
            Melted m = first;

            while (m != null)
            {
                if (m.state.nr == nr)
                {
                    return(m.set);
                }
                else
                {
                    m = m.next;
                }
            }
            throw new Exception("-- compiler error in Melted.Set");
        }
示例#8
0
 public void GetTargetStates(out BitArray targets, out Symbol endOf, out bool ctx)
 {
     // compute the set of target states
     targets = new BitArray(DFA.maxStates);
     endOf   = null;
     ctx     = false;
     for (Target t = target; t != null; t = t.next)
     {
         int stateNr = t.state.nr;
         if (stateNr <= DFA.lastSimState)
         {
             targets[stateNr] = true;
         }
         else
         {
             targets.Or(Melted.Set(stateNr));
         }
         if (t.state.endOf != null)
         {
             if (endOf == null || endOf == t.state.endOf)
             {
                 endOf = t.state.endOf;
             }
             else
             {
                 Console.WriteLine("Tokens {0} and {1} cannot be distinguished", endOf.name, t.state.endOf.name);
                 Errors.count++;
             }
         }
         if (t.state.ctx)
         {
             ctx = true;
             // The following check seems to be unnecessary. It reported an error
             // if a symbol + context was the prefix of another symbol, e.g.
             //   s1 = "a" "b" "c".
             //   s2 = "a" CONTEXT("b").
             // But this is ok.
             // if (t.state.endOf != null) {
             //   Console.WriteLine("Ambiguous context clause");
             //	 Errors.count++;
             // }
         }
     }
 }
示例#9
0
 Melted NewMelted(BitArray set, State state)
 {
     Melted m = new Melted(set, state);
     m.next = firstMelted; firstMelted = m;
     return m;
 }
示例#10
0
 public DFA(Parser parser)
 {
     this.parser = parser;
     tab = parser.tab;
     errors = parser.errors;
     trace = parser.trace;
     firstState = null; lastState = null; lastStateNr = -1;
     firstState = NewState();
     firstMelted = null; firstComment = null;
     ignoreCase = false;
     dirtyDFA = false;
     hasCtxMoves = false;
 }
示例#11
0
	static void MeltStates(State state) {
		bool changed, ctx;
		BitArray targets;
		Symbol endOf;
		for (Action action = state.firstAction; action != null; action = action.next) {
			if (action.target.next != null) {
				action.GetTargetStates(out targets, out endOf, out ctx);
				Melted melt = Melted.StateWithSet(targets);
				if (melt == null) {
					State s = NewState(); s.endOf = endOf; s.ctx = ctx;
					for (Target targ = action.target; targ != null; targ = targ.next)
						s.MeltWith(targ.state);
					do {changed = MakeUnique(s);} while (changed);
					melt = new Melted(targets, s);
				}
				action.target.next = null;
				action.target.state = melt.state;
			}
		}
	}
示例#12
0
	public Melted(BitArray set, State state) {
		this.set = set; this.state = state;
		this.next = first; first = this;
	}