To whom it may concern,

I get this warning when compiling the Java runtime.

.\TestRecursion_JavaParser.java:64: warning: [unchecked] unchecked call to
push(E) as a member of the raw type java.util.Stack
        block_stack.push(new block_scope());
I attach the source code and the grammar which produced it.

The "Java" in the name refers to the runtime language in this case.

Am I doing something wrong? If not, I wonder if the warning could possibly
be removed in future?

For our information, I also have a C runtime version. This version does not
seem to work in quite the same way as the Java version in that the block
data appears to be popped before performing any @after processing (instead
of after any @after processing as in the Java runtime) so that any
appropriate block data is no longer available..

Thanks,

David.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

// Found on page 139/140 of Antlr Book, renamed and amended
grammar TestRecursion_Java;     // Java only
//grammar TestRecursion_C;      // C only

options
        {
        language = Java;        // Java only
        //language = C; // C only
        }

@members 
        {
        int level=0;
        }

prog:   block
    ;
    
block
scope 
        {
    int myLevel;
        }
@init 
        {
        level++;
        }
@after 
        {
    System.out.println("Printed from [EMAIL PROTECTED], myLevel = " + 
$block::myLevel); // Java only
    //printf("Printed from [EMAIL PROTECTED], myLevel = 
\%d\n",$block::myLevel);        // C only
    level--;
        }
    :   '{' decl* statement+ '}'
    ;
    
decl:   'int' ID        {$block::myLevel = level;} ';'
                                    {System.out.println("Printed from decl, 
myLevel = " + $block::myLevel);}    // Java only
                                    //{printf("Printed from decl, myLevel = 
\%d\n",$block::myLevel);}   // C only
    ;
    
statement
        :   ID '=' INT ';'
        {
            System.out.println("Printed from Statement, myLevel = " + 
$block::myLevel); // Java only
                //printf("Printed from Statement, myLevel = 
\%d\n",$block::myLevel);    // C only
        }
    |   block
    ;

ID  :   'a'..'z'+ 
        ;

INT :   '0'..'9'+ 
        ;

WS  :   (' '|'\n'|'\r')+ {$channel = HIDDEN;} 
        ;

// $ANTLR 3.0.1 TestRecursion\\TestRecursion_Java.g 2008-09-30 11:03:59

import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

public class TestRecursion_JavaParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "ID", "INT", "WS", "'{'", 
"'}'", "'int'", "';'", "'='"
    };
    public static final int WS=6;
    public static final int INT=5;
    public static final int ID=4;
    public static final int EOF=-1;

        public TestRecursion_JavaParser(TokenStream input) {
            super(input);
        }
        

    public String[] getTokenNames() { return tokenNames; }
    public String getGrammarFileName() { return 
"TestRecursion\\TestRecursion_Java.g"; }


        int level=0;
        


    // $ANTLR start prog
    // TestRecursion\\TestRecursion_Java.g:16:1: prog : block ;
    public final void prog() throws RecognitionException {
        try {
            // TestRecursion\\TestRecursion_Java.g:16:5: ( block )
            // TestRecursion\\TestRecursion_Java.g:16:9: block
            {
            pushFollow(FOLLOW_block_in_prog39);
            block();
            _fsp--;


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end prog

    protected static class block_scope {
        int myLevel;
    }
    protected Stack block_stack = new Stack();


    // $ANTLR start block
    // TestRecursion\\TestRecursion_Java.g:19:1: block : '{' ( decl )* ( 
statement )+ '}' ;
    public final void block() throws RecognitionException {
        block_stack.push(new block_scope());

                level++;
                
        try {
            // TestRecursion\\TestRecursion_Java.g:34:5: ( '{' ( decl )* ( 
statement )+ '}' )
            // TestRecursion\\TestRecursion_Java.g:34:9: '{' ( decl )* ( 
statement )+ '}'
            {
            match(input,7,FOLLOW_7_in_block82); 
            // TestRecursion\\TestRecursion_Java.g:34:13: ( decl )*
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==9) ) {
                    alt1=1;
                }


                switch (alt1) {
                case 1 :
                    // TestRecursion\\TestRecursion_Java.g:34:13: decl
                    {
                    pushFollow(FOLLOW_decl_in_block84);
                    decl();
                    _fsp--;


                    }
                    break;

                default :
                    break loop1;
                }
            } while (true);

            // TestRecursion\\TestRecursion_Java.g:34:19: ( statement )+
            int cnt2=0;
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==ID||LA2_0==7) ) {
                    alt2=1;
                }


                switch (alt2) {
                case 1 :
                    // TestRecursion\\TestRecursion_Java.g:34:19: statement
                    {
                    pushFollow(FOLLOW_statement_in_block87);
                    statement();
                    _fsp--;


                    }
                    break;

                default :
                    if ( cnt2 >= 1 ) break loop2;
                        EarlyExitException eee =
                            new EarlyExitException(2, input);
                        throw eee;
                }
                cnt2++;
            } while (true);

            match(input,8,FOLLOW_8_in_block90); 

            }


                System.out.println("Printed from [EMAIL PROTECTED], myLevel = " 
+ ((block_scope)block_stack.peek()).myLevel); // Java only
                //printf("Printed from [EMAIL PROTECTED], myLevel = 
%d\n",((block_scope)block_stack.peek()).myLevel);   // C only
                level--;
                
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
            block_stack.pop();
        }
        return ;
    }
    // $ANTLR end block


    // $ANTLR start decl
    // TestRecursion\\TestRecursion_Java.g:37:1: decl : 'int' ID ';' ;
    public final void decl() throws RecognitionException {
        try {
            // TestRecursion\\TestRecursion_Java.g:37:5: ( 'int' ID ';' )
            // TestRecursion\\TestRecursion_Java.g:37:9: 'int' ID ';'
            {
            match(input,9,FOLLOW_9_in_decl108); 
            match(input,ID,FOLLOW_ID_in_decl110); 
            ((block_scope)block_stack.peek()).myLevel = level;
            match(input,10,FOLLOW_10_in_decl114); 
            System.out.println("Printed from decl, myLevel = " + 
((block_scope)block_stack.peek()).myLevel);

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end decl


    // $ANTLR start statement
    // TestRecursion\\TestRecursion_Java.g:42:1: statement : ( ID '=' INT ';' | 
block );
    public final void statement() throws RecognitionException {
        try {
            // TestRecursion\\TestRecursion_Java.g:43:2: ( ID '=' INT ';' | 
block )
            int alt3=2;
            int LA3_0 = input.LA(1);

            if ( (LA3_0==ID) ) {
                alt3=1;
            }
            else if ( (LA3_0==7) ) {
                alt3=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("42:1: statement : ( ID '=' INT 
';' | block );", 3, 0, input);

                throw nvae;
            }
            switch (alt3) {
                case 1 :
                    // TestRecursion\\TestRecursion_Java.g:43:6: ID '=' INT ';'
                    {
                    match(input,ID,FOLLOW_ID_in_statement154); 
                    match(input,11,FOLLOW_11_in_statement156); 
                    match(input,INT,FOLLOW_INT_in_statement158); 
                    match(input,10,FOLLOW_10_in_statement160); 

                            System.out.println("Printed from Statement, myLevel 
= " + ((block_scope)block_stack.peek()).myLevel); // Java only
                                //printf("Printed from Statement, myLevel = 
%d\n",((block_scope)block_stack.peek()).myLevel);   // C only
                            

                    }
                    break;
                case 2 :
                    // TestRecursion\\TestRecursion_Java.g:48:9: block
                    {
                    pushFollow(FOLLOW_block_in_statement180);
                    block();
                    _fsp--;


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end statement


 

    public static final BitSet FOLLOW_block_in_prog39 = new BitSet(new 
long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_7_in_block82 = new BitSet(new 
long[]{0x0000000000000290L});
    public static final BitSet FOLLOW_decl_in_block84 = new BitSet(new 
long[]{0x0000000000000290L});
    public static final BitSet FOLLOW_statement_in_block87 = new BitSet(new 
long[]{0x0000000000000190L});
    public static final BitSet FOLLOW_8_in_block90 = new BitSet(new 
long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_9_in_decl108 = new BitSet(new 
long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ID_in_decl110 = new BitSet(new 
long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_10_in_decl114 = new BitSet(new 
long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_statement154 = new BitSet(new 
long[]{0x0000000000000800L});
    public static final BitSet FOLLOW_11_in_statement156 = new BitSet(new 
long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_INT_in_statement158 = new BitSet(new 
long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_10_in_statement160 = new BitSet(new 
long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_block_in_statement180 = new BitSet(new 
long[]{0x0000000000000002L});

}
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address

Reply via email to