[antlr-interest] Extracting portions of code

mzukowski at yci.com mzukowski at yci.com
Fri Oct 11 07:47:13 PDT 2002


First a nitpick.  The ^ on sql_statement doesn't make sense:

> seq_of_statements:
> 	assignment_statement
> 	| if_statement 
> 	| sql_statement^
>         ;

^ should only be applied to tokens, it doesn't make sense on a rule.

findAll and findAllPartial may work for you.  They try to match trees
against trees, comparing on types but ignoring the text.  I would take a
different approach, however.  I would create a tree grammar for your PL/SQL
and then just override sql_statement to have actions to print itself out.
Alternatively you could build a list of all sql_statement roots in your
parser and use that as the starting point, but you still need most of the
tree grammar to be able to write the statments out.  

Monty

> -----Original Message-----
> From: Benhur [mailto:krupa_gadde at yahoo.com]
> Sent: Thursday, October 10, 2002 9:40 PM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Extracting portions of code
> 
> 
> Hi all,
> 
> I am Krupa Benhur, who is working on PL/SQL grammar. I have written 
> grammar for the same and used "^" notation for tokens to make them 
> as root nodes. I have many sub-rules as part of my grammar like 
> this - 
> 
> plsql_block:
> 	(("declare")? (declare_spec)+)? 
> 	("begin"^)?
>       	seq_of_statements
>       	("exception" exception_handler (exception_handler)*)? 
>       	("end" (label_name)? SEMI!)?
>       	;
> 
> seq_of_statements:
> 	assignment_statement
> 	| if_statement 
> 	| sql_statement^
>         ;
> 
> I have also written grammar for sql_statement. I am able to apply 
> this grammar for any PL/SQL program and see the tree generated. Now, 
> using this grammar, I want to extract the sql_statement part from 
> the PL/SQL file and write the same to another file. Can some one 
> give me code sample for the same. 
> 
> I feel I need to use findAll(AST target) and findAllPartial(AST sub) 
> member functions of the abstract class BaseAST. I am not sure on how 
> to pass AST as a parameter to this findAll member function. I will 
> be very happy if some one can help me in this regard.
> 
> Thanks in advace
> Benhur
> krupa_gadde at yahoo.com
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/ 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list