help-bison
[Top][All Lists]
Advanced

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

Re: Using the "output" from yacc


From: Alex Ryu
Subject: Re: Using the "output" from yacc
Date: Tue, 27 Jan 2009 13:11:00 -0600

On Tue, Jan 27, 2009 at 12:36 PM, Hans Aberg <address@hidden> wrote:
> On 27 Jan 2009, at 17:40, Alex Ryu wrote:
>
>>>> PS Is top posting or bottom posting the custom here?
>>>
>>> The style I use, inserting comments, is normal on all technical lists of
>>> some age that I know - easier to follow technical details. Top posting is a
>>> younger style.
>
> Why do you top post, if you first ask, then get the reply that the other is
> normal on technical lists?
Because the style "inserting comments" does not seem to prescribe
either top-posting or bottom-posting when one doesn't wish to respond
to any particular comment?
>
>> One last question, and then I think I understand.  I have read the
>> various examples in the manual, and none of them look like they are
>> doing anything "external," so to speak.  The following is copied from
>> the mfcalc example, grammar section:
>> ********************
>> exp:      NUM                { $$ = $1;                         }
>>            | VAR                { $$ = $1->value.var;              }
>>            | VAR '=' exp        { $$ = $3; $1->value.var = $3;     }
>>            | FNCT '(' exp ')'   { $$ = (*($1->value.fnctptr))($3); }
>>            | exp '+' exp        { $$ = $1 + $3;                    }
>>            | exp '-' exp        { $$ = $1 - $3;                    }
>> ********************
>> Once the string has been fully evaluated, then exp will be of type
>> NUM, so the action for NUM would be:
>> {$$ = $1; array[someindex]  = $$}
>> Is that correct?
>
> Yes, normally one has to insert some such global reference. (If you want
> more than one simultaneous parser call per program, then you must make a
> pure parser.) But you can of course let the array indexes be parsed. You
> might look at the grammar for some standard like C or C++ to get ideas.
>
> If you want more than one array, also defined on the fly, then make a lookup
> table with identifier names and the semantic values (such an array). Then
> you can make code like
>  define c[100]
>  read c from "filename"
>  if c[1] < 54 and c[0] != 7 then c[3] := 5
> Environments are created by stacking such tables.
Okay, I think I understand.  Thank you.
> If you further want to have loops, like
>  for i=1..100 do c[i] := i+1
> then you need to build a closure: a piece of data that can hold a
> representation of the whole expression together with an evaluator function
> that can evaluate it after the parse.
>
>  Hans
>
>
>




reply via email to

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