public object VisitExpression3(Expression3 expression3, object o) { if (expression3.Operator3 == null) { expression3.Primary.Visit(this); return(null); } expression3.Primary.Visit(this); expression3.Expression1.Visit(this); int operatorAsDisplacement; switch (expression3.Operator3.Spelling) { case "*": operatorAsDisplacement = Machine.multDisplacement; break; case "/": operatorAsDisplacement = Machine.divDisplacement; break; case "and": operatorAsDisplacement = Machine.andDisplacement; break; default: throw new ArgumentException("Invalid operator"); } Emit(Machine.CALLop, Machine.CB, Machine.PBr, operatorAsDisplacement); _stackManager.DecrementOffset(); return(null); }
public object VisitExpression3(Expression3 expression3, object o) { if (expression3.Operator3 == null) { return(expression3.Primary.Visit(this, o)); } var lv3IntyOpr = new List <string>() { "*", "/" }; var t1 = (VariableType.ValueTypeEnum)expression3.Expression1.Visit(this, o); var t2 = (VariableType.ValueTypeEnum)expression3.Primary.Visit(this, o); if (t1 == VariableType.ValueTypeEnum.NOTHING || t2 == VariableType.ValueTypeEnum.NOTHING) { throw new Exception("<Nothing> not a valid operand for " + expression3.Operator3.Spelling + " operator"); } if (t1 != t2) { throw new Exception("The operands for a Operator3 operator must be of same type"); } if (lv3IntyOpr.Contains(expression3.Operator3.Spelling)) { if (t1 == VariableType.ValueTypeEnum.INTY) { return(VariableType.ValueTypeEnum.INTY); } else { throw new Exception("Operator " + expression3.Operator3.Spelling + " expexted inty operands"); } } else if ("and".Equals(expression3.Operator3.Spelling)) { if (t1 == VariableType.ValueTypeEnum.BOOLY) { return(VariableType.ValueTypeEnum.BOOLY); } else { throw new Exception("Operator " + expression3.Operator3.Spelling + " expected booly operands"); } } throw new Exception("Something bad happened, code: 32546863135"); }
private Expression2 ParseExpression2() { Expression3 expression3 = ParseExpression3(); Operator2 operator2 = null; Expression1 expression1 = null; if (Token.TokenType.OPERATOR_2 == _currentToken.TheTokenType) { operator2 = new Operator2(Accept(Token.TokenType.OPERATOR_2)); expression1 = ParseExpression1(); } return(new Expression2(expression3, operator2, expression1)); }
public Expression2(Expression3 expression3, Operator2 operator2, Expression1 expression1) { Expression3 = expression3; Operator2 = operator2; Expression1 = expression1; }