Esempio n. 1
0
        // <-- 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);
        }
        }                                                                  // do nothing

        bool IBoundExprVisitor <bool> .Visit(BoolExpr expr)
        {
            Write(OpCode.PushBool, expr.Value ? (byte)1 : (byte)0); return(true);
        }
 public virtual IUnboundExpr Transform(BoolExpr expr)
 {
     return(expr);
 }
Esempio n. 4
0
 IBoundExpr IUnboundExprVisitor<IBoundExpr>.Visit(BoolExpr expr)
 {
     return expr;
 }
Esempio n. 5
0
 IUnboundExpr IUnboundExprVisitor <IUnboundExpr> .Visit(BoolExpr expr)
 {
     return(Call("BoolExpr", expr));
 }