[antlr-interest] Creating AST with third party grammar

tahiti rus-reg at yandex.ru
Tue Feb 9 10:17:40 PST 2010


No, I confused right for lack of return type of this methods. The method
query() that parse entire query has return type boid. It is only modify the
state of the parser class state._fsp located in base class of Parser:
RecognizerSharedState. I suppose that after calling this method I must to
use standart feature of ANTLR for generating AST tree from this state.

This is a code of query() method that mutch query:

public final void query() throws RecognitionException {
        try {
            // C:\\Documents and
Settings\\rushan\\data\\workspace\\devel\\ANTLR\\sparkle-g-2.0\\src\\com\\sparkleg\\Sparql.g:36:5:
( prologue ( selectQuery | constructQuery | describeQuery | askQuery ) EOF )
            // C:\\Documents and
Settings\\rushan\\data\\workspace\\devel\\ANTLR\\sparkle-g-2.0\\src\\com\\sparkleg\\Sparql.g:36:7:
prologue ( selectQuery | constructQuery | describeQuery | askQuery ) EOF
            {
            pushFollow(FOLLOW_prologue_in_query36);
            prologue();

            state._fsp--;

            // C:\\Documents and
Settings\\rushan\\data\\workspace\\devel\\ANTLR\\sparkle-g-2.0\\src\\com\\sparkleg\\Sparql.g:36:16:
( selectQuery | constructQuery | describeQuery | askQuery )
            int alt1=4;
            switch ( input.LA(1) ) {
            case SELECT:
                {
                alt1=1;
                }
                break;
            case CONSTRUCT:
                {
                alt1=2;
                }
                break;
            case DESCRIBE:
                {
                alt1=3;
                }
                break;
            case ASK:
                {
                alt1=4;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 1, 0, input);

                throw nvae;
            }

            switch (alt1) {
                case 1 :
                    // C:\\Documents and
Settings\\rushan\\data\\workspace\\devel\\ANTLR\\sparkle-g-2.0\\src\\com\\sparkleg\\Sparql.g:36:18:
selectQuery
                    {
                    pushFollow(FOLLOW_selectQuery_in_query40);
                    selectQuery();

                    state._fsp--;


                    }
                    break;
                case 2 :
                    // C:\\Documents and
Settings\\rushan\\data\\workspace\\devel\\ANTLR\\sparkle-g-2.0\\src\\com\\sparkleg\\Sparql.g:36:32:
constructQuery
                    {
                    pushFollow(FOLLOW_constructQuery_in_query44);
                    constructQuery();

                    state._fsp--;


                    }
                    break;
                case 3 :
                    // C:\\Documents and
Settings\\rushan\\data\\workspace\\devel\\ANTLR\\sparkle-g-2.0\\src\\com\\sparkleg\\Sparql.g:36:49:
describeQuery
                    {
                    pushFollow(FOLLOW_describeQuery_in_query48);
                    describeQuery();

                    state._fsp--;


                    }
                    break;
                case 4 :
                    // C:\\Documents and
Settings\\rushan\\data\\workspace\\devel\\ANTLR\\sparkle-g-2.0\\src\\com\\sparkleg\\Sparql.g:36:65:
askQuery
                    {
                    pushFollow(FOLLOW_askQuery_in_query52);
                    askQuery();

                    state._fsp--;


                    }
                    break;

            }

            match(input,EOF,FOLLOW_EOF_in_query56); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
-- 
View this message in context: http://n2.nabble.com/Creating-AST-with-third-party-grammar-tp4524691p4542892.html
Sent from the ANTLR mailing list archive at Nabble.com.


More information about the antlr-interest mailing list