# Theory Antiquote

Up to index of Isabelle/HOL/ex

theory Antiquote
imports Main
begin

    (*  Title:      HOL/ex/Antiquote.thy
        ID:         $Id: Antiquote.thy,v 1.7 2005/06/17 14:12:49 haftmann Exp $
        Author:     Markus Wenzel, TU Muenchen
    *)

    header {* Antiquotations *}

    theory Antiquote imports Main begin

    text {*
      A simple example on quote / antiquote in higher-order abstract
      syntax.
    *}

    syntax
      "_Expr" :: "'a => 'a"                         ("EXPR _" [1000] 999)

    constdefs
      var :: "'a => ('a => nat) => nat"             ("VAR _" [1000] 999)
      "var x env == env x"

      Expr :: "(('a => nat) => nat) => ('a => nat) => nat"
      "Expr exp env == exp env"

    parse_translation {* [Syntax.quote_antiquote_tr "_Expr" "var" "Expr"] *}
    print_translation {* [Syntax.quote_antiquote_tr' "_Expr" "var" "Expr"] *}

    term "EXPR (a + b + c)"
    term "EXPR (a + b + c + VAR x + VAR y + 1)"
    term "EXPR (VAR (f w) + VAR x)"

    term "Expr (λenv. env x)"                               (*improper*)
    term "Expr (λenv. f env)"
    term "Expr (λenv. f env + env x)"                       (*improper*)
    term "Expr (λenv. f env y z)"
    term "Expr (λenv. f env + g y env)"
    term "Expr (λenv. f env + g env y + h a env z)"

    end