[antlr-interest] languages without reserved words

Michael Brade brade at informatik.uni-muenchen.de
Thu Mar 2 02:49:41 PST 2006


Hi all,

is there a standard way or a best practice to implement grammars for languages 
that allow identifiers to be anything, including the keywords of the language 
itself?

Example: I have a language that has the keyword "position", and that allows to
create tags like
  NCNAME (...) { .... }
with NCNAME being all letters and '_'.

Or think of C/C++ allowing to declare a variable "int struct = 0;".

The problem is that as soon as I use literals in the parser they are passed on 
to the lexer. If I disable testLiterals all keywords stay NCNAMEs, if I 
enable testLiterals all NCNAMES with text "position" are turned into the 
position-literal.

I don't want to use actions to test the NCNAME in the parser. What other 
possibilities are there?

Thanks,
-- 
Michael Brade;                 KDE Developer, Student of Computer Science
  |-mail: echo brade !#|tr -d "c oh"|s\e\d 's/e/\@/2;s/$/.org/;s/bra/k/2'
  °--web: http://www.kde.org/people/michaelb.html

KDE 4: Beyond Your Expectations
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20060302/863684a2/attachment.bin


More information about the antlr-interest mailing list