Exemple #1
0
 /// <summary>
 /// Creates a new LALR parser.
 /// </summary>
 /// <param name="tokenizer">A tokenizer.</param>
 /// <param name="states">The LALR states.</param>
 /// <param name="startState">The starting state.</param>
 /// <param name="symbols"></param>
 public LALRParser(IStringTokenizer tokenizer, StateCollection states, State startState, SymbolCollection symbols)
 {
     this.tokenizer = tokenizer;
     this.states = states;
     this.startState = startState;
     this.symbols = symbols;
     storeTokens = StoreTokensMode.NoUserObject;
 }
Exemple #2
0
		private void Reset()
		{
			stream = null;
			structure = null;
			content = null;
			dfaStates = null;
			parserStates = null;
			symbols = null;
			rules = null;
		}
Exemple #3
0
 /// <summary>
 /// Creates a new LALR parser.
 /// </summary>
 /// <param name="tokenizer">A tokenizer.</param>
 /// <param name="states">The LALR states.</param>
 /// <param name="startState">The starting state.</param>
 public LALRParser(IStringTokenizer tokenizer,
                   StateCollection states,
                   State startState,
                   SymbolCollection symbols)
 {
     this.tokenizer  = tokenizer;
     this.states     = states;
     this.startState = startState;
     this.symbols    = symbols;
     storeTokens     = StoreTokensMode.NoUserObject;
 }
Exemple #4
0
        private SymbolCollection CreateSymbols(CGTContent content)
        {
            SymbolCollection symbols = new SymbolCollection();

            foreach (SymbolRecord symbolRecord in content.SymbolTable)
            {
                Symbol symbol = SymbolFactory.CreateSymbol(symbolRecord);
                symbols.Add(symbol);
            }
            return(symbols);
        }
Exemple #5
0
        private SymbolCollection FindExpectedTokens()
        {
            SymbolCollection symbols = new SymbolCollection();
            State            state   = stateStack.Peek();

            foreach (Action action in state.Actions)
            {
                if ((action is ShiftAction) || (action is ReduceAction) || (action is AcceptAction))
                {
                    symbols.Add(action.symbol);
                }
            }
            return(symbols);
        }
Exemple #6
0
		private SymbolCollection FindExpectedTokens()
		{
			SymbolCollection symbols = new SymbolCollection();
			State state = stateStack.Peek();
			foreach(Action action in state.Actions)
			{
				if ((action is ShiftAction) || (action is ReduceAction) 
					|| (action is AcceptAction))
				{
					symbols.Add(action.symbol);
				}
			}
			return symbols;
		}
Exemple #7
0
 public ParseErrorEventArgs(TerminalToken unexpectedToken, SymbolCollection expectedTokens)
 {
     this.unexpectedToken = unexpectedToken;
     this.expectedTokens = expectedTokens;
     contin = ContinueMode.Stop;
     nextToken = null;
 }
Exemple #8
0
 private SymbolCollection CreateSymbols(CGTContent content)
 {
     SymbolCollection symbols = new SymbolCollection();
     foreach (SymbolRecord symbolRecord in content.SymbolTable)
     {
         Symbol symbol = SymbolFactory.CreateSymbol(symbolRecord);
         symbols.Add(symbol);
     }
     return symbols;
 }
Exemple #9
0
        private DFA.StateCollection CreateDFAStates(CGTContent content)
        {
            symbols = CreateSymbols(content);
            DFA.StateCollection states = new DFA.StateCollection();
            foreach (DFAStateRecord stateRecord in content.DFAStateTable)
            {
                DFA.State state;
                if (stateRecord.AcceptState)
                {
                    Symbol symbol = symbols[stateRecord.AcceptIndex];

                    state = new DFA.EndState(stateRecord.Index,(SymbolTerminal)symbol);
                    //todo: type checking (exception?)
                }
                else
                {
                    state = new DFA.State(stateRecord.Index);
                }
                states.Add(state);
            }

            foreach (DFAStateRecord stateRecord in content.DFAStateTable)
            {
                foreach (EdgeSubRecord edgeRecord in stateRecord.EdgeSubRecords)
                {
                    DFA.State source = states[stateRecord.Index];
                    DFA.State target = states[edgeRecord.TargetIndex];
                    CharacterSetRecord charsetRec = content.CharacterSetTable[edgeRecord.CharacterSetIndex];
                    DFA.Transition transition = new DFA.Transition(target,charsetRec.Characters);
                    source.Transitions.Add(transition);
                }
            }
            return states;
        }
Exemple #10
0
		public ParseErrorEventArgs(TerminalToken unexpectedToken,
			                       SymbolCollection expectedTokens)
		{
			this.unexpectedToken = unexpectedToken;
			this.expectedTokens = expectedTokens;
			this.contin = false;
			this.nextToken = null;
		}