Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #3104

Re: Basic Lexing Question

From gah4 <gah4@u.washington.edu>
Newsgroups comp.compilers
Subject Re: Basic Lexing Question
Date 2022-06-29 16:27 -0700
Organization Compilers Central
Message-ID <22-06-087@comp.compilers> (permalink)
References <22-06-086@comp.compilers>

Show all headers | View raw


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.

Even more, gmake has

cvar ::= $AVAR

where $AVAR is expanded.

I first thought about this for PHP, which is a preprocessor (meant for)
HTML.  The processor doesn't know about HTML at all, but looks for

    <?php

such that:

<?php
            echo "Hi, I'm a PHP script!";
        ?>

is processed by PHP, with the result sent out be the server for the
web browser to process.  I am not sure of the exact rules, so it might
be that it is processed differently in quoted strings, but I suspect not.

The gmake manual has the example, which they recommend not using:

foo = c
prog.o : prog.$(foo)
        $(foo)$(foo) -$(foo) prog.$(foo)

Note that the $(foo)$(foo) is replaced by cc to run the C compiler.

Some of the more interesting parsing examples come with TeX, which allows
one to change, while it is running, which characters are letters.  Letters
can be used in control-sequence name longer than one character.
(Note unlike many languages, not digits ... unless they are letters!)

TeX also has \expandafter, which allows for delaying expansion of something
until what follows it expanded.

In any case, when input is parsed more than once, often by parsers with
different rules, the exact order of processing is very important!

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Basic Lexing Question Jon Forrest <nobozo@gmail.com> - 2022-06-29 10:11 -0700
  Re: Basic Lexing Question gah4 <gah4@u.washington.edu> - 2022-06-29 16:27 -0700
    Re: Basic Lexing Question Kaz Kylheku <480-992-1380@kylheku.com> - 2022-07-01 04:44 +0000
  Re: Basic Lexing Question Johann Klammer <klammerj@a1.net> - 2022-06-30 02:38 +0200

csiph-web