Skip to content

Instantly share code, notes, and snippets.

@wilbowma
Forked from jrslepak/gist:5054161
Last active December 14, 2015 07:59
Show Gist options
  • Save wilbowma/5054403 to your computer and use it in GitHub Desktop.
Save wilbowma/5054403 to your computer and use it in GitHub Desktop.
A demonstration of a merging nonterminals in define-union-language
#lang racket
(provide LMerge)
(require redex/reduction-semantics
(only-in redex/private/matcher compiled-lang-lang))
(define-language LBase
(e (+ e e)
number))
(define-extended-language L1 LBase
(e ....
(- e e)))
(define-extended-language L2 LBase
(e ....
(* e e)))
;; Untagged merge of two languages that define the same nonterminal
(define-union-language LMerge L1 L2)
;; Tagged merge of two extended languages that define the same
;; nonterminal
(define-union-language LMerge2 (f. L1) (d. L2))
(redex-match? LBase e (term (+ 1 1)))
(redex-match? LMerge e (term (* 1 1)))
(redex-match? LMerge e (term (- 1 1)))
(redex-match? LMerge e (term (+ 1 1)))
(redex-match? LMerge e (term (^ 1 1)))
(compiled-lang-lang LMerge)
(compiled-lang-lang LMerge2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment