Re: Best language for implementing compilers?

Martin Ward <martin@gkc.org.uk>
Tue, 19 Feb 2019 11:23:12 -0500 (EST)

          From comp.compilers

Related articles
[5 earlier articles]
Best language for implementing compilers? davidlovemore@gmail.com (David Lovemore) (2019-02-12)
Re: Best language for implementing compilers? drb@ihatespam.msu.edu (2019-02-12)
Re: Best language for implementing compilers? 157-073-9834@kylheku.com (Kaz Kylheku) (2019-02-12)
Re: Best language for implementing compilers? costello@mitre.org (Costello, Roger L.) (2019-02-12)
Re: Best language for implementing compilers? 157-073-9834@kylheku.com (Kaz Kylheku) (2019-02-12)
Re: Best language for implementing compilers? drb@ihatespam.msu.edu (2019-02-19)
Re: Best language for implementing compilers? martin@gkc.org.uk (Martin Ward) (2019-02-19)
Re: Best language for implementing compilers? arnold@skeeve.com (2019-02-20)
Re: Best language for implementing compilers? mertesthomas@gmail.com (2019-03-09)
Re: Best language for implementing compilers? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2019-03-09)
Re: Best language for implementing compilers? bc@freeuk.com (Bart) (2019-03-09)
Re: Best language for implementing compilers? gneuner2@comcast.net (George Neuner) (2019-03-09)
Re: Best language for implementing compilers? gneuner2@comcast.net (George Neuner) (2019-03-09)
[12 later articles]
| List of all articles for this month |
From: Martin Ward <martin@gkc.org.uk>
Newsgroups: comp.compilers
Date: Tue, 19 Feb 2019 11:23:12 -0500 (EST)
Organization: Compilers Central
References: <02fa4eb9-584c-3472-8a31-6d2cec140863@gkc.org.uk>
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="23367"; mail-complaints-to="abuse@iecc.com"
Keywords: tools
Posted-Date: 19 Feb 2019 11:23:12 EST
In-Reply-To: <02fa4eb9-584c-3472-8a31-6d2cec140863@gkc.org.uk>

On 12/02/19 17:27, Costello, Roger L. wrote:
> Are there programming languages that have the pattern matching capability
> shown in Kaz's last example?


MetaWSL is a domain-specific language designed for implementing
program transformations. Pattern matching is built into
the language: to test if the currently selected item
is an expression that is the binary product of two binary sums
we can use an IFMATCH:


IFMATCH Expression (~?a + ~?b) * (~?c + ~?d)
      THEN ... here a, b, c, and d are local variables
      ELSE ... the match failed ENDMATCH


The pattern matching includes variable interpolation
and back references, for example to match an IF statement
whose ELSE body is the same as the THEN body:


IFMATCH Statement IF ~?B THEN ~*S ELSE ~*=S FI
THEN ... ELSE ... ENDMATCH


The FILL construct builds a new item from the given components.
A program transformation to reverse the branches of an IF statement
is as simple as:


IFMATCH Statement IF ~?B THEN ~*S1 ELSE ~*S2 FI
      THEN @Paste_Over(FILL Statement
                                            IF ~=(@Not(B)) THEN ~*S2 ELSE ~*S1 FI
                                        ENDFILL) ENDMATCH


The function @Not takes a condition and returns a simplified
version of the negation of the condition. So we negate
the condition and interpolate the result into the IF statement
that we are constructing. This is then "pasted over"
the currently selected statement.


The FermaT program transformation system is largely implemented
in MetaWSL. The system and a graphical front end (called fme)
can be downloaded from here:


http://www.gkc.org.uk/fermat.html


(Disclaimer: I implemented most of FermaT and currently maintain it).


--
Martin


Dr Martin Ward | Email: martin@gkc.org.uk | http://www.gkc.org.uk
G.K.Chesterton site: http://www.gkc.org.uk/gkc | Erdos number: 4


Post a followup to this message

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