Re: bison/flex grammar

"Robert Monroe" <robert.f.monroe@verizon.net>
11 Sep 2002 23:19:45 -0400

          From comp.compilers

Related articles
bison/flex grammar chvist@club-internet.fr (christian visticot) (2002-09-03)
Re: bison/flex grammar robert.f.monroe@verizon.net (Robert Monroe) (2002-09-08)
Re: bison/flex grammar pjj@cs.man.ac.uk (Pete Jinks) (2002-09-08)
Re: bison/flex grammar robert.f.monroe@verizon.net (Robert Monroe) (2002-09-11)
| List of all articles for this month |
From: "Robert Monroe" <robert.f.monroe@verizon.net>
Newsgroups: comp.compilers
Date: 11 Sep 2002 23:19:45 -0400
Organization: http://groups.google.com/
References: 02-09-020 02-09-043
Keywords: lex
Posted-Date: 11 Sep 2002 23:19:45 EDT

"Robert Monroe" <robert.f.monroe@verizon.net> wrote in message news:02-09-043...
> Specify a (f)lexer:
>
> %%
> description {return DESCRIPTION;}
> keywords {return KEYWORDS;}
> = {return *yytext;}
> \"[^\"\n]\" {/* One of a million ways to describe a string */ return
> yytext;}
> .|\n {/* eat everything else */}
> %%


Naturally, after posting my response I immediately saw a few errors in
the flex part (incorrect RE for a string, no yylval assignments...).
For what it's worth, here are the corrections:


%%
description {return (yylval.intval = DESCRIPTION);}
keywords {return (yylval.intval = KEYWORDS);}
= {return (yylval.intval = *yytext);}
\"[^\"\n]*\" {/* One of a million ways to describe a string */
yylval.strval = yytext; return VALUE;}
.|\n {/* eat everything else */}
%%


Bob.


Post a followup to this message

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