Chapter 19
Core Maude Grammar

This chapter describes the syntax of Maude using the following extended BNF notation: the symbols ‘(’ and ‘)’ are used as metaparentheses; the symbol ‘’ is used to separate alternatives; square bracket pairs, ‘[’ and ‘]’, enclose optional syntax; ‘*’ indicates zero or more repetitions of preceding unit; ‘+’ indicates one or more repetitions of preceding unit; and the string “x” denotes x literally. As an application of this notation, A(, A)* indicates a non-empty list of A’s separated by commas. Finally, %%% indicates comments in the syntactic description, as opposed to comments in the Maude code.

19.1 The grammar

MaudeTop ::=
    ( SystemCommand  Command  DebuggerCommand 
       Module  Theory  View )+

SystemCommand ::= in FileName  load FileName 
    quit  eof  popd  pwd 
    cd Directory  push Directory 
    ls [ LsFlag ] [ Directory ]

Command ::= select ModId . 
    parse [ in ModId : ] Term . 
    [ debug ] reduce [ in ModId : ] Term . 
    [ debug ] rewrite [ [ Nat ] ] [ in ModId : ] Term . 
    [ debug ] frewrite [ [ Nat [ , Nat ] ] ] [ in ModId :
        ] Term . 
    [ debug ] erewrite [ [ Nat [ , Nat ] ] ] [ in ModId : ]
        Term . 
    ( match  xmatch ) [ [ Nat ] ] [ in ModId : ]
        Term <=? Term [ such that Condition ] . 
    unify [ [ Nat ] ] [ in ModId : ]
        UnificationEquation  ( /\ UnificationEquation )* . 
    [ debug ] variant unify [ [ Nat ] ] [ in ModId : ]
        UnificationEquation  ( /\ UnificationEquation )* . 
    [ debug ] get [ irredundant ] variants [ [ Nat ] ] [ in ModId : ] Term . 
    search [ [ Nat ] ] [ in ModId : ]
        Term SearchType Term [ such that Condition ] . 
    [ debug ] continue Nat . 
    loop [ in ModId : ] Term . 
    ( TokenString ) 
    trace ( select  deselect  include  exclude )
        ( OpId  ( OpForm ) )+ . 
    print ( conceal  reveal ) ( OpId  ( OpForm ) )+ . 
    break ( select  deselect ) ( OpId  ( OpForm ) )+ . 
    show ShowItem [ ModId ] . 
    show view [ ViewId ] . 
    show modules . 
    show views . 
    show search graph . 
    show path [ labels ] Nat .
    do clear memo . 
    set SetOption ( on  off ) .

UnificationEquation ::= Term =? Term

ShowItem ::= module  all  sorts  ops  vars  mbs 
    eqs  rls  summary  kinds  profile

SetOption ::= show ShowOption 
    print PrintOption 
    trace [ TraceOption ] 
    break  verbose  profile 
    clear ( memo  rules  profile ) 
    protect ModId 
    extend ModId 
    include ModId

ShowOption ::= advise  stats  loop stats  timing 
    loop timing  breakdown  command  gc

PrintOption ::= mixfix  flat  with parentheses 
    with aliases  conceal  number  rat  color 
    format  graph  attribute  attribute newline

TraceOption ::= condition  whole  substitution  select 
    mbs  eqs  rls  rewrite  body

DebuggerCommand ::= resume .  abort .  step .  where .

Module ::= fmod ModId [ ParameterList ] is ModElt* endfm 
    mod ModId [ ParameterList ] is ModElt’* endfm

Theory ::= fth ModId is ModElt* endfth 
    th ModId is ModElt’* endth

View ::= view ViewId from ModExp to ModExp is
             ViewElt*
           endv

ParameterList ::= { ParameterDecl ( , ParameterDecl )* }

ParameterDecl ::= ParameterId :: ModExp

ModElt ::= including ModExp . 
    extending ModExp . 
    protecting ModExp . 
    sorts Sort+ . 
    subsorts Sort+ ( < Sort+ )+ . 
    op OpForm : Type* Arrow Type [ Attr ] . 
    ops ( OpId  ( OpForm ) )+ : Type* Arrow Type
           [ Attr ] . 
    vars VarId+ : Type . 
    Statement [ StatementAttr ] .

ViewElt ::= var varId+ : Type . 
    sort Sort to Sort . 
    label LabelId to LabelId . 
    op OpForm to OpForm .  
    op OpForm : Type* Arrow Type to OpForm . 
    op Term to Term .

ModExp ::= ModId 
    ( ModExp ) 
    ModExp + ModExp 
    ModExp * Renaming
    ModExp { ViewId ( , ViewId )* }

Renaming ::= ( RenamingItem ( , RenamingItem )* )

RenamingItem ::= sort Sort to Sort 
    label LabelId to LabelId 
    op OpForm ToPartRenamingItem 
    op OpForm : Type* Arrow Type ToPartRenamingItem

ToPartRenamingItem ::= to OpForm [ Attr ]

Arrow ::= ->  ~>

Type ::= Sort  Kind

Kind ::= [ Sort (, Sort )* ]

Sort ::= SortId  Sort { Sort ( , Sort )* }

ModElt’ ::= ModElt 
    Statement’ [ StatementAttr ] .

Statement  ::=  mb [ Label ] Term : Sort 
    cmb [ Label ] Term : Sort if Condition 
    eq [ Label ] Term = Term 
    ceq [ Label ] Term = Term if Condition

Statement’ ::= rl [ Label ] Term => Term 
    crl [ Label ] Term => Term if Condition’

Label ::= [ LabelId ] :

Condition ::= ConditionFragment ( /\ ConditionFragment )*

Condition’ ::= ConditionFragment’
                 ( /\ ConditionFragment’ )*

ConditionFragment ::= Term = Term  Term := Term
                         Term : Sort

ConditionFragment’ ::= ConditionFragment  Term => Term

Attr ::=
    [ ( assoc  comm 
        [ left  right ] id: Term 
        idem  iter  memo  ditto 
        config  obj  msg 
        metadata StringId
        strat ( Nat+ ) 
        poly ( Nat+ ) 
        frozen [ ( Nat+ ) ] 
        prec Nat 
        gather ( ( e  E  & )+ ) 
        format ( Token+ ) 
        special ( Hook+ ) )+ ]

StatementAttr ::=
    [ ( nonexec  otherwise  variant 
        metadata StringId 
        label LabelId  
        print PrintItem* )+ ]

PrintItem ::= StringId  VarId  VarAndSortId

Hook ::= id-hook Token [ ( TokenString ) ] 
    ( op-hook  term-hook ) ( TokenString )

FileName    %%% OS dependent
Directory   %%% OS dependent
LsFlag      %%% OS dependent

StringId    %%% characters enclosed in double quotes "..."
ModId       %%% simple identifier, by convention all capitals
ViewId      %%% simple identifier, by convention capitalized
ParameterId %%% simple identifier, by convention single capital
SortId      %%% simple identifier, by convention capitalized
VarId       %%% simple identifier, by convention capitalized
VarAndSortId %%% an identifier consisting of a variable name
                   followed by a colon followed by a sort name
OpId        %%% identifier possibly with underscores
OpForm ::= OpId  ( OpForm )  OpForm+
Nat         %%% a natural number
Term ::= Token  ( Term )  Term+
Token       %%% Any symbol other than ( or )
TokenString ::= Token  ( TokenString )  TokenString*
LabelId     %%% simple identifier

In parsing module expressions, instantiation has higher precedence than renaming, which in turn has higher precedence than summation.

19.2 Synonyms

sort = sorts
subsort = subsorts
var = vars

Command only synonyms:

advise = advisory = advisories
alias = aliases
attr = attribute
cmd = command
cond = condition
cont = continue
eqs = eq
erew = erewrite
flat = flattened
frew = frewrite
kinds = components
label = labels
mbs = mb
norm = normalize
paren = parens = parentheses
q = quit
rat = rational
red = reduce
rew = rewrite
rls  = rl = rule = rules
s.t. = such that
subst = substitution

Module only synonyms:

assoc = associative
ceq = cq
comm = commutative
config = configuration
ctor = constructor
ex = extending
id: = identity:
idem = idempotent
inc = including
iter = iterated
msg = message
obj = object
owise = otherwise
poly = polymorphic
prec = precedence
pr = protecting
strat = strategy

19.3 Lexical Issues

Tokens are sequences of printable ASCII characters delimited by white space, except that ‘(’, ‘)’, ‘[’, ‘]’, ‘{’, ‘}’, and ‘,’ are always considered as single character tokens, unless backquoted.

Single line comments are started by one of *** or ---, and ended by the end of line. Multiline comments are started by ***( and ended by ). Parentheses (whether backquoted or not) must balance within multiline comments.

String identifiers use C backslash conventions [80, Section A2.5.2].