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


Groups > comp.compilers > #2165

Re: Best language for implementing compilers?

From Martin Ward <martin@gkc.org.uk>
Newsgroups comp.compilers
Subject Re: Best language for implementing compilers?
Date 2019-02-19 11:23 -0500
Organization Compilers Central
Message-ID <19-02-013@comp.compilers> (permalink)
References <02fa4eb9-584c-3472-8a31-6d2cec140863@gkc.org.uk>

Show all headers | View raw


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

Back to comp.compilers | Previous | Next | Find similar | Unroll thread


Thread

Re: Best language for implementing compilers? Martin Ward <martin@gkc.org.uk> - 2019-02-19 11:23 -0500

csiph-web