On 10 August 2010 21:23, Sasan Forghani <sasanforgh...@gmail.com> wrote: > Chris, > > The project is for a CS class. I don't know if I can submit it to the > list. I don't want my code out on the internet. I don't know how my prof > would feel about that. That being said, I discovered that if I add any code > Bison's parse goes wrong. Even if I add an empty action the parse goes > wrong. > > For example: > > expr : expr addop expr { } > > causes Bison to parse a = b + c + d > > c + d = something > b + something = something > > On the note of sending data up the stack, my prof sent me an email with a > example script that I am going to try tonight. Why do you think adding an > action to the rule causes Bison to to parse incorrectly? > > Thanks again for all the help.
I think you need to think about what your trying to do before you do it for example lets look at an expression: x = 2 + y - 43 ... So ok what way do you want this to work depends on how you want this to be parsed and what output you want for one of my projects simply doing something like: %right '=' %left '+' '-' expr: accessor '=' expr | expr '+' expr | expr '-' expr | primary primary: INTEGER | IDENTIFIER accessor: IDENTIFIER So ok this WILL parse the code your code you want, but if your making something like a compiler and you generate your self some kind of DAG tree representation like: struct symtab { short opa_type, opb_type; union { struct symtab * symbol; int integer; char * string; } opa; union { struct symtab * symbol; int integer; char * string; } opb ; } And you do something like * example: * >>> x = y = z = 2 + 2 + 2; + / \ + 2 / = / \ x = / \ y = / \ z 2 Which you may want to change into something like: = / \ x = / \ y = / \ z + / \ + 2 / \ 2 2 Not sure if these diagrams will look right i jsut copied and pasted them out of one of my source files which was a long comment if it didnt come out right @see http://code.redbrain.co.uk/cgit.cgi/gcc-dev/tree/gcc/python/pypy.c?h=python @line 142 Might be what your getting confused about not sure let us know how your getting on. --Phil _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison