public Parser(Konsole caller) { _konsole = caller; _last_result = new None(); _stacked_input_queue = new Stack<Queue<Lexicon>>(); _commands[""] = blank; _commands["dv"] = dv; _commands["if"] = ifCond; _commands["add"] = math; _commands["sub"] = math; _commands["div"] = math; _commands["mul"] = math; _commands["#ans"] = getLastAns; _commands["mass"] = mass; _commands["type"] = type; _commands["echo"] = echo; _commands["exec"] = playerExecute; _commands["etype"] = evaluatedType; _commands["mtype"] = multipleType; _commands["lthan"] = equality; _commands["gthan"] = equality; _commands["equal"] = equality; _commands["massT"] = massTotal; _commands["crewco"] = crewCount; _commands["airpress"] = airPressure; _vessel = FlightGlobals.ActiveVessel; }
public Lexicon parseAndExecute(string input) { addInput(input); Lexicon firstLex = nextLexicon(); if (firstLex.Type != DataTypes.Command) { _last_result = new Error(firstLex.getValueAsString() + " is not a command"); } else { _last_result = execute(firstLex); } emptyScope(); // We're exiting this scope, so clear the queue and pop the stack return _last_result; }
private Lexicon execute(Lexicon nextLex) { if (nextLex.Type == DataTypes.Function) { addInput(nextLex.getValueAsString()); Lexicon result = execute(nextLexicon()); return result; } else { while (nextLex.Type == DataTypes.Command) { Command cmd = (Command)nextLex; nextLex = _commands[cmd.Value](cmd); } } return nextLex; }