/// <summary>
        /// Creates a new action by specifying the needed information.
        /// </summary>
        /// <param name="record">A part of the LALR record from the file content.</param>
        /// <param name="states">The LALR states.</param>
        /// <param name="symbols">The symbols.</param>
        /// <param name="rules">The rules.</param>
        /// <returns>A new action object.</returns>
        public static Action CreateAction(ActionSubRecord record, StateCollection states, SymbolCollection symbols,
                                          RuleCollection rules)
        {
            Action action;

            switch (record.Action)
            {
            case 1:
                action = CreateShiftAction(record, symbols, states);
                break;

            case 2:
                action = CreateReduceAction(record, symbols, rules);
                break;

            case 3:
                action = CreateGotoAction(record, symbols, states);
                break;

            case 4:
                action = CreateAcceptAction(record, symbols);
                break;

            default:
                return(null);    //todo: make exception
            }
            return(action);
        }
示例#2
0
 private static GotoAction CreateGotoAction(ActionSubRecord record, SymbolCollection symbols,
     StateCollection states)
 {
     SymbolNonterminal symbol = symbols[record.SymbolIndex] as SymbolNonterminal;
     State state = states[record.Target];
     return new GotoAction(symbol, state);
 }
        private static GotoAction CreateGotoAction(ActionSubRecord record, SymbolCollection symbols,
                                                   StateCollection states)
        {
            SymbolNonterminal symbol = symbols[record.SymbolIndex] as SymbolNonterminal;
            State             state  = states[record.Target];

            return(new GotoAction(symbol, state));
        }
示例#4
0
 private static ShiftAction CreateShiftAction(ActionSubRecord record, SymbolCollection symbols,
     StateCollection states)
 {
     State state = states[record.Target];
     SymbolTerminal symbol = symbols[record.SymbolIndex] as SymbolTerminal;
     //todo: exception symbol type
     return new ShiftAction(symbol, state);
 }
示例#5
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;
 }
        private static ShiftAction CreateShiftAction(ActionSubRecord record, SymbolCollection symbols,
                                                     StateCollection states)
        {
            State          state  = states[record.Target];
            SymbolTerminal symbol = symbols[record.SymbolIndex] as SymbolTerminal;

            //todo: exception symbol type
            return(new ShiftAction(symbol, state));
        }
示例#7
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)
		{
			this.tokenizer = tokenizer;
			this.states = states;
			this.startState = startState;
			this.trimReductions = trimReductions;
			storeTokens = StoreTokensMode.NoUserObject;
		}
示例#8
0
 /// <summary>
 /// Creates a new action by specifying the needed information.
 /// </summary>
 /// <param name="record">A part of the LALR record from the file content.</param>
 /// <param name="states">The LALR states.</param>
 /// <param name="symbols">The symbols.</param>
 /// <param name="rules">The rules.</param>
 /// <returns>A new action object.</returns>
 public static Action CreateAction(ActionSubRecord record,
     StateCollection states,
     SymbolCollection symbols,
     RuleCollection rules)
 {
     Action action;
     switch (record.Action)
     {
         case 1: action = CreateShiftAction(record,symbols,states); break;
         case 2: action = CreateReduceAction(record,symbols,rules); break;
         case 3: action = CreateGotoAction(record,symbols,states); break;
         case 4: action = CreateAcceptAction(record,symbols); break;
         default: return null; //todo: make exception
     }
     return action;
 }