Re: Lexical feedback

Paul Long <plong@perf.com>
Fri, 6 Oct 1995 18:13:12 GMT

          From comp.compilers

Related articles
Lexical feedback plong@perf.com (Paul Long) (1995-09-22)
Re: Lexical feedback mnp@compass-da.com (Mitchell Perilstein) (1995-09-29)
Re: Lexical feedback plong@perf.com (Paul Long) (1995-10-06)
Lexical feedback 75066.3204@CompuServe.COM (Carl Barron) (1995-10-21)
Re: Lexical feedback rich@rdp.introl.com (Richard Pennington) (1995-10-22)
Re: Lexical feedback pardo@cs.washington.edu (1995-10-23)
Re: Lexical feedback vern@daffy.ee.lbl.gov (1995-10-25)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Paul Long <plong@perf.com>
Keywords: parse, yacc, lex, comment
Organization: Performance Computing Incorporated
References: 95-09-143 95-10-032
Date: Fri, 6 Oct 1995 18:13:12 GMT

Mitchell Perilstein <mnp@compass-da.com> wrote:
>What's wrong with the parser communicating its state to the lexer at the
>same time it asks the lexer for the next token?


Passing information through global variables is bug prone and inelegant.
I'd like to avoid unnecessary common coupling.


>I'm about to do exactly this for a C-like language that has its own
>macro processor. Some of the macros are only valid in certain contexts.
>If I pass a little context information to lex from the parser, all the
>macros can be handled by lex. Fortunately, this is a by-hand lex and
>parser; who knows how to teach lex and yacc this trick without globals?


Apparently no one. PCCTS (?) and BTYACC (back-tracking yacc) were suggested
to me as replacements for yacc. These would presumably obviated the need
for the parser to explicitly pass context to the lexer, but global
variables seem like the only way for yacc to pass context to lex. I suppose
there are worse things in life.


I don't know if this an option for you (sounds like it isn't because you
are probably doing macro processing in the lexer), but you might be able
to rewrite your grammar in order to delay processing that is based on
context until the parser, thus avoiding having to pass context
information to the lexer--the lexer does the same thing regardless of
context, and the parser handles the ambiguity semantically.


>[Don't forget that yacc can be reading a token ahead of where it's parsing.
>That makes lexical feedback more exciting. -John]


Whoopee! :-)


--
Paul Long 45:29:14N 122:48:09W
plong@perf.com http://www.teleport.com/~pciwww/
[As I recall, the original tech report on yacc over 20 years ago pretty much
said that languages that need lexical feedback are bad, so it doesn't give
them any support. It also made it fairly clear that he knew this was just
an excuse, feedback is hard. -John]
--


Post a followup to this message

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