By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,143 Members | 826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,143 IT Pros & Developers. It's quick & easy.

parsing problem with lex/yacc - yylval returns unintended value for $1

P: 5
Hi Folks,
I am writing a simple parser to parse SPICE code ( Spice is a transistor level simulator ). The spice code looks like this -
========================
R10 2 3 0.5e-3
C11 4 6 0.2e-6
L13 4 4 0.1e-9
=========================
As you can see each line has 4 items -
a character string followed by an integer then another integer and finally a floating point number.
I need to return the appropriate token on a per line basis.

I am attaching a tar ball called parse.zip that has the following files -
1. netlist ( the source file to be parsed )
2. spice.lex ( the lexer code )
3. spice.y ( the grammar )
4. Makefile

To build the parser, simple type make ( on linux ). Then to run -
%parser < netlist

In the .y file I have the grammar rule where I expect $1 to return the character string, $2 to return the first integer, $3 to return the next integer value and finally $4 to return the floating point value on a per line basis. Mos of this works correctly, except $1 returns the entire line instead of the character string. Can anyone tell what's wrong in the token generator ( lex file ) or the grammar description ( .y file ) ?? Any help will be highly appreciated.

Thanks,

Rajat Mitra
Attached Files
File Type: zip parse.zip (1.8 KB, 72 views)
Jun 2 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.