Exemple #1
0
 public UnaryExpression(Terminal op, Expression expression)
 {
     Operator = op;
     Expression = expression;
     AddAttribute(new OperatorAttr(op));
     AddChild(expression);
 }
Exemple #2
0
 public VarDeclaration(Terminal type, Id id)
 {
     Type = type;
     Id = id;
     AddAttribute(new TypeAttr(type));
     AddAttribute(new IdAttr(id));
 }
 public BinaryExpression(Expression expression1, Terminal op, Expression expression2)
 {
     Operator = op;
     LeftOperand = expression1;
     RightOperand = expression2;
     AddAttribute(new OperatorAttr(op));
     AddChild(expression1);
     AddChild(expression2);
 }
Exemple #4
0
        public FuncDeclaration(Terminal returnType, Id name, ParamDeclaration[] parameters, Block body)
        {
            ReturnType = returnType;
            Params = parameters;
            Body = body;
            Name = name;

            AddAttribute(new TypeAttr(returnType));
            AddAttribute(new IdAttr(name));
            AddAttribute(parameters);
            AddChild(body);
        }
 public ParamDeclaration(Terminal type, Id id, bool isArray)
 {
     Type = type;
     Id = id;
     IsArray = isArray;
 }
Exemple #6
0
 private Type GetType(Terminal terminal, bool isArray = false)
 {
     if (terminal == Terminals.Int)
         return isArray ? typeof(int[]) : typeof(int);
     return isArray ? typeof(byte[]) : typeof(byte);
 }
Exemple #7
0
 private void CodeMathOp(Terminal op, ILGenerator il)
 {
     if (op == Terminals.Minus)
     {
         il.Emit(OpCodes.Sub);
     }
     else if (op == Terminals.Plus)
     {
         il.Emit(OpCodes.Add);
     }
     else if (op == Terminals.Mul)
     {
         il.Emit(OpCodes.Mul);
     }
     else if (op == Terminals.Div)
     {
         il.Emit(OpCodes.Div);
     }
 }
Exemple #8
0
 private bool CodeLogicOp(Terminal op, ILGenerator il)
 {
     if (op == Terminals.And)
     {
         var ret = il.DefineLabel();
         il.Emit(OpCodes.Brtrue_S, ret);
         il.Emit(OpCodes.Pop);
         il.Emit(OpCodes.Ldc_I4_0);
         il.MarkLabel(ret);
         return true;
     }
     if (op == Terminals.Or)
     {
         var ret2 = il.DefineLabel();
         il.Emit(OpCodes.Brfalse_S, ret2);
         il.Emit(OpCodes.Pop);
         il.Emit(OpCodes.Ldc_I4_1);
         il.MarkLabel(ret2);
         return true;
     }
     if (op == Terminals.Equal)
     {
         il.Emit(OpCodes.Ceq);
         return true;
     }
     if (op == Terminals.NotEqual)
     {
         il.Emit(OpCodes.Ceq);
         il.Emit(OpCodes.Ldc_I4_0);
         il.Emit(OpCodes.Ceq);
     }
     return false;
 }
Exemple #9
0
 private bool CodeLessOp(Terminal op, ILGenerator il)
 {
     if (op == Terminals.Less)
     {
         il.Emit(OpCodes.Clt);
         return true;
     }
     if (op == Terminals.LessOrEqual)
     {
         il.Emit(OpCodes.Cgt);
         il.Emit(OpCodes.Ldc_I4_0);
         il.Emit(OpCodes.Ceq);
         return true;
     }
     return false;
 }
Exemple #10
0
 public TypeAttr(Terminal type)
 {
     Type = type;
 }
Exemple #11
0
 public ArrayDeclaration(Terminal type, Id id, Num size)
     : base(type, id)
 {
     Size = size;
     AddAttribute(new NumAttr(size));
 }
Exemple #12
0
 public OperatorAttr(Terminal op)
 {
     Operator = op;
 }