Example #1
0
 public Input(Expression inputPromptExpr, Block inputs, LineId line)
     : base(line)
 {
     this.inputPrompt = new Print(
         new Expression[] { inputPromptExpr, new StringLiteral("\0", line) }, line);
     this.inputs = inputs;
 }
Example #2
0
 private Assign(Location loc, string builtIn, LineId line)
     : base(line)
 {
     this.location = loc;
     this.value = null;
     this.builtIn = builtIn;
 }
Example #3
0
 public For(Assign init, Expression comparison, Assign update, Statement stmt, LineId line)
     : base(line)
 {
     this.init = init;
     this.comparison = comparison;
     this.stmt = stmt;
     this.update = update;
 }
 protected RelationalExpression(Expression e1,
     Expression e2, bool not, LineId line)
     : base(line)
 {
     this.e1 = e1;
     this.e2 = e2;
     this.not = not;
 }
Example #5
0
 public If(Expression conditional, string label, string elseLabel,
     LineId line)
     : base(line)
 {
     jmp = new Goto(label, line);
     elseJmp = new Goto(elseLabel, line);
     this.conditional = conditional;
 }
        public override void EmitStore(ILGenerator gen, IList<FieldBuilder> fields, Expression value)
        {
            gen.Emit(OpCodes.Ldarg_0);
            // Emit the code to generate the value for the given expression
            value.Emit(gen);

            // Convert booleans (which are used internally for Booleans) to doubles
            // which is how they are stored in TIBasic. Plus it needs to be negated.
            if (value.GetBasicType() == BasicType.Boolean)
            {
                gen.Emit(OpCodes.Conv_R8);
                gen.Emit(OpCodes.Neg);
            }

            gen.Emit(OpCodes.Stfld, fields[symbolIndex]);
        }
Example #7
0
 public Negative(Expression value, LineId line)
     : base(line)
 {
     this.value = value;
 }
Example #8
0
 public Equals(Expression e1, Expression e2, bool not, LineId line)
     : base(e1, e2, not, line)
 {
 }
Example #9
0
 protected BinaryOperator(Expression e1, Expression e2, LineId line)
     : base(line)
 {
     this.expr1 = e1;
     this.expr2 = e2;
 }
Example #10
0
        public override void CheckTypes()
        {
            location.ConstrainType(symbols);
            BasicType locationType = location.BasicType;
            if (locationType != BasicType.String && locationType != BasicType.Number
                && locationType != BasicType.Boolean) throw new Exception("type error");

            if (builtIn != null)
            {
                switch (builtIn)
                {
                    case readExpr:
                        value = (locationType == BasicType.String) ?
                            BuiltInsMethodCall.ReadStringFromData() : BuiltInsMethodCall.ReadNumberFromData();
                        break;
                    case inputExpr:
                        value = (locationType == BasicType.String) ?
                            BuiltInsMethodCall.ReadStringFromConsole() : BuiltInsMethodCall.ReadNumberFromConsole();
                        break;
                }
            }

            valueType = value.GetBasicType();

            if (locationType == BasicType.String && valueType == BasicType.String) return;

            if (valueType == BasicType.Number || valueType == BasicType.Boolean) return;

            throw new Exception("Type mismatch exception in an assignment");
        }
Example #11
0
 public Randomize(Expression seedExpression, LineId line)
     : base(line)
 {
     this.seedExpression = seedExpression;
     seedSpecified = true;
 }
Example #12
0
 public Power(Expression e1, Expression e2, LineId line)
     : base(e1, e2, line)
 {
 }
Example #13
0
 public Assign(Location loc, Expression value, LineId line)
     : base(line)
 {
     this.location = loc;
     this.value = value;
 }
 public static RelationalExpression CompareLessThan(
     Expression e1, Expression e2, LineId line)
 {
     return new LessThan(e1, e2, false, line);
 }
 public static RelationalExpression CompareLessThanEquals(
     Expression e1, Expression e2, LineId line)
 {
     return new GreaterThan(e1, e2, true, line);
 }
Example #16
0
 public GreaterThan(Expression expr1, Expression expr2, bool not,
     LineId line)
     : base(expr1, expr2, not, line)
 {
 }
Example #17
0
 Expression MoreStringExpr(Expression s1)
 {
     if (lookahead == Token.Concatenate)
     {
         LineId line = lexer.LineId;
         Match(Token.Concatenate);
         Expression s2 = StringExpr();
         return MoreStringExpr(new Concatenate(s1, s2, line));
     }
     else return s1;
 }
Example #18
0
 public Subtract(Expression e1, Expression e2, LineId line)
     : base(e1, e2, line)
 {
 }
Example #19
0
 public Tab(Expression expr, LineId line)
     : base(line)
 {
     this.expr = expr;
 }
Example #20
0
 public LessThan(Expression e1, Expression e2, bool not, LineId line)
     : base(e1, e2, not, line)
 {
 }
Example #21
0
 Expression MoreMultiplicationExpr(Expression m1)
 {
     LineId line = lexer.LineId;
     switch (lookahead)
     {
         case Token.Times:
         case Token.Divides:
             Token l = lookahead;
             Match(lookahead);
             Expression m2 = MultiplicationExpr();
             Expression m3=null;
             if (l == Token.Times) m3 = new Multiply(m1, m2, line);
             if (l == Token.Divides) m3 = new Division(m1, m2, line);
             return MoreMultiplicationExpr(m3);
         default:
             break;
     }
     return m1;
 }
Example #22
0
 Expression MoreAdditionExpr(Expression a1)
 {
     LineId line = lexer.LineId;
     switch (lookahead)
     {
         case Token.Plus:
         case Token.Minus:
             Token l = lookahead;
             Match(lookahead);
             Expression a2 = AdditionExpr();
             Expression a3=null;
             if (l == Token.Plus) a3 = new Add(a1, a2, line);
             if (l == Token.Minus) a3 = new Subtract(a1, a2, line);
             return MoreAdditionExpr(a3);
         default:
             break;
     }
     return a1;
 }
Example #23
0
 public OnGoto(Expression number, List<string> targets, LineId line)
     : base(line)
 {
     this.numericExpression = number;
     this.targets = targets;
 }
Example #24
0
 public abstract void EmitStore(ILGenerator gen, IList<FieldBuilder> fields, Expression value);
Example #25
0
 public Concatenate(Expression s1, Expression s2, LineId line)
     : base(line)
 {
     this.s1 = s1;
     this.s2 = s2;
 }
Example #26
0
 public Add(Expression e1, Expression e2, LineId line)
     : base(e1, e2, line)
 {
 }
Example #27
0
 Expression MoreFactors(Expression f1)
 {
     LineId line = lexer.LineId;
     if (lookahead == Token.Exponent)
     {
         Match(lookahead);
         Expression f2 = Factor();
         Expression f3 = new Power(f1, f2, line);
         return MoreFactors(f3);
     }
     return f1;
 }
Example #28
0
        Expression MoreRelationalExpr(Expression r1)
        {
            Expression r2;
            Expression r3=null;
            LineId line = lexer.LineId;

            switch (lookahead)
            {
                case Token.Equals:
                case Token.LessThan:
                case Token.GreaterThan:
                case Token.NotEquals:
                case Token.LessThanEqual:
                case Token.GreaterThanEqual:
                    Token l = lookahead;
                    Match(lookahead);
                    r2 = RelationalExpr();
                    if (l == Token.Equals) r3 = RelationalExpression.CompareEquals(r1, r2, line);
                    else if (l == Token.LessThan) r3 = RelationalExpression.CompareLessThan(r1, r2, line);
                    else if (l == Token.LessThanEqual) r3 = RelationalExpression.CompareLessThanEquals(r1, r2, line);
                    else if (l == Token.GreaterThan) r3 = RelationalExpression.CompareGreaterThan(r1, r2, line);
                    else if (l == Token.GreaterThanEqual) r3 = RelationalExpression.CompareGreaterThanEquals(r1, r2, line);
                    else if (l == Token.NotEquals) r3 = RelationalExpression.CompareNotEquals(r1, r2, line);
                    return MoreRelationalExpr(r3);
                default:
                    break;
            }
            return r1;
        }
 public static RelationalExpression CompareNotEquals(
     Expression e1, Expression e2, LineId line)
 {
     return new Equals(e1, e2, true, line);
 }
Example #30
0
 public Print(Expression[] values, LineId line)
     : base(line)
 {
     this.values = values;
     printItemTypes = new BasicType[values.Length];
 }