Re: Basic Lexing Question

Kaz Kylheku <480-992-1380@kylheku.com>
Fri, 1 Jul 2022 04:44:08 -0000 (UTC)

          From comp.compilers

Related articles
Basic Lexing Question nobozo@gmail.com (Jon Forrest) (2022-06-29)
Re: Basic Lexing Question gah4@u.washington.edu (gah4) (2022-06-29)
Re: Basic Lexing Question klammerj@a1.net (Johann Klammer) (2022-06-30)
Re: Basic Lexing Question 480-992-1380@kylheku.com (Kaz Kylheku) (2022-07-01)
| List of all articles for this month |
From: Kaz Kylheku <480-992-1380@kylheku.com>
Newsgroups: comp.compilers
Date: Fri, 1 Jul 2022 04:44:08 -0000 (UTC)
Organization: A noiseless patient Spider
References: 22-06-086 22-06-087
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="43891"; mail-complaints-to="abuse@iecc.com"
Keywords: lex
Posted-Date: 01 Jul 2022 11:21:50 EDT

On 2022-06-29, gah4 <gah4@u.washington.edu> wrote:
> On Wednesday, June 29, 2022 at 2:02:08 PM UTC-7, nob...@gmail.com wrote:
>> The following line is from a makefile accepted by gmake:
>
>> onefile: $(AVAR)
>
>> I'm wondering what the ramification are of lexing what's on the right of the
>> colon as a single string and then breaking it apart later, as opposed to
>> returning a more detailed sequence of tokens, such as DOLLAR LPAREN NAME
>> RPAREN.
>
> I suspect that the question is more complicated than it looks.
>
> Well, first, you might look at the gmake manual, and especially here:
>
> https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors
>
> Often in interpreted languages, and also in languages that use a preprocessor,
> you have to consider that things might be parsed more than once.
>
> As well as I know it, in processing that line gmake searches the line for $,
> without (mostly) looking at the rest of the line. (Even more, I am not sure
> about string constants.) So variables are replaced, and then the line
> is executed. Except when it isn't.
>
> It seems that in variable assignment:
>
> bvar = $AVAR
>
> the variable isn't expanded yet, but $AVAR is the value of bvar.
> Then, later, when there is a $bvar, and $AVAR is substituted,
> and then the value of AVAR is substituted.


I believe that = versus := variables can all be handled at the semantic
level, after an abstract parse.


    bvar = $(AVAR)


is like a macro. When we call $(bvar), it must expand to $(AVAR), which
then expands to the current value of AVAR. That does not mean we have
to scan any tokens any more; bar can exist in a translated form.


Whereas


    bvar := $(AVAR)


can produce exactly the same representation for the right hand side,
but then evaluate it immediately and capture the resulting string into
bvar.


The one Gmake feature which, I suspect, *must* re-scan the code at
the character level is $(eval ...). Because, look what you can do:


    DOLLAR := $$
    LPAREN := (
    RPAREN := )


    CODE := $(DOLLAR)$(LPAREN)info CC is $(DOLLAR)$(LPAREN)CC$(RPAREN)$(RPAREN)


    $(eval $(CODE))


    .PHONY: all
    all:


Output:


      CC is cc


Other than eval, I don't suspect anything else requires rescanning;
and note that $(CODE) without eval will not rescan!


So this will not work without eval either:


      $(shell echo foo.o: foo.c)


but this will produce a dependency rule:


      $(eval $(shell echo foo.o: foo.c))


Make can be given a bona-fide "waterfall model of compiling" treatment. :)


Post a followup to this message

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