Inheritance: Statement, IForStatement
Esempio n. 1
0
		public void Visit(ForEachInStatement expression)
		{
			throw new System.NotImplementedException();
		}
Esempio n. 2
0
        public void Visit(ForEachInStatement statement)
        {
            // todo: may be declare own property in the current scope if not a globalDeclaration?
            bool globalDeclaration = true;
            string identifier = String.Empty;

            if (statement.InitialisationStatement is VariableDeclarationStatement) {
                globalDeclaration = ((VariableDeclarationStatement)statement.InitialisationStatement).Global;
                identifier = ((VariableDeclarationStatement)statement.InitialisationStatement).Identifier;
            }
            else if (statement.InitialisationStatement is Identifier) {
                globalDeclaration = true;
                identifier = ((Identifier)statement.InitialisationStatement).Text;
            }
            else {
                throw new NotSupportedException("Only variable declaration are allowed in a for in loop");
            }

            statement.Expression.Accept(this);

            var dictionary = Result as JsDictionaryObject;

            if (Result.Value is IEnumerable) {
                foreach (object value in (IEnumerable)Result.Value) {
                    CurrentScope[identifier] = Global.WrapClr(value);

                    statement.Statement.Accept(this);

                    ResetContinueIfPresent(statement.Label);

                    if (StopStatementFlow()) {
                        if (breakStatement != null && statement.Label == breakStatement.Label) {
                            breakStatement = null;
                        }

                        return;
                    }

                    ResetContinueIfPresent(statement.Label);
                }
            }
            else if (dictionary != null) {
                List<string> keys = new List<string>(dictionary.GetKeys());

                // Uses a for loop as it might be changed by the inner statements
                for (int i = 0; i < keys.Count; i++) {
                    string value = keys[i];

                    CurrentScope[identifier] = Global.StringClass.New(value);

                    statement.Statement.Accept(this);

                    ResetContinueIfPresent(statement.Label);

                    if (StopStatementFlow()) {
                        if (breakStatement != null && statement.Label == breakStatement.Label) {
                            breakStatement = null;
                        }

                        return;
                    }

                    ResetContinueIfPresent(statement.Label);
                }
            }
            else {
                throw new InvalidOperationException("The property can't be enumerated");
            }
        }
Esempio n. 3
0
    // $ANTLR start "forControlVar"
    // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1582:1: forControlVar returns [IForStatement value] : VAR first= variableDeclarationNoIn ( ( IN ex= expression ) | ( ( COMMA follow= variableDeclarationNoIn )* SEMIC (ex1= expression )? SEMIC (ex2= expression )? ) ) ;
    public ES3Parser.forControlVar_return forControlVar() // throws RecognitionException [1]
    {   
        ES3Parser.forControlVar_return retval = new ES3Parser.forControlVar_return();
        retval.Start = input.LT(1);

        object root_0 = null;

        IToken VAR132 = null;
        IToken IN133 = null;
        IToken COMMA134 = null;
        IToken SEMIC135 = null;
        IToken SEMIC136 = null;
        ES3Parser.variableDeclarationNoIn_return first = null;

        ES3Parser.expression_return ex = null;

        ES3Parser.variableDeclarationNoIn_return follow = null;

        ES3Parser.expression_return ex1 = null;

        ES3Parser.expression_return ex2 = null;


        object VAR132_tree=null;
        object IN133_tree=null;
        object COMMA134_tree=null;
        object SEMIC135_tree=null;
        object SEMIC136_tree=null;


        	var forStatement = new ForStatement();
        	var foreachStatement = new ForEachInStatement();
        	var cs = new CommaOperatorStatement();

        try 
    	{
            // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1589:2: ( VAR first= variableDeclarationNoIn ( ( IN ex= expression ) | ( ( COMMA follow= variableDeclarationNoIn )* SEMIC (ex1= expression )? SEMIC (ex2= expression )? ) ) )
            // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1589:4: VAR first= variableDeclarationNoIn ( ( IN ex= expression ) | ( ( COMMA follow= variableDeclarationNoIn )* SEMIC (ex1= expression )? SEMIC (ex2= expression )? ) )
            {
            	root_0 = (object)adaptor.GetNilNode();

            	VAR132=(IToken)Match(input,VAR,FOLLOW_VAR_in_forControlVar5819); 
            		VAR132_tree = (object)adaptor.Create(VAR132);
            		adaptor.AddChild(root_0, VAR132_tree);

            	PushFollow(FOLLOW_variableDeclarationNoIn_in_forControlVar5823);
            	first = variableDeclarationNoIn();
            	state.followingStackPointer--;

            	adaptor.AddChild(root_0, first.Tree);
            	 foreachStatement.InitialisationStatement = forStatement.InitialisationStatement = first.value; first.value.Global = false;  
            	// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1590:2: ( ( IN ex= expression ) | ( ( COMMA follow= variableDeclarationNoIn )* SEMIC (ex1= expression )? SEMIC (ex2= expression )? ) )
            	int alt69 = 2;
            	int LA69_0 = input.LA(1);

            	if ( (LA69_0 == IN) )
            	{
            	    alt69 = 1;
            	}
            	else if ( ((LA69_0 >= SEMIC && LA69_0 <= COMMA)) )
            	{
            	    alt69 = 2;
            	}
            	else 
            	{
            	    NoViableAltException nvae_d69s0 =
            	        new NoViableAltException("", 69, 0, input);

            	    throw nvae_d69s0;
            	}
            	switch (alt69) 
            	{
            	    case 1 :
            	        // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1591:3: ( IN ex= expression )
            	        {
            	        	// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1591:3: ( IN ex= expression )
            	        	// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1592:4: IN ex= expression
            	        	{
            	        		IN133=(IToken)Match(input,IN,FOLLOW_IN_in_forControlVar5837); 
            	        			IN133_tree = (object)adaptor.Create(IN133);
            	        			adaptor.AddChild(root_0, IN133_tree);

            	        		PushFollow(FOLLOW_expression_in_forControlVar5841);
            	        		ex = expression();
            	        		state.followingStackPointer--;

            	        		adaptor.AddChild(root_0, ex.Tree);
            	        		 retval.value =  foreachStatement; foreachStatement.Expression = ((ex != null) ? ex.value : null); 

            	        	}


            	        }
            	        break;
            	    case 2 :
            	        // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1596:3: ( ( COMMA follow= variableDeclarationNoIn )* SEMIC (ex1= expression )? SEMIC (ex2= expression )? )
            	        {
            	        	// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1596:3: ( ( COMMA follow= variableDeclarationNoIn )* SEMIC (ex1= expression )? SEMIC (ex2= expression )? )
            	        	// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1597:4: ( COMMA follow= variableDeclarationNoIn )* SEMIC (ex1= expression )? SEMIC (ex2= expression )?
            	        	{
            	        		// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1597:4: ( COMMA follow= variableDeclarationNoIn )*
            	        		do 
            	        		{
            	        		    int alt66 = 2;
            	        		    int LA66_0 = input.LA(1);

            	        		    if ( (LA66_0 == COMMA) )
            	        		    {
            	        		        alt66 = 1;
            	        		    }


            	        		    switch (alt66) 
            	        			{
            	        				case 1 :
            	        				    // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1597:6: COMMA follow= variableDeclarationNoIn
            	        				    {
            	        				    	COMMA134=(IToken)Match(input,COMMA,FOLLOW_COMMA_in_forControlVar5866); 
            	        				    		COMMA134_tree = (object)adaptor.Create(COMMA134);
            	        				    		adaptor.AddChild(root_0, COMMA134_tree);

            	        				    	 if( cs.Statements.Count == 0) { foreachStatement.InitialisationStatement = forStatement.InitialisationStatement = cs; cs.Statements.Add(first.value); } 
            	        				    	PushFollow(FOLLOW_variableDeclarationNoIn_in_forControlVar5872);
            	        				    	follow = variableDeclarationNoIn();
            	        				    	state.followingStackPointer--;

            	        				    	adaptor.AddChild(root_0, follow.Tree);
            	        				    	  follow.value.Global = false; cs.Statements.Add(follow.value); 

            	        				    }
            	        				    break;

            	        				default:
            	        				    goto loop66;
            	        		    }
            	        		} while (true);

            	        		loop66:
            	        			;	// Stops C# compiler whining that label 'loop66' has no statements

            	        		SEMIC135=(IToken)Match(input,SEMIC,FOLLOW_SEMIC_in_forControlVar5883); 
            	        			SEMIC135_tree = (object)adaptor.Create(SEMIC135);
            	        			adaptor.AddChild(root_0, SEMIC135_tree);

            	        		// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1598:10: (ex1= expression )?
            	        		int alt67 = 2;
            	        		int LA67_0 = input.LA(1);

            	        		if ( ((LA67_0 >= NULL && LA67_0 <= FALSE) || LA67_0 == DELETE || LA67_0 == FUNCTION || LA67_0 == NEW || LA67_0 == THIS || LA67_0 == TYPEOF || LA67_0 == VOID || LA67_0 == LBRACE || LA67_0 == LPAREN || LA67_0 == LBRACK || (LA67_0 >= ADD && LA67_0 <= SUB) || (LA67_0 >= INC && LA67_0 <= DEC) || (LA67_0 >= NOT && LA67_0 <= INV) || (LA67_0 >= Identifier && LA67_0 <= StringLiteral) || LA67_0 == RegularExpressionLiteral || (LA67_0 >= DecimalLiteral && LA67_0 <= HexIntegerLiteral)) )
            	        		{
            	        		    alt67 = 1;
            	        		}
            	        		switch (alt67) 
            	        		{
            	        		    case 1 :
            	        		        // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1598:12: ex1= expression
            	        		        {
            	        		        	PushFollow(FOLLOW_expression_in_forControlVar5889);
            	        		        	ex1 = expression();
            	        		        	state.followingStackPointer--;

            	        		        	adaptor.AddChild(root_0, ex1.Tree);
            	        		        	 forStatement.ConditionExpression = ((ex1 != null) ? ex1.value : null);

            	        		        }
            	        		        break;

            	        		}

            	        		SEMIC136=(IToken)Match(input,SEMIC,FOLLOW_SEMIC_in_forControlVar5897); 
            	        			SEMIC136_tree = (object)adaptor.Create(SEMIC136);
            	        			adaptor.AddChild(root_0, SEMIC136_tree);

            	        		// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1598:87: (ex2= expression )?
            	        		int alt68 = 2;
            	        		int LA68_0 = input.LA(1);

            	        		if ( ((LA68_0 >= NULL && LA68_0 <= FALSE) || LA68_0 == DELETE || LA68_0 == FUNCTION || LA68_0 == NEW || LA68_0 == THIS || LA68_0 == TYPEOF || LA68_0 == VOID || LA68_0 == LBRACE || LA68_0 == LPAREN || LA68_0 == LBRACK || (LA68_0 >= ADD && LA68_0 <= SUB) || (LA68_0 >= INC && LA68_0 <= DEC) || (LA68_0 >= NOT && LA68_0 <= INV) || (LA68_0 >= Identifier && LA68_0 <= StringLiteral) || LA68_0 == RegularExpressionLiteral || (LA68_0 >= DecimalLiteral && LA68_0 <= HexIntegerLiteral)) )
            	        		{
            	        		    alt68 = 1;
            	        		}
            	        		switch (alt68) 
            	        		{
            	        		    case 1 :
            	        		        // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1598:88: ex2= expression
            	        		        {
            	        		        	PushFollow(FOLLOW_expression_in_forControlVar5902);
            	        		        	ex2 = expression();
            	        		        	state.followingStackPointer--;

            	        		        	adaptor.AddChild(root_0, ex2.Tree);
            	        		        	  forStatement.IncrementExpression = ((ex2 != null) ? ex2.value : null); 

            	        		        }
            	        		        break;

            	        		}

            	        		 retval.value =  forStatement; 

            	        	}


            	        }
            	        break;

            	}


            }

            retval.Stop = input.LT(-1);

            	retval.Tree = (object)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
        }
        return retval;
    }
Esempio n. 4
0
    // $ANTLR start "forControlExpression"
    // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1604:1: forControlExpression returns [IForStatement value] : ex1= expressionNoIn ({...}? ( IN ex2= expression ) | ( SEMIC (ex2= expression )? SEMIC (ex3= expression )? ) ) ;
    public ES3Parser.forControlExpression_return forControlExpression() // throws RecognitionException [1]
    {   
        ES3Parser.forControlExpression_return retval = new ES3Parser.forControlExpression_return();
        retval.Start = input.LT(1);

        object root_0 = null;

        IToken IN137 = null;
        IToken SEMIC138 = null;
        IToken SEMIC139 = null;
        ES3Parser.expressionNoIn_return ex1 = null;

        ES3Parser.expression_return ex2 = null;

        ES3Parser.expression_return ex3 = null;


        object IN137_tree=null;
        object SEMIC138_tree=null;
        object SEMIC139_tree=null;


        	var forStatement = new ForStatement();
        	var foreachStatement = new ForEachInStatement();

        	object[] isLhs = new object[1];

        try 
    	{
            // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1612:2: (ex1= expressionNoIn ({...}? ( IN ex2= expression ) | ( SEMIC (ex2= expression )? SEMIC (ex3= expression )? ) ) )
            // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1612:4: ex1= expressionNoIn ({...}? ( IN ex2= expression ) | ( SEMIC (ex2= expression )? SEMIC (ex3= expression )? ) )
            {
            	root_0 = (object)adaptor.GetNilNode();

            	PushFollow(FOLLOW_expressionNoIn_in_forControlExpression5941);
            	ex1 = expressionNoIn();
            	state.followingStackPointer--;

            	adaptor.AddChild(root_0, ex1.Tree);
            	 foreachStatement.InitialisationStatement = forStatement.InitialisationStatement = ex1.value; 
            	// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1613:2: ({...}? ( IN ex2= expression ) | ( SEMIC (ex2= expression )? SEMIC (ex3= expression )? ) )
            	int alt72 = 2;
            	int LA72_0 = input.LA(1);

            	if ( (LA72_0 == IN) )
            	{
            	    alt72 = 1;
            	}
            	else if ( (LA72_0 == SEMIC) )
            	{
            	    alt72 = 2;
            	}
            	else 
            	{
            	    NoViableAltException nvae_d72s0 =
            	        new NoViableAltException("", 72, 0, input);

            	    throw nvae_d72s0;
            	}
            	switch (alt72) 
            	{
            	    case 1 :
            	        // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1614:3: {...}? ( IN ex2= expression )
            	        {
            	        	if ( !(( IsLeftHandSideIn(ex1.value, isLhs) )) ) 
            	        	{
            	        	    throw new FailedPredicateException(input, "forControlExpression", " IsLeftHandSideIn(ex1.value, isLhs) ");
            	        	}
            	        	// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1614:43: ( IN ex2= expression )
            	        	// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1615:4: IN ex2= expression
            	        	{
            	        		IN137=(IToken)Match(input,IN,FOLLOW_IN_in_forControlExpression5958); 
            	        			IN137_tree = (object)adaptor.Create(IN137);
            	        			adaptor.AddChild(root_0, IN137_tree);

            	        		PushFollow(FOLLOW_expression_in_forControlExpression5962);
            	        		ex2 = expression();
            	        		state.followingStackPointer--;

            	        		adaptor.AddChild(root_0, ex2.Tree);
            	        		 retval.value =  foreachStatement; foreachStatement.Expression = ex2.value; 

            	        	}


            	        }
            	        break;
            	    case 2 :
            	        // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1619:3: ( SEMIC (ex2= expression )? SEMIC (ex3= expression )? )
            	        {
            	        	// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1619:3: ( SEMIC (ex2= expression )? SEMIC (ex3= expression )? )
            	        	// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1620:4: SEMIC (ex2= expression )? SEMIC (ex3= expression )?
            	        	{
            	        		SEMIC138=(IToken)Match(input,SEMIC,FOLLOW_SEMIC_in_forControlExpression5985); 
            	        			SEMIC138_tree = (object)adaptor.Create(SEMIC138);
            	        			adaptor.AddChild(root_0, SEMIC138_tree);

            	        		// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1620:10: (ex2= expression )?
            	        		int alt70 = 2;
            	        		int LA70_0 = input.LA(1);

            	        		if ( ((LA70_0 >= NULL && LA70_0 <= FALSE) || LA70_0 == DELETE || LA70_0 == FUNCTION || LA70_0 == NEW || LA70_0 == THIS || LA70_0 == TYPEOF || LA70_0 == VOID || LA70_0 == LBRACE || LA70_0 == LPAREN || LA70_0 == LBRACK || (LA70_0 >= ADD && LA70_0 <= SUB) || (LA70_0 >= INC && LA70_0 <= DEC) || (LA70_0 >= NOT && LA70_0 <= INV) || (LA70_0 >= Identifier && LA70_0 <= StringLiteral) || LA70_0 == RegularExpressionLiteral || (LA70_0 >= DecimalLiteral && LA70_0 <= HexIntegerLiteral)) )
            	        		{
            	        		    alt70 = 1;
            	        		}
            	        		switch (alt70) 
            	        		{
            	        		    case 1 :
            	        		        // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1620:12: ex2= expression
            	        		        {
            	        		        	PushFollow(FOLLOW_expression_in_forControlExpression5991);
            	        		        	ex2 = expression();
            	        		        	state.followingStackPointer--;

            	        		        	adaptor.AddChild(root_0, ex2.Tree);
            	        		        	 forStatement.ConditionExpression = ex2.value;

            	        		        }
            	        		        break;

            	        		}

            	        		SEMIC139=(IToken)Match(input,SEMIC,FOLLOW_SEMIC_in_forControlExpression5999); 
            	        			SEMIC139_tree = (object)adaptor.Create(SEMIC139);
            	        			adaptor.AddChild(root_0, SEMIC139_tree);

            	        		// I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1620:86: (ex3= expression )?
            	        		int alt71 = 2;
            	        		int LA71_0 = input.LA(1);

            	        		if ( ((LA71_0 >= NULL && LA71_0 <= FALSE) || LA71_0 == DELETE || LA71_0 == FUNCTION || LA71_0 == NEW || LA71_0 == THIS || LA71_0 == TYPEOF || LA71_0 == VOID || LA71_0 == LBRACE || LA71_0 == LPAREN || LA71_0 == LBRACK || (LA71_0 >= ADD && LA71_0 <= SUB) || (LA71_0 >= INC && LA71_0 <= DEC) || (LA71_0 >= NOT && LA71_0 <= INV) || (LA71_0 >= Identifier && LA71_0 <= StringLiteral) || LA71_0 == RegularExpressionLiteral || (LA71_0 >= DecimalLiteral && LA71_0 <= HexIntegerLiteral)) )
            	        		{
            	        		    alt71 = 1;
            	        		}
            	        		switch (alt71) 
            	        		{
            	        		    case 1 :
            	        		        // I:\\Developpement\\Evaluant - R&D\\Jint\\trunk\\Jint\\ES3.g:1620:87: ex3= expression
            	        		        {
            	        		        	PushFollow(FOLLOW_expression_in_forControlExpression6004);
            	        		        	ex3 = expression();
            	        		        	state.followingStackPointer--;

            	        		        	adaptor.AddChild(root_0, ex3.Tree);
            	        		        	  forStatement.IncrementExpression = ex3.value; 

            	        		        }
            	        		        break;

            	        		}

            	        		 retval.value =  forStatement; 

            	        	}


            	        }
            	        break;

            	}


            }

            retval.Stop = input.LT(-1);

            	retval.Tree = (object)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
        }
        return retval;
    }
Esempio n. 5
0
 void Analyze(ForEachInStatement Stmt)
 {
     SetCurrentLineAndCharNos(Stmt);
     if (Stmt.Expression != null) Analyze(Stmt.Expression);
     if (Stmt.InitialisationStatement != null) Analyze(Stmt.InitialisationStatement);
     if (Stmt.Statement != null) Analyze(Stmt.Statement);
 }