Related articles |
---|
Parsing makefiles bart@cs.uoregon.edu (1991-11-01) |
Newsgroups: | comp.compilers |
From: | bart@cs.uoregon.edu (Bart Massey) |
Keywords: | yacc, lex, make |
Organization: | Department of Computer Science, University of Oregon |
References: | 91-10-122 |
Date: | Fri, 1 Nov 1991 06:22:27 GMT |
In article 91-10-122:
> Where can I find a "make" grammar?
> [ ... hard-to-yaccify
> distinction between lines that start with whitespace and lines that don't.]
Yeah, but you do this in the lexer.
BTW, the distinction is more brutal than that -- it's definitely "lines
that start with a tab and lines that don't." The following two scripts
(at least now, as I'm typing them) have very different effects when
executed by make
foo:
BAR=bletch; echo $$BAR
foo:
BAR=bletch; echo $$BAR
(For those upon whom the distinction may be lost :-) (probably by the news
transport system), the first has a tab before the B, the second has a
space followed by a tab.) This is obviously a total design botch, but it
happened long ago.
If the lexer returns the appropriate token for lines that begin with a tab
(probably with its value just some sort of string containing the command)
then the parser hardly cares...
The moderator writes:
> For the make stuff, I suppose that you could have the lexer return the
> command lines as TAB-token REST-OF-LINE-token and just glom everything
> together, but by the time you've done that, there's hardly anything left
> for the parser to do.
Unless you write a modal lexer, though, that's kind of hard to
do, and not really worth it. You just want an
EXECUTABLE-LINE-token, whose value (LEX yylval) is some kind of
structure like
{
int ignore_errors;
int execute_silently;
char *to-execute;
}
There's still a *bit* for the parser to do, but you're right
about YACC probably being overkill.
Bart Massey
bart@cs.uoregon.edu
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.