[prog] lex/yacc problem
Jimen Ching
jching at flex.com
Tue May 27 22:22:11 EST 2003
Hi all,
I've been stuck on this lex/yacc problem for a day now, so I thought I
start asking for help. ;-)
I'm writing a grammar that needs to parse the following:
result = #1 'b1001;
Here, the #1 is a token, and 'b1001 is another token. The yacc BNF looks
like this:
statement : assignment ';' ;
assignment : lvalue '=' optional_delay expression ;
lvalue : identifier ;
identifier : YYCHARSTR ;
optional_delay : /* nothing */ | YYPOUND unsigned_number ;
expression : primary ;
primary : unsigned_number ;
unsigned_number : YYNUMBER ;
The lexer has the following patterns:
WS [ \t\r\b]
Digit [0-9]
DigitU [0-9_]
Letter [a-zA-Z]
LetterU [a-zA-Z_]
WordNum [0-9a-zA-Z]
WordNumU [0-9a-zA-Z_]
Number {Digit}{DigitU}*
Word {LetterU}{WordNumU}*
Binary ([-+]?{Number}{WS}*)?\'[bB]{WS}*[01xXzZ?][01xXzZ?_]*
<INITIAL>"#" { save_word("#"); return YYPOUND; }
<INITIAL>{Binary} { copy_word(yytext); return YYNUMBER; }
<INITIAL>{Word} { copy_word(yytext); return YYCHARSTR; }
The problem I'm running into is that a parser error occurs for the input
above. If I remove the pound sign (#), then it works fine. It seems like
the parser is trying to match the "1 'b1001" to a YYNUMBER instead of
treating the "#1" as a token. How do I write the specification so it does
what I want?
Is this enough details to determine the problem? If not, I can send my
original source code. It is rather large, so that's why I didn't include
it here.
Thanks in advance.
--jc
--
Jimen Ching (WH6BRR) jching at flex.com wh6brr at uhm.ampr.org
More information about the Programming
mailing list