Exemple #1
0
        public static If produce(Queue<Token> tokens)
        {
            expect(tokens, TokenType.IF);

            Expression expression = ExpressionFactory.produce(tokens);

            expect(tokens, TokenType.DO);

            Block block = BlockFactory.produce(tokens);

            if (tokens.Count != 0 && tokens.First().tokenType == TokenType.ELSE)
            {
                tokens.Dequeue();

                Block elseBlock = null;

                if (tokens.First().tokenType == TokenType.IF)
                {
                    Token firstBlockToken = tokens.First();
                    If ifSymbol = produce(tokens);

                    List<Statement> elseBlockSymbolList = new List<Statement> {ifSymbol};

                    elseBlock = new Block(firstBlockToken, elseBlockSymbolList);
                }
                else {
                    expect(tokens, TokenType.DO);

                    elseBlock = BlockFactory.produce(tokens);
                }

                return new If(expression, block, elseBlock);
            }

            return new If(expression, block);
        } 
 bool visitLeave(Block block)
 {
     Console.WriteLine("LEAVE - Block");
     return true;
 }
 bool visitEnter(Block block)
 {
     Console.WriteLine("ENTER - Block");
     return true;
 }
Exemple #4
0
 public While(Expressions.Expression expression, Block block) : base(expression.token)
 {
     this.expression = expression;
     this.block = block;
 }
Exemple #5
0
 public If(Expressions.Expression expression, Block block, Block elseBlock) : base(expression.token)
 {
     this.expression = expression;
     this.block = block;
     this.elseBlock = elseBlock;
 }
 public bool visitLeave(Block block)
 {
     return true;
 }
 public bool visitEnter(Block block)
 {
     return true;
 }