[Mediacloth-talk] MediaCloth grammar

Thiago Arrais thiago.arrais at gmail.com
Thu Jan 31 12:26:28 EST 2008


Eric,

On Jan 28, 2008 6:55 PM, Eric Armstrong <Eric.Armstrong at sun.com> wrote:
> The racc manual page had this example:
>
> class Calcparser
> rule
>    target: exp { print val[0] }
>
>    exp: exp '+' exp
>       | exp '*' exp
>       | '(' exp ')'
>       | NUMBER
> end
>
> The idea of "rule" and "exp" is clear. I
> assume that "target" is specifying the right
> side of the production rule. Yes? So what
> is "val[0]", in that context?

The array `val` holds the results from matching each of
the productions inside the grammar rule. In this case it
will contain anything returned from the `exp` rule which,
by default, is _its_ `val[0]` value [1] and in the end boils
down to either a number or an opening parenthesis.

Cheers,

Thiago Arrais

[1] http://i.loveruby.net/en/projects/racc/doc/grammar.html


More information about the Mediacloth-talk mailing list