public bool EnterProductExpr(ProductExpressionSyntax productExpr, WaddleContext ctx) { if (productExpr.Left.Accept(TypeVisitor) != TypeSymbol.Integer) { throw new SemanticErrorException($"Not an Integer @({productExpr.Left.StartToken.LineNumber}{productExpr.Left.StartToken.CharPosition})."); } if (productExpr.Right.Accept(TypeVisitor) != TypeSymbol.Integer) { throw new SemanticErrorException($"Not an Integer @({productExpr.Right.StartToken.LineNumber}{productExpr.Right.StartToken.CharPosition})."); } return(true); }
private TypeSymbol WaddleExpression(ExpressionSyntax exprStmt) { return(exprStmt switch { LogicalExpressionSyntax logicalExpr => WaddleLogicalExpr(logicalExpr), ProductExpressionSyntax productExpr => WaddleProductExpr(productExpr), RelationalExpressionSyntax relationalExpr => WaddleRelationalExpr(relationalExpr), TermExpressionSyntax termExpr => WaddleTermExpr(termExpr), InvocationExpressionSyntax invocationExpr => WaddleInvocationExpr(invocationExpr), BoolLiteralAtom _ => TypeSymbol.Bool, IntegerLiteralAtom _ => TypeSymbol.Integer, StringLiteralAtom _ => TypeSymbol.String, IdentifierAtom identifierAtom => _currentFunction?.Variables[identifierAtom.Identifier].Type ?? throw new SemanticErrorException($"{identifierAtom.Identifier} does not have a type"), _ => throw new ArgumentOutOfRangeException(nameof(exprStmt)), });
private ExpressionSyntax ParseProductExpression() { var startToken = CurrentToken; ExpressionSyntax left = ParseAtom(); while (true) { switch (CurrentToken.Type) { case TokenType.Multiply: Next(); left = new ProductExpressionSyntax(startToken, left, ParseAtom(), ProductOperator.Times); break; case TokenType.Divide: Next(); left = new ProductExpressionSyntax(startToken, left, ParseAtom(), ProductOperator.Divide); break; default: return(left); } } }
public virtual TResult Visit(ProductExpressionSyntax syntax) { return(DefaultResult); }
public void LeaveProductExpr(ProductExpressionSyntax productExpr, WaddleContext ctx) { }