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 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}"); } }
public virtual TResult Visit(StringLiteralAtom syntax) { return(DefaultResult); }
public override TypeSymbol Visit(StringLiteralAtom syntax) { return(TypeSymbol.String); }
public void LeaveStringLiteral(StringLiteralAtom atom, WaddleContext ctx) { }
public bool EnterStringLiteral(StringLiteralAtom atom, WaddleContext ctx) { return(true); }