예제 #1
0
        public Statement Parse(LoonyParser parser, LoonyToken token, out bool trailingSemicolon)
        {
            trailingSemicolon = true;

            var        name        = parser.Take(LoonyTokenType.Identifier).Contents;
            TypeBase   type        = null;
            Expression initializer = null;

            if (parser.MatchAndTake(LoonyTokenType.Colon))
            {
                type = parser.ParseType();
            }

            if (type == null)
            {
                parser.Take(LoonyTokenType.Assign);
                initializer = parser.ParseExpression();
            }
            else if (parser.MatchAndTake(LoonyTokenType.Assign))
            {
                initializer = parser.ParseExpression();
            }

            return(new VariableStatement(token, parser.Previous, name, type, initializer));
        }
예제 #2
0
        public Statement Parse(LoonyParser parser, LoonyToken token, out bool trailingSemicolon)
        {
            trailingSemicolon = true;

            var value = parser.ParseExpression();
            return new ReturnStatement(token, parser.Previous, value);
        }
예제 #3
0
        public Expression Parse(LoonyParser parser, LoonyToken token)
        {
            var expression = parser.ParseExpression();

            parser.Take(LoonyTokenType.RightParen);
            return(expression);
        }
예제 #4
0
        public Statement Parse(LoonyParser parser, LoonyToken token, out bool trailingSemicolon)
        {
            trailingSemicolon = true;

            var value = parser.ParseExpression();

            return(new ReturnStatement(token, parser.Previous, value));
        }
예제 #5
0
        public Statement Parse(LoonyParser parser, LoonyToken token, out bool trailingSemicolon)
        {
            trailingSemicolon = true;

            var name = parser.Take(LoonyTokenType.Identifier).Contents;
            TypeBase type = null;
            Expression initializer = null;

            if (parser.MatchAndTake(LoonyTokenType.Colon))
                type = parser.ParseType();

            if (type == null)
            {
                parser.Take(LoonyTokenType.Assign);
                initializer = parser.ParseExpression();
            }
            else if (parser.MatchAndTake(LoonyTokenType.Assign))
            {
                initializer = parser.ParseExpression();
            }

            return new VariableStatement(token, parser.Previous, name, type, initializer);
        }
예제 #6
0
 public Expression Parse(LoonyParser parser, Expression left, LoonyToken token)
 {
     var right = parser.ParseExpression(Precedence - (_isRight ? 1 : 0));
     return new BinaryOperatorExpression(token, left, right);
 }
예제 #7
0
 public Expression Parse(LoonyParser parser, LoonyToken token)
 {
     var expression = parser.ParseExpression();
     parser.Take(LoonyTokenType.RightParen);
     return expression;
 }
예제 #8
0
        public Expression Parse(LoonyParser parser, Expression left, LoonyToken token)
        {
            var right = parser.ParseExpression(Precedence - (_isRight ? 1 : 0));

            return(new BinaryOperatorExpression(token, left, right));
        }