[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LaTeX from SableCC & auto-resolution of shift/reduce



Hi all,

I'm writing a toy language (for a POPL paper).  To avoid embarassing
errors, it would be nice if my toy language could actually have a parser
which recognizes the language.  So far, so good; I can write a SableCC
grammar for the language.

1. It would be great if I could generate a LaTeX grammar from the SableCC
grammar (design conformance for compilers!).  It doesn't seem like too
much work and I guess I could do this in a few hours.

2. Unfortunately, my language has shift-reduce conflicts.  I can manually
resolve them, but then if I would automatically generate LaTeX on the
resolved grammars, I'd get pretty nonintuitive grammars as a result.

Now, it appears to me that Etienne's inlining algorithm for resolving
shift-reduce conflicts could be automatically applied to a source SableCC
file to get a shift-reduce free SableCC file.  Does it seem to be
reasonable to implement a SableCC-to-SableCC compiler that could
automatically inline offending productions, or am I missing something
here?

It's a bit of a hassle for me to inline the offending production by hand,
as I happen to use it 4 times, and that would make my grammar look pretty
unreadable; but if I could do it automatically, that would be grand.

(Etienne's explanation of shift-reduce conflicts is at
http://www.sable.mcgill.ca/listarchives/sablecc-list/msg00238.html
for those who might not have the link ready)

To be explicit, one offending grammar chunk is:
  param = {pn} type_constr param_name;
  type_constr = {simple}ds_role_name |
                {cplx}[ds]:ds_role_name dot [role]:ds_role_name;

where ds_role_name, param_name are standard identifiers, dot is '.'.  Of
course I can inline into:

  param = {p1} ds_role_name param_name |
          {p2} [ds]:ds_role_name dot [role]:ds_role_name;

but I don't want to do that for each use of type_constr, because it
obscures the exposition of my toy language!

pat