コード例 #1
0
ファイル: SGLTreeWalker.cs プロジェクト: peppy/sgl4cs
    // $ANTLR end "whileLoop"


    // $ANTLR start "forLoop"
    // C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\AntlrParser\\SGLTreeWalker.g:168:1: forLoop returns [SGLNode node] : ^( 'for' ^( FORDEC (dec= statement )? ) ^( FORCOND (cond= expression )? ) ^( FORITER (iter= statement )? ) block ) ;
    public SGLNode forLoop() // throws RecognitionException [1]
    {   
        SGLNode node = default(SGLNode);

        SGLNode dec = default(SGLNode);

        SGLNode cond = default(SGLNode);

        SGLNode iter = default(SGLNode);

        SGLNode block24 = default(SGLNode);



          // We have to use 2 Blocks for the for-Node to work correctly
          // Create new block for the beginning of the for-Loop
          Scope scope = new Scope(currentScope); 
          currentScope = scope;
          BlockNode bn = new BlockNode(spriteObjects, currentScope); 
          
          //Create the For-Node and add it to the block
          ForNode forNode = new ForNode();
          bn.AddStatement(forNode);
          
          // Return the block node
          node = bn;

        try 
    	{
            // C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\AntlrParser\\SGLTreeWalker.g:186:2: ( ^( 'for' ^( FORDEC (dec= statement )? ) ^( FORCOND (cond= expression )? ) ^( FORITER (iter= statement )? ) block ) )
            // C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\AntlrParser\\SGLTreeWalker.g:186:4: ^( 'for' ^( FORDEC (dec= statement )? ) ^( FORCOND (cond= expression )? ) ^( FORITER (iter= statement )? ) block )
            {
            	Match(input,61,FOLLOW_61_in_forLoop408); 

            	Match(input, Token.DOWN, null); 
            	Match(input,FORDEC,FOLLOW_FORDEC_in_forLoop411); 

            	if ( input.LA(1) == Token.DOWN )
            	{
            	    Match(input, Token.DOWN, null); 
            	    // C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\AntlrParser\\SGLTreeWalker.g:186:21: (dec= statement )?
            	    int alt3 = 2;
            	    int LA3_0 = input.LA(1);

            	    if ( ((LA3_0 >= AT && LA3_0 <= IF) || (LA3_0 >= VARDEF && LA3_0 <= ASSIGN) || LA3_0 == OBJMETHOD || (LA3_0 >= VARINC && LA3_0 <= BREAK) || (LA3_0 >= METH_CALL && LA3_0 <= RETURN) || (LA3_0 >= 60 && LA3_0 <= 61)) )
            	    {
            	        alt3 = 1;
            	    }
            	    switch (alt3) 
            	    {
            	        case 1 :
            	            // C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\AntlrParser\\SGLTreeWalker.g:186:22: dec= statement
            	            {
            	            	PushFollow(FOLLOW_statement_in_forLoop416);
            	            	dec = statement();
            	            	state.followingStackPointer--;

            	            	 forNode.SetInit(dec); 

            	            }
            	            break;

            	    }


            	    Match(input, Token.UP, null); 
            	}
            	Match(input,FORCOND,FOLLOW_FORCOND_in_forLoop425); 

            	if ( input.LA(1) == Token.DOWN )
            	{
            	    Match(input, Token.DOWN, null); 
            	    // C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\AntlrParser\\SGLTreeWalker.g:186:82: (cond= expression )?
            	    int alt4 = 2;
            	    int LA4_0 = input.LA(1);

            	    if ( (LA4_0 == NEGATE || LA4_0 == STRING || (LA4_0 >= STRINGNOQUOTES && LA4_0 <= VARDEC) || LA4_0 == METH_CALL || LA4_0 == Identifier || (LA4_0 >= IntegerAtom && LA4_0 <= Animation) || LA4_0 == 67 || (LA4_0 >= 69 && LA4_0 <= 81)) )
            	    {
            	        alt4 = 1;
            	    }
            	    switch (alt4) 
            	    {
            	        case 1 :
            	            // C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\AntlrParser\\SGLTreeWalker.g:186:83: cond= expression
            	            {
            	            	PushFollow(FOLLOW_expression_in_forLoop430);
            	            	cond = expression();
            	            	state.followingStackPointer--;

            	            	 forNode.SetCondition(cond); 

            	            }
            	            break;

            	    }


            	    Match(input, Token.UP, null); 
            	}
            	Match(input,FORITER,FOLLOW_FORITER_in_forLoop438); 

            	if ( input.LA(1) == Token.DOWN )
            	{
            	    Match(input, Token.DOWN, null); 
            	    // C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\AntlrParser\\SGLTreeWalker.g:186:150: (iter= statement )?
            	    int alt5 = 2;
            	    int LA5_0 = input.LA(1);

            	    if ( ((LA5_0 >= AT && LA5_0 <= IF) || (LA5_0 >= VARDEF && LA5_0 <= ASSIGN) || LA5_0 == OBJMETHOD || (LA5_0 >= VARINC && LA5_0 <= BREAK) || (LA5_0 >= METH_CALL && LA5_0 <= RETURN) || (LA5_0 >= 60 && LA5_0 <= 61)) )
            	    {
            	        alt5 = 1;
            	    }
            	    switch (alt5) 
            	    {
            	        case 1 :
            	            // C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\AntlrParser\\SGLTreeWalker.g:186:151: iter= statement
            	            {
            	            	PushFollow(FOLLOW_statement_in_forLoop443);
            	            	iter = statement();
            	            	state.followingStackPointer--;

            	            	 forNode.SetIteration(iter); 

            	            }
            	            break;

            	    }


            	    Match(input, Token.UP, null); 
            	}
            	PushFollow(FOLLOW_block_in_forLoop450);
            	block24 = block();
            	state.followingStackPointer--;


            	Match(input, Token.UP, null); 
            	 forNode.SetBlock(block24); 

            }

             
              currentScope = currentScope.Parent(); 

        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
        }
        finally 
    	{
        }
        return node;
    }
コード例 #2
0
ファイル: SGLTreeWalker.cs プロジェクト: brianex/osu-sgl
    // $ANTLR end "ifStatement"


    // $ANTLR start "forLoop"
    // D:\\sgl4c#\\NewSGLGramma\\SGLTreeWalker.g:205:1: forLoop returns [SGLNode node] : ^( 'for' ^( FORDEC (dec= statement )? ) ^( FORCOND (cond= expression )? ) ^( FORITER (iter= statement )? ) block ) ;
    public SGLNode forLoop() // throws RecognitionException [1]
    {   
        SGLNode node = default(SGLNode);

        SGLNode dec = default(SGLNode);

        SGLNode cond = default(SGLNode);

        SGLNode iter = default(SGLNode);

        SGLNode block25 = default(SGLNode);



          // We have to use 2 Blocks for the for-Node to work correctly
          // Create new block for the beginning of the for-Loop
          Scope scope = new Scope(currentScope); 
          currentScope = scope;
          BlockNode bn = new BlockNode(spriteObjects, currentScope); 
          
          //Create the For-Node and add it to the block
          ForNode forNode = new ForNode();
          bn.AddStatement(forNode);
          
          // Return the block node
          node = bn;

        try 
    	{
            // D:\\sgl4c#\\NewSGLGramma\\SGLTreeWalker.g:223:2: ( ^( 'for' ^( FORDEC (dec= statement )? ) ^( FORCOND (cond= expression )? ) ^( FORITER (iter= statement )? ) block ) )
            // D:\\sgl4c#\\NewSGLGramma\\SGLTreeWalker.g:223:4: ^( 'for' ^( FORDEC (dec= statement )? ) ^( FORCOND (cond= expression )? ) ^( FORITER (iter= statement )? ) block )
            {
            	Match(input,86,FOLLOW_86_in_forLoop510); 

            	Match(input, Token.DOWN, null); 
            	Match(input,FORDEC,FOLLOW_FORDEC_in_forLoop513); 

            	if ( input.LA(1) == Token.DOWN )
            	{
            	    Match(input, Token.DOWN, null); 
            	    // D:\\sgl4c#\\NewSGLGramma\\SGLTreeWalker.g:223:21: (dec= statement )?
            	    int alt9 = 2;
            	    int LA9_0 = input.LA(1);

            	    if ( (LA9_0 == ASSIGN || (LA9_0 >= VARINC && LA9_0 <= VARDEC) || (LA9_0 >= METH_CALL && LA9_0 <= IF) || LA9_0 == GLOBAL_ASSIGN || (LA9_0 >= 85 && LA9_0 <= 86)) )
            	    {
            	        alt9 = 1;
            	    }
            	    switch (alt9) 
            	    {
            	        case 1 :
            	            // D:\\sgl4c#\\NewSGLGramma\\SGLTreeWalker.g:223:22: dec= statement
            	            {
            	            	PushFollow(FOLLOW_statement_in_forLoop518);
            	            	dec = statement();
            	            	state.followingStackPointer--;

            	            	 forNode.SetInit(dec); 

            	            }
            	            break;

            	    }


            	    Match(input, Token.UP, null); 
            	}
            	Match(input,FORCOND,FOLLOW_FORCOND_in_forLoop527); 

            	if ( input.LA(1) == Token.DOWN )
            	{
            	    Match(input, Token.DOWN, null); 
            	    // D:\\sgl4c#\\NewSGLGramma\\SGLTreeWalker.g:223:82: (cond= expression )?
            	    int alt10 = 2;
            	    int LA10_0 = input.LA(1);

            	    if ( ((LA10_0 >= STRING && LA10_0 <= VARDEC) || LA10_0 == LOOKUP || (LA10_0 >= IntAtom && LA10_0 <= LoopTypeAtom) || (LA10_0 >= Null && LA10_0 <= List) || LA10_0 == 63 || (LA10_0 >= 65 && LA10_0 <= 78)) )
            	    {
            	        alt10 = 1;
            	    }
            	    switch (alt10) 
            	    {
            	        case 1 :
            	            // D:\\sgl4c#\\NewSGLGramma\\SGLTreeWalker.g:223:83: cond= expression
            	            {
            	            	PushFollow(FOLLOW_expression_in_forLoop532);
            	            	cond = expression();
            	            	state.followingStackPointer--;

            	            	 forNode.SetCondition(cond); 

            	            }
            	            break;

            	    }


            	    Match(input, Token.UP, null); 
            	}
            	Match(input,FORITER,FOLLOW_FORITER_in_forLoop540); 

            	if ( input.LA(1) == Token.DOWN )
            	{
            	    Match(input, Token.DOWN, null); 
            	    // D:\\sgl4c#\\NewSGLGramma\\SGLTreeWalker.g:223:150: (iter= statement )?
            	    int alt11 = 2;
            	    int LA11_0 = input.LA(1);

            	    if ( (LA11_0 == ASSIGN || (LA11_0 >= VARINC && LA11_0 <= VARDEC) || (LA11_0 >= METH_CALL && LA11_0 <= IF) || LA11_0 == GLOBAL_ASSIGN || (LA11_0 >= 85 && LA11_0 <= 86)) )
            	    {
            	        alt11 = 1;
            	    }
            	    switch (alt11) 
            	    {
            	        case 1 :
            	            // D:\\sgl4c#\\NewSGLGramma\\SGLTreeWalker.g:223:151: iter= statement
            	            {
            	            	PushFollow(FOLLOW_statement_in_forLoop545);
            	            	iter = statement();
            	            	state.followingStackPointer--;

            	            	 forNode.SetIteration(iter); 

            	            }
            	            break;

            	    }


            	    Match(input, Token.UP, null); 
            	}
            	PushFollow(FOLLOW_block_in_forLoop552);
            	block25 = block();
            	state.followingStackPointer--;


            	Match(input, Token.UP, null); 
            	 forNode.SetBlock(block25); 

            }

             
              currentScope = currentScope.Parent(); 

        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
        }
        finally 
    	{
        }
        return node;
    }