bison-patches
[Top][All Lists]
Advanced

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

Naming the symbols


From: Akim Demaille
Subject: Naming the symbols
Date: Fri, 08 Jul 2005 16:57:36 +0200
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Hi,

I'm trying to put together two communities here: that of Bison ---
parser generator --- , and that of MonoBURG --- code generator
generator.  They share several features, and this message is about
trying to have a common syntax for one of these feature.  Or not.

Both take rules as input, decorated with actions referring to the
values of the symbols.  Bison, just like Yacc, uses $n, while MonoBURG
was just equipped with symbol labels (before the values had to be
accessed in a completely different way).

As an example, here is a piece of MonoBURG input code as of today:

  move: Move(exp, Mem(b : Binop(binop_left : Const, binop_right : exp)))
  {
    short sign = (b.cast<Binop> ()->oper_get () == Binop::sub) ? -1 : 1;
    EMIT (ASSEMBLY.load_build (binop_right->asm_get (),
                             sign * binop_left.cast<Const> ()->value_get (),
                             tree->left_get ()->asm_get ()));
  }

here is a piece of Bison input :

   exp:
     "if" exp "then" exp
      { $$ = new ast::IfExp ($2, $4); }
   | "if" exp "then" exp "else" exp
      { $$ = new ast::IfExp ($2, $4, $6); }

I dislike the latter, I would much rather have a labeling scheme, just
as we introduced in MonoBURG.  And `:' seems to be quite a nice
symbols to this end :

   r:exp:
     "if" c:exp "then" t:exp
      { r = new ast::IfExp (c, t); }
   | "if" c:exp "then" t:exp "else" e:exp
      { r = new ast::IfExp (c, t, e); }

But then we have several problems: the colon is seriously overloaded
in the context of Bison.  Contrary to MonoBURG, Bison can't require
rules to be terminated (thanks to POSIX).  Contrary to Bison, MonoBURG
does not need to name its LHS.  The result might be quite clumsy to
read:

        r:exp: l:exp r:exp
        l:exp: s:symbol
        r:exp: s:symbol

but I don't think it's becoming ambiguous.  Labels are optional, of
course.

I would like to share the same syntax for both tools.  So we have a
set of choices:

- use this syntax, it is human readable and natural.  It is just
  probably very hard to implement in Bison's bison grammar :(  Thanks
  POSIX.

- use another syntax, say another separator, such as `@'.  I don't
  like it too much, because it's a poor separator IMHO.  But it is
  frequently used in functional languages for similar purpose.  It
  is also usually bound to locations in Bison.

- there is no reason for MonoBURG to escape from a nice an clean
  syntax just because Bison cannot keep the pace.

- maybe it is time to use... the GLR parser to parse Bison's grammar
  file without having to resort to these horrible scanner hacks.

Any opinion?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]