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:

signature
  sorts Exp
  constructors
    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.

strategies

  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

Revision: r1.6 - 29 Jan 2005 - 14:45 - MartinBravenboer
Stratego > StrategoGlossary > FormatChecker
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback