Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: gah4 Newsgroups: comp.compilers Subject: Re: How do you create a grammar for a multi-language language? Date: Sun, 6 Mar 2022 21:22:17 -0800 (PST) Organization: Compilers Central Lines: 29 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <22-03-016@comp.compilers> References: <22-03-004@comp.compilers> <22-03-009@comp.compilers> <22-03-015@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="15313"; mail-complaints-to="abuse@iecc.com" Keywords: parse, design Posted-Date: 07 Mar 2022 13:04:25 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com In-Reply-To: <22-03-015@comp.compilers> Xref: csiph.com comp.compilers:2921 On Sunday, March 6, 2022 at 8:43:43 PM UTC-8, Hans-Peter Diettrich wrote: (snip) > 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 :-( It would be complicated for compiled languages. TeX allows one to change, character by character in the input, which characters are letters, and so used in a control sequence name. LaTeX macros, to allow for internal names that don't conflict with any user defined names, puts an @ sign in them, after changing @ to a letter. Then, just before going into user code, changes @ back to not a letter. (Specifically, it is other.) The lexer can't read too far ahead, as the character codes might change at any time. It is also interesting to see how languages without reserved words, keep track of which words have the keyword meaning, and which are ordinary names. [Back in the 1970s there were a bunch of extendible languages like EL/1 and IMP72 where you could add and change syntax on the fly. They all died since it meant that in practice no two programs were written in the same language and they were unreadable. Now we have overloading so you understand the syntax but you don't know what it means. -John]