示例#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);
        } 
示例#2
0
 bool visitLeave(Block block)
 {
     Console.WriteLine("LEAVE - Block");
     return true;
 }
示例#3
0
 bool visitEnter(Block block)
 {
     Console.WriteLine("ENTER - Block");
     return true;
 }
示例#4
0
 public While(Expressions.Expression expression, Block block) : base(expression.token)
 {
     this.expression = expression;
     this.block = block;
 }
示例#5
0
 public If(Expressions.Expression expression, Block block, Block elseBlock) : base(expression.token)
 {
     this.expression = expression;
     this.block = block;
     this.elseBlock = elseBlock;
 }
示例#6
0
 public bool visitLeave(Block block)
 {
     return true;
 }
示例#7
0
 public bool visitEnter(Block block)
 {
     return true;
 }