Esempio n. 1
0
        public bool EnterIdentifierLiteral(IdentifierAtom atom, WaddleContext ctx)
        {
            var _ = _currentFunction?.Variables[atom.Identifier].Type
                    ?? throw new SemanticErrorException($"{atom.Identifier} does not have a type");

            return(true);
        }
Esempio n. 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)),
     });
Esempio n. 3
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}");
            }
        }
Esempio n. 4
0
 public virtual TResult Visit(IdentifierAtom syntax)
 {
     return(DefaultResult);
 }
Esempio n. 5
0
 public override TypeSymbol Visit(IdentifierAtom syntax)
 {
     return(_symbols[syntax.Identifier].Type !);
 }
Esempio n. 6
0
 public void LeaveIdentifierLiteral(IdentifierAtom atom, WaddleContext ctx)
 {
 }