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

"Kartik Agaram" <ak@akkartik.com>
Sat, 05 Mar 2022 16:55:48 -0800

          From comp.compilers

Related articles
How do you create a grammar for a multi-language language? costello@mitre.org (Roger L Costello) (2022-03-03)
Re: How do you create a grammar for a multi-language language? costello@mitre.org (Roger L Costello) (2022-03-05)
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)
[1 later articles]
| List of all articles for this month |

From: "Kartik Agaram" <ak@akkartik.com>
Newsgroups: comp.compilers
Date: Sat, 05 Mar 2022 16:55:48 -0800
Organization: Compilers Central
References: 22-03-004 22-03-006
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="68525"; mail-complaints-to="abuse@iecc.com"
Keywords: parse, design
Posted-Date: 05 Mar 2022 20:11:57 EST
In-Reply-To: 22-03-006

> I am working with a team to develop a new language and our current thinking is
> that the language will use the XPath language for navigating through documents
> and the CSS language for expressing sets of match/action pairs.


That feels like a much more tractable problem. Don't even think of it
as a multi-language language. It's a language you're designing (so you
have lots of room for maneuver) around XPath.


> This idea of multi-language languages is very common within the XML community.
> For example, the XSLT language uses (hosts) the XPath language. Here is an
> excerpt to illustrate:
>
> select="/Bookstore/Book[1]/Title"
>
> The expression /Bookstore/Book[1]/Title is an XPath expression, the other
> parts are XSLT. So, the format of the select statement is:
>
> select="XPath"
>
> See how XSLT hosts XPath? That is, one language (XSLT) is using another
> language (XPath).


Yeah, putting a second language inside the string literals of the
first is a very common approach. All the tooling for the outer
language can remain oblivious of the second. You don't even need to
design a new language, this approach works with any existing one, and
you can focus on implementing a library to process XPath.


If you do want to design another language, however, you can make things a lot nicer. For example:


- any URL is a valid literal in the Red programming language: https://github.com/red/docs/blob/master/en/datatypes.adoc
- the JSX extension of JavaScript used in the React framework permits component literals that look a lot like some sort of markup language: https://reactjs.org/docs/introducing-jsx.html


Kartik
http://akkartik.name/about



Post a followup to this message

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