コード例 #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
ファイル: BaseSyntaxVisitor.cs プロジェクト: smackem/waddle
 public virtual TResult Visit(BoolLiteralAtom syntax)
 {
     return(DefaultResult);
 }
コード例 #4
0
 public override TypeSymbol Visit(BoolLiteralAtom syntax)
 {
     return(TypeSymbol.Bool);
 }
コード例 #5
0
 public void LeaveBoolLiteral(BoolLiteralAtom atom, WaddleContext ctx)
 {
 }
コード例 #6
0
 public bool EnterBoolLiteral(BoolLiteralAtom atom, WaddleContext ctx)
 {
     return(true);
 }