Lex and Yacc Newbie Questions!!!

harisriniv@yahoo.com (Hari Sriniv)
26 Mar 2004 22:03:12 -0500

          From comp.compilers

Related articles
Lex and Yacc Newbie Questions!!! harisriniv@yahoo.com (2004-03-26)
Re: Lex and Yacc Newbie Questions!!! toby@telegraphics.com.au (2004-04-04)
Re: Lex and Yacc Newbie Questions!!! trbauer@calpoly.edu (Tim Bauer) (2004-04-14)
| List of all articles for this month |

From: harisriniv@yahoo.com (Hari Sriniv)
Newsgroups: comp.compilers
Date: 26 Mar 2004 22:03:12 -0500
Organization: http://groups.google.com
Keywords: lex, yacc, question, comment
Posted-Date: 26 Mar 2004 22:03:12 EST

Hello experts,
I have some rudimentary question with the Lex and Yacc. I have been
developing an assembler for the in house processsor. I have assembled
the normal instructions pretty easily using the lex and Yacc. I have
some challenges for the branch instructions. I have also made some
progress in it and also know how to approach it. But I am a little bit
confused as how to do it in Lex and Yacc. What I have in mind is to
make 2 passes.

During the first pass, I will get associate the labels to the PC
(Prog. Counter) value and during the second pass assemble all the
instructions and for the Branch instructions assemble using the PC
values from the first pass. For this I have to open the same file
twice and parse it using lex and Yacc.

Whats happening here is I have assigned a variable in a header file
(say prc_defines.h) named static unsigned int Firstpass (This is the
flag I am using in my program). This .h file is included in main.c and
asm.y. Everything is fine and good during the first pass. It
associates the label to PC. But during the second pass the I change
the Firstpass (flag) to zero which signifies that it is not the first
pass and still, it works as though the it is the firstpass. I
understand (guess) the yyparse() initializes the variable defined
inthe prc_defines.h to 1 which makes it to behave like a first pass.
See the value changed in the main.c is overridden inside the asm.y.
Any thoughts, help as how to solve this puzzle in lex and yacc.

Any help is greatly appreciated. Thanks in advance.

[Look at the generated yyparse(), debug it like any other C code. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.