示例#1
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)),
     });
示例#2
0
        private AtomSyntax ParseAtom()
        {
            switch (CurrentToken.Type)
            {
            case TokenType.Arrow:
            {
                Next();
                return(ParseInvocationExpression());
            }

            case TokenType.Number:
            {
                var literal = new IntegerLiteralAtom(CurrentToken, int.Parse(CurrentToken.Lexeme));
                Next();
                return(literal);
            }

            case TokenType.False or TokenType.True:
            {
                var literal = new BoolLiteralAtom(CurrentToken, bool.Parse(CurrentToken.Lexeme));
                Next();
                return(literal);
            }

            case TokenType.String:
            {
                var literal = new StringLiteralAtom(CurrentToken, CurrentToken.Lexeme);
                Next();
                return(literal);
            }

            case TokenType.Identifier:
            {
                var ident = new IdentifierAtom(CurrentToken, CurrentToken.Lexeme);
                Next();
                return(ident);
            }

            default:
                throw new Exception($"syntax error @({CurrentToken.LineNumber}:{CurrentToken.CharPosition}) - atom expected - found {CurrentToken.Type}");
            }
        }
示例#3
0
 public virtual TResult Visit(StringLiteralAtom syntax)
 {
     return(DefaultResult);
 }
示例#4
0
 public override TypeSymbol Visit(StringLiteralAtom syntax)
 {
     return(TypeSymbol.String);
 }
示例#5
0
 public void LeaveStringLiteral(StringLiteralAtom atom, WaddleContext ctx)
 {
 }
示例#6
0
 public bool EnterStringLiteral(StringLiteralAtom atom, WaddleContext ctx)
 {
     return(true);
 }