Format Checker

Stratego -- Strategies for Program Transformation
A format checker is a strategy that checks the well-formedness of an term. Format checkers can check more properties than can just be described using signatures. For example, checking that a term is normalized in a certain way.

Format checkers can be defined easily using RecursivePattern. Consider the following signature of a simple expression language:

  sorts Exp
    Var : String -> Exp
    Add : Exp * Exp -> Exp
    Mul : Exp * Exp -> Exp

The following format checking strategy Exp checks that a term is a well-formed Exp term.


  Exp = Var(is-string) + Add(Exp, Exp) + Mul(Exp, Exp)

It is also possible to check more strict properties such as being an additive expression (if that is a term), i.e., an expression consisting of additions on top and multiplications within. No addition should occur as a sub-term of a multiplication. The following strategy definition is a more concise way of expressing this property:

AdditiveExp = 
  rec a(Add(a, a) + rec m(Mul(m, m) + Var(is-string)))

Note that the use of the rec RecursionOperator makes the definition more concise (without it an additional strategy definition would be needed).

-- EelcoVisser - 28 Nov 2001

The tool format-check (available from StrategoXT 0.10) checks if an ATerm is part of the language defined by an abstract syntax definition in RTG.

-- MartinBravenboer - 29 Jun 2004