Ejemplo n.º 1
0
 /// <summary>
 /// Parses a conditional block by first pushing symbol scope and then popping after completion.
 /// </summary>
 /// <param name="stmt"></param>
 public virtual void ParseConditionalBlock(ConditionalBlockExpr stmt)
 {
     this.Ctx.Symbols.Push(new SymbolsNested(string.Empty), true);
     stmt.SymScope = this.Ctx.Symbols.Current;
     _parser.ParseConditionalStatement(stmt);
     this.Ctx.Symbols.Pop();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Parses a conditional block by first pushing symbol scope and then popping after completion.
 /// </summary>
 /// <param name="expr"></param>
 public void ParseConditionalBlock(ConditionalBlockExpr expr)
 {
     this._parser.Context.Symbols.Push(new SymbolsNested(string.Empty), true);
     expr.SymScope = this._parser.Context.Symbols.Current;
     this._parser.ParseConditionalStatement(expr);
     this._parser.Context.Symbols.Pop();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses a conditional statement.
        /// </summary>
        /// <param name="stmt"></param>
        /// <param name="textToEndCondition"></param>
        /// <returns></returns>
        public ConditionalBlockExpr ParseConditionalStatement(ConditionalBlockExpr stmt, string textToEndCondition = "then")
        {
            if (stmt == null) stmt = new ConditionalBlockExpr(null, null);

            // Case 1: if ( <expression> )
            // Case 2: if   <expression> then
            bool hasParenthesis = _tokenIt.NextToken.Token == Tokens.LeftParenthesis;
            var terminator = hasParenthesis ? Terminators.ExpParenthesisEnd : Terminators.ExpThenEnd;

            if (hasParenthesis)
                Expect(Tokens.LeftParenthesis);

            _state.Conditional++;

            var condition = ParseExpression(terminator, true);

            if (hasParenthesis)
                Expect(Tokens.RightParenthesis);
            else if (_tokenIt.NextToken.Token == Tokens.NewLine
                || _tokenIt.NextToken.Token == Tokens.Then)
                _tokenIt.Advance();

            stmt.Condition = condition;
            stmt.Ctx = _context;
            _state.Conditional--;

            // Parse the block of statements.
            ParseBlock(stmt);
            return stmt;
        }