Uppercase for tokens?

24 views
Skip to first unread message

Elvis Stansvik

unread,
Feb 3, 2014, 4:41:18 PM2/3/14
to sab...@googlegroups.com
Hi all,

Me and a friend of mine are about to start a project writing a compiler for MiniJava (Appel), and we'll probably be using SableCC.

I've looked through some documentation and examples, and I noticed that in most (all?) SableCC grammars I could find, both non-terminals and terminals (tokens) are written in lowercase.

In grammars for other tools like yacc and ANTLR, tokens are usually written in uppercase or at least capitalized, to make them easy to distinguish from non-terminals when reading the grammar.

Is is bad practice to this in SableCC grammars for some reason?

Best regards,
Elvis Stansvik

Etienne Gagnon

unread,
Feb 3, 2014, 7:38:12 PM2/3/14
to sab...@googlegroups.com

Hi,

SableCC reserves uppercase letters for its own keywords. As a consequence, you can use any (lowercase) identifier you like in your grammars, as none is lost to reserved keywords.

If you wish to really highlight tokens in your grammars, you can preceed references to tokens with "T.". For example:

if_statement = T.if T.l_par exp T.r_par statement;

Have fun!

Etienne

Etienne Gagnon, Ph.D.
http://sablecc.org

Elvis Stansvik

unread,
Feb 13, 2014, 10:50:15 AM2/13/14
to sab...@googlegroups.com
(Sorry for the slow reply, I had forgot to turn on e-mails for this group in my settings)

On Tuesday, February 4, 2014 1:38:12 AM UTC+1, Etienne Gagnon wrote:

Hi,

SableCC reserves uppercase letters for its own keywords. As a consequence, you can use any (lowercase) identifier you like in your grammars, as none is lost to reserved keywords.

Ah, that explains it.

If you wish to really highlight tokens in your grammars, you can preceed references to tokens with "T.". For example:

if_statement = T.if T.l_par exp T.r_par statement;

Alright. I'm okay with just the lowercase, it's not such a big deal. But thanks for the tip.
 

Have fun!

 Thanks!
Reply all
Reply to author
Forward
0 new messages