Re: %left

2010-08-09 Thread Sasan Forghani
Thank you Chris for the information. However, I think you are right in saying that I am confused in regards to how Bison is working. After making the modifications you suggested, nothing has changed. Here is the output and below is the code snippets with the changes. Also, the input is a := (b

Re: %left

2010-08-06 Thread Chris verBurg
On Fri, Aug 6, 2010 at 5:17 AM, Sasan Forghani wrote: > > .. > expr : expr BL_ADDOP expr > ... >char bufferT[6]; > ... >$$ = bufferT; > $$ is a char* isn't it? In which case this assigns it to the temporary bufferT, which is going to get wiped out as soon as it goes out of scope. Maybe

Re: %left is not working

2010-08-05 Thread Sasan Forghani
So in any action for a production such as the expr production and specifically the expr : ( expr ) {some action}, specifying $$ will give expr its type. I.E expr : ( expr ) {$$; $$ = $2;} On Wed, Aug 4, 2010 at 5:30 PM, Hans Aberg wrote: > On 4 Aug 2010, at 21:48, Sasan Forghani wrote: > > Ho

Re: %left is not working

2010-08-05 Thread Hans Aberg
On 5 Aug 2010, at 14:01, Sasan Forghani wrote: So in any action for a production such as the expr production and specifically the expr : ( expr ) {some action}, specifying $$ will give expr its type. Bison just implements a union, and the $$ and $k will select the foo field of tha union.

Re: %left is not working

2010-08-04 Thread Hans Aberg
On 4 Aug 2010, at 21:48, Sasan Forghani wrote: How do you assign to $$. I've tried $$ = $1 or in the ( expr ) production $$ = $2; I always get an error along the lines that $$ does not have a type. The same $$, if not declared with %token or %type. See the Bison manual, 3.5.2. __

Re: %left is not working

2010-08-04 Thread Sasan Forghani
How do you assign to $$. I've tried $$ = $1 or in the ( expr ) production $$ = $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 wrote: > > I think I see a few issues in your code, but without the complete source I > can't concl

Re: %left is not working

2010-08-04 Thread Chris verBurg
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($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",

Re: %left is not working

2010-08-04 Thread Hans Aberg
On 4 Aug 2010, at 18:39, Sasan Forghani wrote: Thank you for the information. However, how does this relate to the $ problem I am having. To be more specific, the problem where the $ of the ASSIGNMENT production ends up with the same value of the ( expr ) production. It seems you have

Re: %left is not working

2010-08-04 Thread Sasan Forghani
Thank you for the information. However, how does this relate to the $ problem I am having. To be more specific, the problem where the $ 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 wrote: > On 4 Aug 2010, at 14:

Re: %left is not working

2010-08-04 Thread Hans Aberg
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

Re: %left is not working

2010-08-04 Thread Sasan Forghani
I apologize for my lack of understanding. You said the next step is to clean it up in the actions... please clarify? On Tue, Aug 3, 2010 at 6:13 PM, Hans Aberg wrote: > You seem to do it already by the strdup(). The next step would be to clean > it up in the actions. > > > On 3 Aug 2010, at 23:

Re: %left is not working

2010-08-03 Thread Hans Aberg
You seem to do it already by the strdup(). The next step would be to clean it up in the actions. On 3 Aug 2010, at 23:13, Sasan Forghani wrote: Yes the lexer is generated by flex. In flex script, I have the actions: {addop} {yylval.blOperator = strdup(yytext); return BL_ADDOP;} {identifie

Re: %left is not working

2010-08-03 Thread Hans Aberg
On 3 Aug 2010, at 18:54, Sasan Forghani wrote: | ( expr) as long as there isn't ( expr ) in the input input move up without problem. However once input does have an ( expr) part, $1 at the ADDOP level has the value of $1 at the ASSIGNMENT level. When I add the following action to the ( e

Re: %left is not working

2010-08-03 Thread Hans Aberg
[Please keep the cc to the list so that others may follow.] On 3 Aug 2010, at 22:26, Sasan Forghani wrote: Thank you for the response. However, I don't understand your second statement about properly allocating. In the Bison script, I have IDENTIFIER specified as type . And in the ( expr

Re: %left is not working

2010-08-03 Thread Hans Aberg
On 3 Aug 2010, at 18:54, Sasan Forghani wrote: I have been writing a simple compiler for a CS class and have run into a few problems that I can't figure out how to solve. %left does not seem to be working as Bison is derivating immediately. For example: a := b + c + d expr : expr ADDOP e