예제 #1
0
        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);
        }
예제 #2
0
 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)),
     });
예제 #3
0
        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);
                }
            }
        }
예제 #4
0
 public virtual TResult Visit(ProductExpressionSyntax syntax)
 {
     return(DefaultResult);
 }
예제 #5
0
 public void LeaveProductExpr(ProductExpressionSyntax productExpr, WaddleContext ctx)
 {
 }