예제 #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;
 }
예제 #2
0
		private void Reset()
		{
			stream = null;
			structure = null;
			content = null;
			dfaStates = null;
			parserStates = null;
			symbols = null;
			rules = null;
		}
예제 #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;
 }
예제 #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);
        }
예제 #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);
        }
예제 #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;
		}
예제 #7
0
 public ParseErrorEventArgs(TerminalToken unexpectedToken, SymbolCollection expectedTokens)
 {
     this.unexpectedToken = unexpectedToken;
     this.expectedTokens = expectedTokens;
     contin = ContinueMode.Stop;
     nextToken = null;
 }
예제 #8
0
파일: Reader.cs 프로젝트: langpavel/LPS-old
 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;
 }
예제 #9
0
파일: Reader.cs 프로젝트: langpavel/LPS-old
        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;
        }
예제 #10
0
		public ParseErrorEventArgs(TerminalToken unexpectedToken,
			                       SymbolCollection expectedTokens)
		{
			this.unexpectedToken = unexpectedToken;
			this.expectedTokens = expectedTokens;
			this.contin = false;
			this.nextToken = null;
		}