[antlr-interest] How to process blocks of code?

Jan van der Ven jhvdven at xs4all.nl
Thu Dec 28 06:54:00 PST 2006


Dear List,


I am quite new to grammars, so I had no idea what would be the correct 
phrase to use when searching the archives. I think my problem is quite 
common:

I have a set of statements that need to be syntactically checked. I have 
a g file that does just that for the whole set. However I would like to 
do some more logical processing on each statement separately. So I 
thought to call a function whenever the parser has completed a 
statement. My question now is, how can I find the text/tokens belonging 
to that parsed piece of code?

I thought of chunking the pieces first and then feeding that to the 
parser, but this does not work for all scripts I want to process. As I 
am working on SQL an example may be in order.

This handles mulitple statements:

sql_script :
    statement (statement_separator (statement)? )* EOF
    ;


But the CREATE PROCEDURE is a single statement with multiple ones in it:
create_statement
    :
    CREATE PROCEDURE procedure_name (parameter_list)? sql_script
    | CREATE TABLE table_name
    | CREATE VIEW table_name select_statement
    ;


So I think the first alternative is the best way to go:
statement
    :
      select_statement {SQLSyntaxModel.runChecks();}

And we are down to my original question: what was in this statement and 
how can I access it from code?

Any help will be greatly appreciated.

Kind regards,


Jan



More information about the antlr-interest mailing list