SableCC 4

70 views
Skip to first unread message

dberry

unread,
Jul 20, 2012, 10:42:22 AM7/20/12
to sab...@googlegroups.com
Étienne,

I am about to implement a rather large grammar. I would like to use SableCC 4 as that is going to be the latest and the grammar for SableCC 4 appears to be much closer to pure EBNF than SableCC3. I tried compiling the master branch from GitHub, but it is currently throwing errors. 

Should I use 4 beta 4 or 3.3?  If I put the entire grammar in 3.3 would I have to rewrite the grammar to upgrade to 4?

Thanks,

Dave

Etienne Gagnon

unread,
Jul 20, 2012, 12:29:01 PM7/20/12
to sab...@googlegroups.com
Hi Dave,

You should definitely use SableCC 3.3. It is stable and has a very
powerful inlining process that eliminates many grammar conflicts. As
long as you don't use tree transformations, you'll get a very clean EBNF
syntax.

SableCC 4's syntax keeps evolving from beta to beta. I make it available
so that people can play with it and give some feedback or express wishes
for new features (I got really good feedback from getting it in the
hands of compiler course students). SableCC 4 is not ready for being
used for serious development; it doesn't even pass the base test of
generating its own parser (it still uses SableCC 3.3).

Have fun!

Etienne

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

dberry

unread,
Jul 20, 2012, 12:52:15 PM7/20/12
to sab...@googlegroups.com
Thanks. 

Can you point me to any examples of handling an include statement, where you would need to begin parsing that included file when the include statement is reached by the parser.

Etienne Gagnon

unread,
Jul 20, 2012, 2:33:58 PM7/20/12
to sab...@googlegroups.com
Hi Dave,

The SableCC philosophy for providing a clean include statement is for the included file content not to be part of the syntax of the including file. For example:
...
i = x + y;
include("file.xyz"); # includes additional computation
print(z);
...
In other words, the grammar would have an include statement among its statements:
...
statement =
  {assign} id assign exp sc |
  {include} include l_par string r_par sc |
...
This way, you parse the including file as usual. Later, while walking the AST, when you discover an include statement, you open the included file and parse it using a new parser.

If, on the other hand, you are looking for dirty C-like preprocessing file inclusion, you'll have to do it the dirty C way: implement a preprocessor to preprocess the character stream before feeding it to the parser and deal with the complex issue of figuring out how to provide syntax errors locations to your users.


Have fun!

Etienne
Etienne Gagnon, Ph.D.
http://sablecc.org
On 2012-07-20 12:52, dberry wrote:
Reply all
Reply to author
Forward
0 new messages