public UnaryExpression(Terminal op, Expression expression) { Operator = op; Expression = expression; AddAttribute(new OperatorAttr(op)); AddChild(expression); }
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); }
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; }
private Type GetType(Terminal terminal, bool isArray = false) { if (terminal == Terminals.Int) return isArray ? typeof(int[]) : typeof(int); return isArray ? typeof(byte[]) : typeof(byte); }
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); } }
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; }
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; }
public TypeAttr(Terminal type) { Type = type; }
public ArrayDeclaration(Terminal type, Id id, Num size) : base(type, id) { Size = size; AddAttribute(new NumAttr(size)); }
public OperatorAttr(Terminal op) { Operator = op; }