Ejemplo n.º 1
0
        // "for" "(" <exp-option> ";" <exp-option> ";" <exp-option> ")" <statement>
        public For Parse(Stack <Token> tokens)
        {
            tokens.Pop();
            var token = tokens.Pop();

            if (token.Name != TokenLibrary.Words.OpenParenthesis)
            {
                throw new SyntaxException("expected (");
            }

            var nextToken = tokens.Peek();

            // if the next token is a variable type
            if (nextToken.Name == TokenLibrary.Words.Int)
            {
                return(new ForDeclare(Scope).Parse(tokens));
            }


            Initialise = new OptionalSemicolon(Scope).Parse(tokens);

            Condition = new OptionalSemicolon(Scope).Parse(tokens);

            // ensuring non zero expression
            if (Condition.GetType() == typeof(OptionalSemicolon))
            {
                Condition = new Constant(Scope, 1);
            }

            PostExpression = new OptionalCloseParam(Scope).Parse(tokens);

            Statement = new Statement(new Scope(Scope)).Parse(tokens);

            return(this);
        }
Ejemplo n.º 2
0
        public ForDeclare Parse(Stack<Token> tokens)
        {
            Initialise = new Declare(Scope).Parse(tokens);

            Condition = new OptionalSemicolon(Scope).Parse(tokens);

            PostExpression = new OptionalCloseParam(Scope).Parse(tokens);

            Statement = new Statement(Scope).Parse(tokens);

            return this;
        }