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


Groups > comp.compilers > #2165 > unrolled thread

Re: Best language for implementing compilers?

Started byMartin Ward <martin@gkc.org.uk>
First post2019-02-19 11:23 -0500
Last post2019-02-19 11:23 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.compilers

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#2165 — Re: Best language for implementing compilers?

FromMartin Ward <martin@gkc.org.uk>
Date2019-02-19 11:23 -0500
SubjectRe: Best language for implementing compilers?
Message-ID<19-02-013@comp.compilers>
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

[toc] | [standalone]


Back to top | Article view | comp.compilers


csiph-web