[antlr-interest] Problem with '.' character

Jim Idle jimi at temporal-wave.com
Wed Jan 23 08:20:35 PST 2008


The language is inherently ambiguous (who picks ‘.’ for end of
statement?). The real end of statement token depends on whether the
statement end ‘.’ Always precedes a linefeed, or can separate statements
without line feeds: I.E

 

statement . statement . statement

 

So, you need to pick up the context of the ‘.’. You can either do this
in the lexer or the parser (with a gated predicate).

 

Assuming that a ‘.’ Followed by whitespace or linefeed means the end of
statement, otherwise it is a ‘.’, then you can do this lexically:

 

statements

 : statement (EOS statement)*

;

 

// Place holder so we have a token type

//

fragment EOS : ‘.’ (WS|NL);

 

// can also use input.LA(-1) if preceeding spaces turned out to be
important too.

// use just LA() for C target.

//

DOT  : ‘.’ { if (input.LA(1) == ‘ ‘ | input.LA(1) == ‘\n’ | input.LA(1)
== ‘\t’) { $type = EOS; } ;

 

 

With a gated predicate in the parser you could construct your table
expression such that if there is no whitespace preceding the DOT then it
is a compound, but in this case the lexing solution is probably best:

 

statements : statement (DOT statement)* ;

tableRef: ID

                                (

                                                {(
(CommonTokenStream)input ).get( input.index()-1 ).getType() != WS }?=>

 

                                                DOT ID

                                                

                                )*

                ;

 

Jim

 

From: Dev Team [mailto:devteam at jubii.fr] 
Sent: Wednesday, January 23, 2008 3:30 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Problem with '.' character

 

body{font:12px
Arial;margin:3px;overflow-y:auto;overflow-x:auto}p{margin:0px;}blockquot
e, ol, ul{margin-top:0px;margin-bottom:0px;} 

Hi there,
I am currently trying to write a grammar with antlr.
But the '.' character is used for both table/field separator and
statement ending.
here is an example :

method public void myMethod() :
//...
var1 = var2.
var3 = myTable.myField.
//...
end method.

So, the problem is that the grammar considers 'var2.var3' as a
table/field expression.
Does someone know how to resolve this problem ?
thanks in advance


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


More information about the antlr-interest mailing list