[antlr-interest] Line terminator.

Anthony W Youngman Anthony.Youngman at ECA-International.com
Thu Apr 10 02:01:16 PDT 2003


I have a similar problem in my grammar - with an IF/THEN/ELSE, whether the THEN/ELSE clause is terminated by the line-feed depends on whether the associated statment is on the same line ...

So what I've done is declare each statement without regard to the statement terminator.

My parser now builds up a list of statements with the following rules

exitst : (exitt:"EXIT"^ {System.out.println(exitt+" exit ");} ) ;

statement : ( inputst | printst | exitst | ifst | loopst | "NULL" ) ;

statement_line : (statement ( SEMI! statement)* ) ;

statement_list
	: ( (statement_line (EOL!)+ )+ )
	{ ## = #(#[STLIST,"stlist"], ##); }
	;

So my statement_list rule now throws away the EOL, and in corner cases where I need to be able to handle where there is no EOL I can refer to statement or statement_line. I haven't properly defined it yet but my definition for IF/THEN/ELSE will be something like

   "IF" expr "THEN" statement_line "ELSE" statement_line
 | "IF" expr "THEN" EOL statement_list "END" (EOL!)* "ELSE" EOL statement_list "END" EOL

See if you can do something like this ...

Cheers,
Wol

-----Original Message-----
From: Cesar Octavio López Nataren [mailto:cesar at ciencias.unam.mx] 
Sent: 10 April 2003 09:15
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Line terminator.


Hello, in my grammar the simbols:  \u000A, \u000D, \u2028, \2029 are called 
Line terminator. 

Now my problem is: 

There are some small cases where I don't want to ignore that a line 
terminator appears. 

Here is an example: 

ContinueStatement: continue [no LineTerminator here] Identifier_opt; 

By now, I had been ignoring these "corner cases" by just ignoring on the 
lexer those symbols with the very well known Token.SKIP but now I need more 
control. 

what do you suggest? 

Erasing the Token.SKIP from the lineTerminators lexing rules, and modifying 
all my parser rules to take care of lineTerminators? (looks like lot's of 
work for me). 

is possible a some kind of "lexical" predicates to make a solution for it? 

or? 


Cheers 


césar

 

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/ 

-------------- next part --------------
This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.


More information about the antlr-interest mailing list