Re: Best language for implementing compilers?

Kaz Kylheku <157-073-9834@kylheku.com>
Tue, 12 Feb 2019 16:45:10 +0000 (UTC)

          From comp.compilers

Related articles
Best language for implementing compilers? costello@mitre.org (Costello, Roger L.) (2019-02-08)
Re: Best language for implementing compilers? nalaginrut@gmail.com (Nala Ginrut) (2019-02-09)
Re: Best language for implementing compilers? gneuner2@comcast.net (George Neuner) (2019-02-08)
Re: Best language for implementing compilers? robin51@dodo.com.au (Robin Vowels) (2019-02-09)
Re: Best language for implementing compilers? bc@freeuk.com (Bart) (2019-02-11)
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)
[16 later articles]
| List of all articles for this month |

From: Kaz Kylheku <157-073-9834@kylheku.com>
Newsgroups: comp.compilers
Date: Tue, 12 Feb 2019 16:45:10 +0000 (UTC)
Organization: Aioe.org NNTP Server
References: 19-02-002 19-02-004 19-02-006
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="35929"; mail-complaints-to="abuse@iecc.com"
Keywords: design, practice
Posted-Date: 12 Feb 2019 11:47:46 EST

On 2019-02-11, Bart <bc@freeuk.com> wrote:
> On 08/02/2019 23:36, George Neuner wrote:
>> On Fri, 8 Feb 2019 12:20:18 +0000, "Costello, Roger L."
>> <costello@mitre.org> wrote:
>>
>>> What is it about ML that makes it such a good language for implementing
>>> compilers?
>>
>> Compiling involves a lot of pattern matching, and pattern matching is
>> a native feature of ML.
>
> You mean for tokenising and parsing? That would be a small part of
> compilation (the easy bit, in my view), although it seems to be a
> preoccupation of this group.


I think George is talking about structural pattern matching:
expressing the handling of cases of various shapes of data using
a notation which resembles those shapes.


Opportunities for pattern-matching occur pretty much in any compiler
pass: various tree-to-tree transformations use pattern matching.
Target code generation, peephole optimizations and such can use it.


E.g. suppose we want to check whether we have an expression that is
the binary product of two binary sums, as in (* (+ a b) (+ c d)).


Without pattern matching:


  (when (and (eq (car expr) '*) ;; starts with *
                        (consp (cdr expr)) ;; has an argument
                        (consp (cddr expr)) ;; has another argument
                        (null (cdddr expr)) ;; then the list ends
                        (consp (cadr expr)) ;; first arg is a compound
                        (eq (cadr expr) '+) ;; ... starting with a +
                        ... ;; etc
      (do-whatever ...))


With very rudimentary pattern matching (simple destructuring):


  (destructuring-when (op1 (op2 a b) (op3 c d)) expr
      (when (equal (list op1 op2 op3) '(* + +))
          (do-whatever ...)))


With pattern matching:


  (when-match expr (* (+ ?a ?b) (+ ?c ?d))
      (do-whatever ...) ;; ?a ?b ... are in scope bound to subtrees
      ...)


Pattern matching can typically handle objects other than just lists.
Vectors, data structures, tuples, dictionaries ...


Some pattern matchers have support for arbitrary Boolean predicates,
like matching only when the third element of the list in foo.bar is an
even integer.


Post a followup to this message

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