rtg2typematch
is a tool for generating a duck-typing-based strategies that check if an ATerm is of a type as defined in an RTG?. An example will make this more clear.
Let's take the RTG produced by the example in the manual page of sdf2rtg:
regular tree grammar start Exp productions Exp -> Minus(Exp,Exp) Exp -> Plus(Exp,Exp) Exp -> Mod(Exp,Exp) Exp -> Div(Exp,Exp) Exp -> Mul(Exp,Exp) Exp -> Int(IntConst) Exp -> Var(Id) IntConst -> <string> Id -> <string>
Apply rtg2typematch:
> rtg2typematch -i Exp.rtg -o Exp-typematch.str
will result in the module
module Exp-typematch strategies is-Exp = ?Minus(_, _) + ?Plus(_, _) + ?Mod(_, _) + ?Div(_, _) + ?Mul(_, _) + ?Int(_) + ?Var(_) is-IntConst = is-string is-Id = is-string
You can call is-Exp
to check whether a term is of sort Exp.
Notice that the generated code only looks at the name of the
constructor. If the same constructor can be used to produce
different sorts, the typematch strategy of all these sort will
accept a term that is an application of this constructor.