Related articles |
---|
[5 earlier articles] |
Re: coupling LALR with a scanner? paul@paulbmann.com (Paul B Mann) (2011-09-13) |
Re: coupling LALR with a scanner? armelasselin@hotmail.com (Armel) (2011-09-16) |
Re: coupling LALR with a scanner? paul@paulbmann.com (Paul B Mann) (2011-09-17) |
Re: coupling LALR with a scanner? armelasselin@hotmail.com (Armel) (2011-09-19) |
Re: coupling LALR with a scanner? paul@paulbmann.com (Paul B Mann) (2011-09-19) |
Re: coupling LALR with a scanner? armelasselin@hotmail.com (Armel) (2011-09-20) |
Re: coupling LALR with a scanner? cdodd@acm.org (Chris Dodd) (2011-09-23) |
Re: coupling LALR with a scanner? cfc@shell01.TheWorld.com (Chris F Clark) (2011-09-29) |
Re: coupling LALR with a scanner? armelasselin@hotmail.com (Armel) (2011-10-02) |
Re: coupling LALR with a scanner? cfc@shell01.TheWorld.com (Chris F Clark) (2011-10-03) |
Re: coupling LALR with a scanner? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2011-10-03) |
From: | Chris Dodd <cdodd@acm.org> |
Newsgroups: | comp.compilers |
Date: | 23 Sep 2011 23:59:35 +0100 |
Organization: | X-Privat.Org NNTP Server - http://www.x-privat.org |
References: | 11-07-013 11-07-015 11-07-018 11-08-004 11-09-016 11-09-017 11-09-022 11-09-023 |
Keywords: | parse, yacc |
Posted-Date: | 25 Sep 2011 16:29:46 EDT |
"Armel" <armelasselin@hotmail.com> wrote in news:11-09-023@comp.compilers:
> Of course in the presence of something like expr / expr the parser knows
> the / is for a division, and if the / is found where expr is expected it
> knows there is a regular expression coming.
> I don't see how I could hack this into a scanner only. maybe some
> specific preceding tokens. I have pass again some time on that question.
The usual way to do this in a flex+bison parser is with a production like:
expr: { beginREGEXP(); } '/' regexp { endREGEXP(); } '/'
where beginREGEXP and endREGEXP are functions in the flex file that set
the start-state into and out of regexp mode. Note that the actions need
to be BEFORE the parser shifts the '/' token, as an LALR(1) parser may look
ahead one token. Which means that a '/' must be a '/' regardless of the
scanner state.
Note that if you allow additional lookahead in the parser (LR(k) or LR(*) or
any kind of backtracking) this will break badly.
Chris Dodd
cdodd@acm.org
Return to the
comp.compilers page.
Search the
comp.compilers archives again.