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 10:40:05 -0600

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?


On Tue, Jan 27, 2009 at 9:58 AM, Hans Aberg <address@hidden> wrote:
>
> On 27 Jan 2009, at 16:25, Alex Ryu wrote:
>
>> Thank you for your reply.  I would prefer to keep everything in the project
>> straight C for various reasons.  Your idea is interesting, however, I would
>> prefer things to be the other way around - my main function to only call
>> yyparse to parse the instruction string when it encounters one of the
>> integer "header" arrays mentioned above.  The vast majority of execution
>> time will be spent on processing the numeric data, and the code for that
>> task is very long and complex.  So I think it makes more sense to do it that
>> way - however, I understand that might not be possible, seeing as it is not
>> the purpose yacc is designed for.  I suppose the best alternative is to just
>> hand-write a parser in C, maybe using flex for the lexer?
>
> If you somehow have dynamic strings you want to parse from a file or a 
> command line input, then a Bison/Flex is just fine.
>
> You might star with the calculator example in the Bison manual. The code 
> section of you .y file should have a #include. Then if you already have 
> defined arrays, just write code in the actions to call them.
>
>> Thanks for your time
>> Alex
>> 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.
>
>  Hans
>
>




reply via email to

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