[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
%left is not working
From: |
Sasan Forghani |
Subject: |
%left is not working |
Date: |
Tue, 3 Aug 2010 12:54:27 -0400 |
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 is specified with the %left
The directed translation in parse tree representation is
E
E + E
R E + E
b c d
Since ADDOP is specified with % left shouldn't the tree look like:
E
E + E
E + E R
R R d
b c
Another problem I have run into is sending data back when a recursive call
is finished. If the input is a := (b + c) + d, the code I have is as
follows:
stmt : ref_name BL_ASSIGNMENT expr {
fprintf(ptrToIrFile, "mov %s %s\n", $<blIdentifier>3,
$<blIdentifier>1);
}
expr : expr BL_ADDOP expr {
if(strcmp($<blOperator>2, "+"))
strcpy($<blOperator>2, "add");
else
strcpy($<blOperator>2, "sub");
char bufferT[6];
changeToString(++amtOfTemps, "T", bufferT);
fprintf(ptrToIrFile, "%s %s %s %s\n",
$<blOperator>2, $<blIdentifier>1, $<blIdentifier>3,
bufferT);
strcpy($<blIdentifier>1, bufferT);
}
| ( expr)
as long as there isn't ( expr ) in the input input move up without problem.
However once input does have an ( expr) part, $<blIdentifier>1 at the ADDOP
level has the value of $<blIdentifier>1 at the ASSIGNMENT level. When I add
the following action to the ( expr ) production- {strcpy($<blIdentifier>1,
$<blIdentifier>2);}, $<blIdentifier>1 at the ADDOP level has the correct
value but then the $<blIdentifier>1 at the ASSIGNMENT level value is what I
changed $<blIdentifier>1 to be at the ( expr ) level. I'm very confused.
Please help.
- %left is not working,
Sasan Forghani <=
- 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, 2010/08/04
- Re: %left is not working, Hans Aberg, 2010/08/04