[antlr-interest] about parse key words

Jim Idle jimi at temporal-wave.com
Fri Nov 6 10:10:58 PST 2009


You need an identifier rule and use that not an ID token, when identifiers can also be keywords:

 

id : ID | t=EXIT { $t.setType(ID); } .... ;

 

It can be done for all SQL keywords:

http://www.temporal-wave.com/index.php?option=com_psrrun <http://www.temporal-wave.com/index.php?option=com_psrrun&view=psrrun&Itemid=56> &view=psrrun&Itemid=56

 

Jim

 

 

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Renee Luo
Sent: Friday, November 06, 2009 8:10 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] about parse key words

 

Hi there,

 

I have a problem with parse key words.  Like in PL/SQL "EXIT"  is key word. But some variable names also include this key word.

 

DECLARE

 CURSOR my_cursor IS 

 ........

BEGIN

 OPEN my_cursor;

 LOOP

 ......

 exit WHEN my_cursor%NOTFOUND;

 .......

END LOOP;

CLOSE my_cursor;

 

:GLOBAL.exit := 'Y'; --------- (if this statement is  :GLOBAL.exit123:= 'Y', no problem)

 EXECUTE_TRIGGER('WHEN-WINDOW-CLOSED');

 

If my g file is set "exit" as keyword, when the g file analyses the variable name , always go to "statement" rule to match keyword then throw exception. How can let the parser knows the second "exit" is variable( go to varName rule) not key word ( don't  go to "statement" rule)?

 

statement

                :               

                .......

                |

                                "EXIT"^ (expression)? (WHEN! (expression))? SEMI!                       

                |

                                ...........   

                ;

......

 

varName : 

                (COLON)? IDENT^ (DOLLAR IDENT)? ( DOT IDENT )?  ( DOT (IDENT | COMMIT) )? ( DOT (IDENT) )?                  {#varName.setType(VARIABLE_NAME); }

                ;

 

Someone can help me to solve this problem? Thanks in advance.

 

Renee

 

  _____  

This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of ImexSystems Inc.
If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone.
Please contact the sender if you believe you have received this email in error.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091106/b22ba3fe/attachment.html 


More information about the antlr-interest mailing list