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


Groups > comp.compilers > #2918

Re: How do you create a grammar for a multi-language language?

From gah4 <gah4@u.washington.edu>
Newsgroups comp.compilers
Subject Re: How do you create a grammar for a multi-language language?
Date 2022-03-06 16:50 -0800
Organization Compilers Central
Message-ID <22-03-013@comp.compilers> (permalink)
References <22-03-004@comp.compilers> <22-03-006@comp.compilers> <22-03-010@comp.compilers> <22-03-011@comp.compilers>

Show all headers | View raw


On Sunday, March 6, 2022 at 3:22:57 PM UTC-8, gah4 wrote:

(snip)

> I don't believe I ever tried preprocessor statements inside C string
> constants, but as far as I know, it works.
 (snip)

> [PHP effectively treats material between ?> and <?php as an instruction
> to print the material as if it were a quoted string.

I suppose it works that way.

> C says that the input is tokenized before it does the preprocessor
> phase, so it does not look inside quoted strings. The # and ##
> preprocessor operators allow some preprocessor time creation of quoted
> strings. -John]

It seems that the traditional C compiler, sometimes used with other
languages, such as Fortran, has different parsing and tokenizing rules.

gcc -E --traditional quote.c

will process files with a preprocessor statement inside quotes.

On the other hand, the result is likely not what was wanted,
at least not for C.  Among others, it puts out lines like:

# 6 "quote.c" 2

which then end up inside the string.

On the other hand, if you language uses ' for other than strings,
or for two uses, then it should work.

One of the stranger things that I have known for about 50 years,
is direct access I/O in IBM Fortran IV.  There are statements like:

      WRITE(1'N) X, Y, Z

where N is the record in the direct access file.  The compiler also
accepts string (Hollerith) constants with apostrophes.
(But not in direct access I/O statements.)

In any case, the --traditional C preprocessor is commonly used with Fortran,
where I suspect C tokenizing could cause problems.

Some C preprocessors, but not the current ISO C version, and it
seems not gcc -E --traditional, will substitute preprocessor symbols
inside quoted strings.

As the OP notes, mixed parsing can have surprising effects!

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


Thread

How do you create a grammar for a multi-language language? Roger L Costello <costello@mitre.org> - 2022-03-03 13:57 +0000
  Re: How do you create a grammar for a multi-language language? Roger L Costello <costello@mitre.org> - 2022-03-05 22:29 +0000
    Re: How do you create a grammar for a multi-language language? "Kartik Agaram" <ak@akkartik.com> - 2022-03-05 16:55 -0800
    RE: How do you create a grammar for a multi-language language? Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-03-06 15:37 +0200
      Re: How do you create a grammar for a multi-language language? gah4 <gah4@u.washington.edu> - 2022-03-06 14:36 -0800
        Re: How do you create a grammar for a multi-language language? gah4 <gah4@u.washington.edu> - 2022-03-06 16:50 -0800
      RE: How do you create a grammar for a multi-language language? Roger L Costello <costello@mitre.org> - 2022-03-06 23:32 +0000
  Re: How do you create a grammar for a multi-language language? gah4 <gah4@u.washington.edu> - 2022-03-05 21:10 -0800
    Re: How do you create a grammar for a multi-language language? "Robin Vowels" <robin51@dodo.com.au> - 2022-03-07 13:39 +1100
  Re: How do you create a grammar for a multi-language language? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-03-06 12:23 +0100
    Re: How do you create a grammar for a multi-language language? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-03-07 05:08 +0100
      Re: How do you create a grammar for a multi-language language? gah4 <gah4@u.washington.edu> - 2022-03-06 21:22 -0800
        Keywords and Reserved Words Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-03-08 21:46 +0200
          Re: Keywords and Reserved Words gah4 <gah4@u.washington.edu> - 2022-03-09 00:31 -0800
            Re: Keywords and Reserved Words "Robin Vowels" <robin51@dodo.com.au> - 2022-03-10 10:00 +1100
          Re: Keywords and Reserved Words "Robin Vowels" <robin51@dodo.com.au> - 2022-03-10 09:55 +1100
            Re: Keywords and Reserved Words in Fortran Thomas Koenig <tkoenig@netcologne.de> - 2022-03-10 07:07 +0000
          Re: Keywords and Reserved Words "Robin Vowels" <robin51@dodo.com.au> - 2022-03-10 11:59 +1100

csiph-web