Hello,
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 expr
expr: ref_name
ref_name: IDENTIFIER
ADDOP
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;}
>> {identifier} {yylval.blIdentifier = strdup(yytext); return BL_IDENTIFIER;}
>>
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 le
ank 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,
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 wr
I've modified my code to the following:
$$ = varLocation //at the ref_name rule level
$$ = $2 //at the ( expr ) rule level
$$ = bufferT //at the expr rule level
The output is still incorrect. Moving up the stack the value does not
hold. For example after derivating to the ref_name level for the
uot;, $$);
}
stmt
: ref_name BL_ASSIGNMENT expr {
fprintf(ptrToIrFile, "mov %s %s\n", $3,
$1);
printf("$1 at := is: %s\n", $1);
printf("$3 at := is: %s\n", $3);
printf("$$ at := is: %s\n", $$);
amtOfTe
Below is some thinking I've done on the %left problem not working. I'm
hoping that someone will see what is wrong and point it out to me so I can
get the behavior I want. If input is a := b + c + d, Bison is adding c + d
and then adding b. Since add is %left, it should add b + c and then d.
Than
In the ref_name production, I have the following statement: $$
= strdup(varLocation). varLocation is local buffer. In the ( expr )
production, I have the statement $$ = $2. Am I
correct in thinking that I shouldn't have to use strdup() here since expr in
( expr ) will be getting its value from t
It seems that my code was somehow effecting how Bison was parsing. Or at
least this is the assumption I am left making. After deleting all the code
that had anything to do with the %left issue, the Bison parse is correct. Or
at least it is according to the printf statements. Using the printf
state
After the %left issue, the issue left is how to send data up the stack.
Once a production such as expr : expr + expr is reduced and the actions
performed how can I send data to the next reduction?
___
help-bison@gnu.org http://lists.gnu.org/mailman/listin
therwise sent out your actual bison source file? Would that be possible to
> do? It might not be, due to company IP concerns, etc, but at least those of
> us trying to help you wouldn't be shooting in the dark so much. :)
>
> -Chris
>
>
>
> On Mon, Aug 9, 2010 at 2:27
12 matches
Mail list logo