[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: %left is not working
From: |
Sasan Forghani |
Subject: |
Re: %left is not working |
Date: |
Wed, 4 Aug 2010 15:48:41 -0400 |
How do you assign to $$. I've tried $$ = $<blIdentifier>1 or in the ( expr
) production $$ = $<blIdentifier>2; I always get an error along the lines
that $$ does not have a type.
On Wed, Aug 4, 2010 at 2:45 PM, Chris verBurg <address@hidden>wrote:
>
> I think I see a few issues in your code, but without the complete source I
> can't conclusively say what your problem might be.
>
> First:
> > if(strcmp($<blOperator>2, "+"))
> Just to be sure: you know strcmp returns 0 when the strings match, right?
> I ask because it looks like you're trying to convert "+" to "add", and this
> logic will convert it to "sub".
>
> Next:
> > strcpy($<blOperator>2, "add");
> I don't think it's really safe to write to a $k variable. Granted if you
> own its type you can do whatever you want, but that's not the case here.
> You show that it's created by strdup, but if the value is "+" then the char
> string is only two characters long -- you can't safely strcpy the
> four-character "add" string to that location.
>
> Next:
> > | ( expr)
> As Hans mentioned, there's a default action here to return the $1 value as
> $$, and that's not what you want. You'll need to make an explicit action to
> return $2 instead. Oh, I see he just posted that. :)
>
> Related to that, you don't assign $$ in the "expr" rule at all. Instead
> you seem to be trying to overwrite $1. Since "expr" is recursive, you'll
> have to assign $$ in order to propagate values correctly up the stack.
>
>
> Hope that helps.. :/
> -Chris
>
>
>
> On Wed, Aug 4, 2010 at 9:39 AM, Sasan Forghani <address@hidden>wrote:
>
>> Thank you for the information. However, how does this relate to the
>> $<blIdentifier> problem I am having. To be more specific, the problem
>> where
>> the $<blIdentifier> of the ASSIGNMENT production ends up with the same
>> value
>> of the ( expr ) production.
>>
>> On Wed, Aug 4, 2010 at 9:04 AM, Hans Aberg <address@hidden> wrote:
>>
>> > On 4 Aug 2010, at 14:17, Sasan Forghani wrote:
>> >
>> > I apologize for my lack of understanding. You said the next step is to
>> >> clean it up in the actions... please clarify?
>> >>
>> >
>> > When you allocate stuff using malloc, strdup, etc. when pointer is not
>> used
>> > anymore, to avoid memory leak, one must apply free(). For example, an
>> action
>> > might look like
>> > $$ = malloc(...) // pr something
>> > // copy over some stuff from the $k values.
>> > Now the, $k values are not used anymore - only $$, so they must be
>> cleaned
>> > up using free().
>> >
>> > This works if you do not want to do error recovery. For that there is a
>> > special function (see the Bison manual).
>> >
>> > I do not program in C, but C++, where the language is taking care of
>> this.
>> > So perhaps some else might give better examples.
>> >
>> _______________________________________________
>> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
>>
>
>
- %left is not working, Sasan Forghani, 2010/08/03
- Re: %left is not working, Hans Aberg, 2010/08/03
- Message not available
- Re: %left is not working, Hans Aberg, 2010/08/03
- Message not available
- Re: %left is not working, Hans Aberg, 2010/08/03
- Re: %left is not working, Sasan Forghani, 2010/08/04
- Re: %left is not working, Hans Aberg, 2010/08/04
- Re: %left is not working, Sasan Forghani, 2010/08/04
- Re: %left is not working, Hans Aberg, 2010/08/04
- Re: %left is not working, Chris verBurg, 2010/08/04
- Re: %left is not working,
Sasan Forghani <=
- Re: %left is not working, Hans Aberg, 2010/08/04
- Re: %left is not working, Sasan Forghani, 2010/08/05
- Re: %left is not working, Hans Aberg, 2010/08/05
Re: %left is not working, Hans Aberg, 2010/08/03