[erlang-questions] BNF/EBNF Grammar for Erlang

Robert Raschke rtrlists@REDACTED
Tue Nov 15 12:23:07 CET 2011


On Mon, Nov 14, 2011 at 11:02 PM, Richard O'Keefe <ok@REDACTED> wrote:

>
> Well, any grammar that's actually *used* as the front end of something
> interesting, whether it's a Prolog DCG, or Yacc, or ML-Yacc, or Yecc,
> or whatever is going to have *both* pure syntax *and* some semantics
> in there.  Here's one of the examples from the GENTLE kit:
>
>
> 'root' expression(-> X) print(X)
>
> 'nonterm' expression(-> INT)
>
>   'rule' expression(-> X  ): expr2(-> X)
>   'rule' expression(-> X+Y): expression(-> X) "+" expr2(-> Y)
>   'rule' expression(-> X-Y): expression(-> X) "-" expr2(-> Y)
>
> 'nonterm' expr2(-> INT)
>
>   'rule' expr2(-> X  ): expr3(-> X)
>   'rule' expr2(-> X*Y): expr2(-> X) "*" expr3(-> Y)
>   'rule' expr2(-> X/Y): expr2(-> X) "/" expr3(-> Y)
>
> 'nonterm' expr3(-> INT)
>
>   'rule' expr3(-> X  ): Number(-> X)
>   'rule' expr3(-> - X): "-" expr3(-> X)
>   'rule' expr3(-> + X): "+" expr3(-> X)
>   'rule' expr3(-> X): "(" expression(-> X) ")"
>
> 'token' Number(-> INT)
>
> If you ignore the (-> ...) parts, you have yet another minor variant
> of BNF.  The (-> ...) parts give you the semantics.  Utterly commonplace.
>
>
Wow, it's been a while since I've heard GENTLE mentioned. It is a great
simple toolkit (built on top of standard yacc and lex) for implementing
translators/interpreters/compilers of all sorts. Highly recommended.
Available here: http://gentle.compilertools.net/

Apologies for being off-topic,
Robby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111115/c57366fe/attachment.htm>


More information about the erlang-questions mailing list