Re: Incomplete last line won't match

"Zhu Wenzhang" <>
21 Jun 2001 03:18:11 -0400

          From comp.compilers

Related articles
Incomplete last line won't match (Francis Harvey) (2001-06-14)
Re: Incomplete last line won't match (Tim Van Holder) (2001-06-21)
Re: Incomplete last line won't match (Zhu Wenzhang) (2001-06-21)
| List of all articles for this month |

From: "Zhu Wenzhang" <>
Newsgroups: comp.compilers
Date: 21 Jun 2001 03:18:11 -0400
Organization: CSIS, The University of Hong Kong
References: 01-06-032
Keywords: lex
Posted-Date: 21 Jun 2001 03:18:10 EDT

Why not use "-d" option to flex your scanner and see the debug output? It is
always a good way to use "-d" option when having problems with flex.

BTW: Using different status in your program causes a lot of mess. Why not
just use such rules like the following :
^C {ident} ... return CSTAT;
^Q {ident} ... return QSTAT;
And in the yacc file, you can simplify your "XGROUP" to
XGROUP: /*empty*/
        | XGROUP XSTAT
If you need some inner value of XSTAT, you can pass the value to yylval(use
%union to have a rich definition of yylval) in the lex scanner. Generally
speaking, my suggestion is "do everything that can be recognized in regular
expresion in lex and leave only the nesting rules to yacc as lex is unable
to handle this."

"Francis Harvey" <> wrote in message
> Greetings,
> Using Flex 2.5.4 and Berkeley Yacc, I have finished a fairly complete
> program for analyzing the syntax and logic of a user's source file.
> Unfortunately, my program has one glaring flaw. If a user provides a
> source file whose last line does not have a newline character at the
> end, the parser will fail to recognize all of the rules that it should
> and the last line ends up getting echoed to my output file. All of my
> other rules and grammar will be fulfilled, but for the last line only
> the initial condition rule (.*\n?) will be matched and then no other.

Post a followup to this message

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