Esempio n. 1
0
 private Lexicon playerExecute(Command command)
 {
     return execute(nextLexicon());
 }
Esempio n. 2
0
 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());
 }
Esempio n. 3
0
        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);
              }
        }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
 private Lexicon mass(Command command)
 {
     return new Number(_vessel.RevealMass());
 }
Esempio n. 6
0
 private Lexicon massTotal(Command command)
 {
     return new Number(_vessel.GetTotalMass());
 }
Esempio n. 7
0
 private Lexicon getLastAns(Command command)
 {
     return _last_result;
 }
Esempio n. 8
0
        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
              }
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 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());
 }
Esempio n. 11
0
 // 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);
 }
Esempio n. 12
0
 private Lexicon dv(Command command)
 {
     // (9.8 * ISP) * ln ( M_full / M_empty )
       return new ComplexAtom("Command currently unsupported");
     //      _vessel.GetDeltaV().ToString());
 }
Esempio n. 13
0
 private Lexicon crewCount(Command command)
 {
     return new Number(_vessel.GetCrewCount());
 }
Esempio n. 14
0
 private Lexicon blank(Command command)
 {
     // when the user presses enter, just print a newline
       return new Atom("");
 }
Esempio n. 15
0
 private Lexicon airPressure(Command command)
 {
     return new Number(FlightGlobals.getStaticPressure(_vessel.GetWorldPos3D()));
 }