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

Hans-Peter Diettrich <DrDiettrich1@netscape.net>
Mon, 7 Mar 2022 05:08:33 +0100

          From comp.compilers

Related articles
[2 earlier articles]
Re: How do you create a grammar for a multi-language language? ak@akkartik.com (Kartik Agaram) (2022-03-05)
Re: How do you create a grammar for a multi-language language? gah4@u.washington.edu (gah4) (2022-03-05)
Re: How do you create a grammar for a multi-language language? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2022-03-06)
Re: How do you create a grammar for a multi-language language? gah4@u.washington.edu (gah4) (2022-03-06)
Re: How do you create a grammar for a multi-language language? gah4@u.washington.edu (gah4) (2022-03-06)
Re: How do you create a grammar for a multi-language language? robin51@dodo.com.au (Robin Vowels) (2022-03-07)
Re: How do you create a grammar for a multi-language language? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2022-03-07)
Re: How do you create a grammar for a multi-language language? gah4@u.washington.edu (gah4) (2022-03-06)
Keywords and Reserved Words christopher.f.clark@compiler-resources.com (Christopher F Clark) (2022-03-08)
Re: Keywords and Reserved Words gah4@u.washington.edu (gah4) (2022-03-09)
Re: Keywords and Reserved Words robin51@dodo.com.au (Robin Vowels) (2022-03-10)
Re: Keywords and Reserved Words robin51@dodo.com.au (Robin Vowels) (2022-03-10)
Re: Keywords and Reserved Words robin51@dodo.com.au (Robin Vowels) (2022-03-10)
[1 later articles]
| List of all articles for this month |

From: Hans-Peter Diettrich <DrDiettrich1@netscape.net>
Newsgroups: comp.compilers
Date: Mon, 7 Mar 2022 05:08:33 +0100
Organization: Compilers Central
References: 22-03-004 22-03-009
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="36239"; mail-complaints-to="abuse@iecc.com"
Keywords: parse
Posted-Date: 06 Mar 2022 23:43:40 EST
In-Reply-To: 22-03-009

On 3/6/22 12:23 PM, Hans-Peter Diettrich wrote:
> I don't think that was what he was asking about.


The question is too unspecific for me. A (traditional) grammar covers
the parser part, while the lexer is specified differently. Languages
based on the same lexer can be merged into one grammar, no problem so
far. But if the second language shall apply to a single token
(string...) of the primary language then both languages are independent
and can not share a single grammar. Like a document can contain parts of
several natural languages, where each language applies only to specific
parts of the documents and is subject to special lexer rules (RTL/LTR
reading...).


In C/C++ and its preprocessor we have a special construct where the
preprocessor tokens are refined/extended by the C/C++ lexer. And there
were discussions whether the preprocessor should look into string
literals (Siemens?), or whether the preprocessor can generate C comments
(Microsoft). A separate preprocessor run at least allows for the latter,
as the preprocessed source code is lexed again and can build tokens
differently from the tokens in the original source code.


My conclusion:
A single (formal) grammar can not contain multiple languages. Unless you
specify that e.g. statements and expressions in a programming language
shall be considered subject to different languages. Such nitpicking is
not worth further thoughts :-(


DoDi


Post a followup to this message

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