private Lexicon playerExecute(Command command) { return execute(nextLexicon()); }
private Lexicon type(Command command) { if (inputSize() > 1 || inputSize() > 1) { return new Error("There must be exactly 1 argument."); } Lexicon arg = nextLexicon(); return new Atom(arg.Type.ToString()); }
private Lexicon math(Command command) { // not sure if they're numbers yet Lexicon arg1 = nextLexicon(); Lexicon arg2 = nextLexicon(); if (arg1 == null || arg2 == null) return new Error("Too few arguments"); if (arg1.Type == DataTypes.Command) arg1 = execute(arg1); if (arg2.Type == DataTypes.Command) arg2 = execute(arg2); if (!arg1.Type.Equals(DataTypes.Number)) return new Error("First arg is not a Number"); if (!arg2.Type.Equals(DataTypes.Number)) return new Error("Second arg is not a Number"); if (command.Value == "add") { return Lexer.generateToken(((Number)arg2).Value + ((Number)arg1).Value, this); } else if (command.Value == "sub") { return Lexer.generateToken(((Number)arg2).Value - ((Number)arg1).Value, this); } else if (command.Value == "mul") { return Lexer.generateToken(((Number)arg2).Value * ((Number)arg1).Value, this); } else { /* (command == "div")*/ return Lexer.generateToken(((Number)arg2).Value / ((Number)arg1).Value, this); } }
private Lexicon multipleType(Command command) { if (inputSize() < 1) { return new Error("There must be at least 1 Command provided"); } Lexicon lex; while (null != (lex = nextLexicon())) { _konsole.printOutput(lex.getValueAsString() + ": " + lex.Type); } return new None(); }
private Lexicon mass(Command command) { return new Number(_vessel.RevealMass()); }
private Lexicon massTotal(Command command) { return new Number(_vessel.GetTotalMass()); }
private Lexicon getLastAns(Command command) { return _last_result; }
private Lexicon ifCond(Command command) { // not a good test for correctness if (inputSize() < 3) { return new Error("If requires the format 'if (Bool) {A} else {B}'"); } Lexicon cond = execute(nextLexicon()); Lexicon true_block = nextLexicon(); Lexicon false_block = nextLexicon(); if (false_block.getValueAsString() == "else") { false_block = nextLexicon(); } if (cond.Type != DataTypes.Bool) { new Error("Expected Bool, received " + cond.Type); } // If BOOL A B // if true, then A // if false, then B // This bit is selecting which code to execute based off of Bool arg1 if (((Bool)cond).Value) { // Lexicon result = _lexer.getNextLexicon(); return execute(true_block); // recursively go until the following expression is done } else { return execute(false_block); // recursively go until the following expression is done } }
private Lexicon equality(Command command) { bool result; if (inputSize() < 2) { return new Error("Must have two values to compare"); } Lexicon arg1 = execute(nextLexicon()); Lexicon arg2 = execute(nextLexicon()); if (arg1.Type != arg2.Type) { return new Error("Data types must be equivalent when comparing"); } if (arg1.Type != DataTypes.Number && command.Value != "equal") { return new Error("Non-Numbers can only be tested for equality using 'equals'"); } switch (arg1.Type) { case DataTypes.Number: Number num1 = (Number)arg1; Number num2 = (Number)arg2; if (command.Value == "gthan") { result = num1.Value > num2.Value; } else if (command.Value == "lthan") { result = num1.Value < num2.Value; } else { // equal result = num1.Value == num2.Value; } break; default: result = arg1.getValueAsString() == arg2.getValueAsString(); break; } return new Bool(result); }
private Lexicon evaluatedType(Command command) { if (inputSize() < 1) { return new Error("There must be at least 1 Command provided"); } Lexicon result = execute(nextLexicon()); return new Atom(result.Type.ToString()); }
// There's gotta be a better way to typecast this stuff private Lexicon echo(Command command) { Lexicon lex; string output = ""; while (null != (lex = nextLexicon())) { output += lex.getValueAsString() + " "; } return new ComplexAtom(output); }
private Lexicon dv(Command command) { // (9.8 * ISP) * ln ( M_full / M_empty ) return new ComplexAtom("Command currently unsupported"); // _vessel.GetDeltaV().ToString()); }
private Lexicon crewCount(Command command) { return new Number(_vessel.GetCrewCount()); }
private Lexicon blank(Command command) { // when the user presses enter, just print a newline return new Atom(""); }
private Lexicon airPressure(Command command) { return new Number(FlightGlobals.getStaticPressure(_vessel.GetWorldPos3D())); }