// <-- Name
        //   | FN Name TupleType
        //   | BOOL_LITERAL
        //   | INT_LITERAL
        //   | STRING_LITERAL
        //   | LPAREN (Expression)? RPAREN
        private IUnboundExpr PrimaryExpr()
        {
            IUnboundExpr expression;

            if (CurrentIs(TokenType.Name))
            {
                var name = Consume();
                expression = new NameExpr(name.Position, name.StringValue, TypeArgs());
            }
            else if (CurrentIs(TokenType.Fn))
            {
                expression = FuncExpr();
            }
            else if (CurrentIs(TokenType.Bool))
            {
                expression = new BoolExpr(Consume(TokenType.Bool));
            }
            else if (CurrentIs(TokenType.Int))
            {
                expression = new IntExpr(Consume(TokenType.Int));
            }
            else if (CurrentIs(TokenType.String))
            {
                expression = new StringExpr(Consume(TokenType.String));
            }
            else if (CurrentIs(TokenType.LeftParen))
            {
                Token leftParen = Consume(TokenType.LeftParen);

                if (CurrentIs(TokenType.RightParen))
                {
                    // () -> unit
                    expression = new UnitExpr(leftParen.Position);
                }
                else if (CurrentIs(TokenType.Operator))
                {
                    // ( OPERATOR ) -> an operator in prefix form
                    Token op = Consume(TokenType.Operator);
                    expression = new NameExpr(op.Position, op.StringValue);
                }
                else
                {
                    // anything else is a regular parenthesized expression
                    expression = Expression();
                }

                Consume(TokenType.RightParen);
            }
            else
            {
                expression = null;
            }

            return(expression);
        }
 bool IBoundExprVisitor <bool> .Visit(IntExpr expr)
 {
     Write(OpCode.PushInt, expr.Value); return(true);
 }
 public virtual IUnboundExpr Transform(IntExpr expr)
 {
     return(expr);
 }
 IBoundExpr IUnboundExprVisitor<IBoundExpr>.Visit(IntExpr expr)
 {
     return expr;
 }
Beispiel #5
0
 IUnboundExpr IUnboundExprVisitor <IUnboundExpr> .Visit(IntExpr expr)
 {
     return(Call("IntExpr", expr));
 }