Пример #1
0
        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
        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
 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
 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
        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;
	}