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) |
From: | "Pete Jinks" <pjj@cs.man.ac.uk> |
Newsgroups: | comp.compilers |
Date: | 8 Sep 2002 22:53:55 -0400 |
Organization: | Computer Science Dept, University of Manchester |
References: | 02-09-020 |
Keywords: | parse, lex |
Posted-Date: | 08 Sep 2002 22:53:55 EDT |
christian visticot wrote:
>
> I try to parse a file like following:
>
> description=a super example keywords=value1 value2
>
> and the result would be:
>
> attribute:description
> values:a super example
>
> attribute keywords
> values: value1 value2
The flex:
[a-z]+"="[a-z0-9 ]+/[ \t\n] {char*c= strchr(yytext, '=');
*c= 0; printf("attribute: %s\n", yytext);
printf("values: %s\n\n", c+1);
}
[ \t\n] ;
. {printf("didn't recognise: %s\n", yytext);}
outputs:
attribute: description
values: a super example
attribute: keywords
values: value1 value2
which should give you some idea how to do it properly.
i.e. I wouldn't show this to my students, and what I would show them
would depend on the context in which I was solving this sub-problem.
--
Peter J. Jinks, Room 2.99, Department of Computer Science,
University of Manchester, Oxford Road, Manchester, M13 9PL, U.K.
(+44/0)161-275 6186 http://www.cs.man.ac.uk/~pjj
Return to the
comp.compilers page.
Search the
comp.compilers archives again.