bool IBoundExprVisitor <bool> .Visit(StringExpr expr)
        {
            Write(OpCode.PushString);
            mStrings.InsertOffset(expr.Value);

            return(true);
        }
示例#2
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);
        }
 public virtual IUnboundExpr Transform(StringExpr expr)
 {
     return(expr);
 }
 IBoundExpr IUnboundExprVisitor<IBoundExpr>.Visit(StringExpr expr)
 {
     return expr;
 }
示例#5
0
 IUnboundExpr IUnboundExprVisitor <IUnboundExpr> .Visit(StringExpr expr)
 {
     return(Call("StringExpr", expr));
 }