[antlr-interest] structure parameter access

Alexey Demakov demakov at ispras.ru
Tue Nov 9 03:40:51 PST 2004


From: <silverio.di at qem.it>
> I've a problem with a simple language which have
> some grammar likeness to C/C++ & Java.
> 
> I've tried to read the C & Java grammars on ANTLR
> web page but I isn't been able to uderstand how they
> solve my question.
> 
> My language say that:
> 
> a) struct_name.struct_parameter
> 
> How you can see (a) is likeness to c statement.
> My throuble is that in between struct_name and '.' I can't
> admit spaces chars and between '.' and struct_parameter
> I can't admit spaces chars too. I think this is same behaviour
> required to a C/C++ program.
> 
> But I don't understand how to obtain that starting from:
> 
> statement : label | struct_assign;
> label : LABEL EOL;
> struct_assign : IDENT POINT IDENT ASSIGN IDENT EOL;
> 
> WS : (' ' | '\t' | '\f') { $setType(Token.SKIP); };
> EOL : ("\r\n" | '\r' | '\n'   ) { newline(); };
> POINT : '.';
> IDENT : ('a'..'z')+;
> 
> Thank you very much for your suggestions...
> Silverio Diquigiovanni

Because parser doesn't know about skipped tokens the only way to
skip WS and forbid WS near POINT - is to handle struct_name.struct_parameter
as single token in lexer.
Another idea - the only idea - is to track WS while skipping and decorate
POINT token by flag indicating that there was WS just before or after.
You can check it in parser rule and print error message.

Regards,
Alexey

-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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





More information about the antlr-interest mailing list