§ 5.1.2 Grammatical Roles

As mentioned above, the grammar take advantage of the structure (however minimal) of the markup. Thus, the grammer is applied in layers, to sequences of tokens or atomic subexpressions (like a fractions or arrays). It is the role attribute that indicates the syntactic and/or presentational nature of each item. On the one hand, this drives the parsing: the grammar rules are keyed on the role (say, ADDOP), rather than content (say + or -), of the nodes [In some cases, the content is used to distinguish special synthesized roles]. The role is also used to drive the conversion to presentation markup, (say, as an infix operator), especially Presentation MathML. Some values of role are used only in the grammar, some are only used in presentation; most are used both ways.

The following grammatical roles are recognized by the math parser. These values can be specified in the role attribute during the initial document construction or by rewrite rules. Although the precedence of operators is loosely described in the following, since the grammar contains various special case productions, no rigidly ordered precedence is given. Also note that in the current design, an expresssion has only a single role, although that role may be involved in grammatical rules with distinct syntax and semantics (some roles directly reflect this ambiguity).

ATOM

a general atomic subexpression (atomic at the level of the expression; it may have internal structure);

ID

a variable-like token, whether scalar or otherwise, but not a function;

NUMBER

a number;

ARRAY

a structure with internal components and alignments; typically has a particular syntactic relationship to OPEN and CLOSE tokens.

UNKNOWN

an unknown expression. This is the default for token elements. Such tokens are treated essential as ID, but generate a warning if it seems to be used as a function.

OPEN,CLOSE

opening and closing delimiters, group expressions or enclose arguments among other structures;

MIDDLE

a middle operator used to group items between an OPEN, CLOSE pair;

PUNCT,PERIOD

punctuation; a period ‘ends’ formula (note that numbers, including floating point, are recognized earlier in processing);

VERTBAR

a vertical bar (single or doubled) which serves a confusing variety of notations: absolute values, “at”, divides;

RELOP

a relational operator, loosely binding;

ARROW

an arrow operator (with little semantic significance), but generally treated equivalently to RELOP;

METARELOP

an operator used for relations between relations, with lower precedence;

MODIFIER

an atomic expression following an object that ‘modifies’ it in some way, such as a restriction (<0) or modulus expression;

MODIFIEROP

an operator (such as mod) between two expressions such that the latter modifies the former;

ADDOP

an addition operator, between RELOP and MULOP operators in precedence;

MULOP

a multiplicative operator, high precedence than ADDOOP;

BINOP

a generic infix operator, can act as either an ADDOP or MULOP, typically used for cases wrapped in \mathbin;

SUPOP

An operator appearing in a superscript, such as a collection of primes, or perhaps a T for transpose. This is distinct from an expression in a superscript with an implied power or index operator;

PREFIX

for a prefix operator;

POSTFIX

for a postfix operator;

FUNCTION

a function which (may) apply to following arguments with higher precedence than addition and multiplication, or to parenthesized arguments (enclosed between OPEN,CLOSE);

OPFUNCTION

a variant of FUNCTION which doesn’t require fenced arguments;

TRIGFUNCTION

a variant of OPFUNCTION with special rules for recognizing which following tokens are arguments and which are not;

APPLYOP

an explicit infix application operator (high precedence);

COMPOSEOP

an infix operator that composes two FUNCTION’s (resulting in another FUNCTION);

OPERATOR

a general operator; higher precedence than function application. For example, for an operator A, and function F, AFx would be interpretted as (A(F))(x);

SUMOP,INTOP, LIMITOP,DIFFOP,BIGOP

a summation/union, integral, limiting, differential or general purpose operator. These are treated equivalently by the grammar, but are distinguished to facilitate (eventually) analyzing the argument structure (eg bound variables and differentials within an integral). Note are SUMOP and LIMITOP significantly different in this sense?

POSTSUBSCRIPT,POSTSUPERSCRIPT

intermediate form of sub- and superscript, roughly as  processes them. The script is (essentially) treated as an argument but the base will be determined by parsing.

FLOATINGSUBSCRIPT,FLOATINGSUPERSCRIPT

A special case for a sub- and superscript on an empty base, ie. {}^{x}. It is often used to place a pre-superscript or for non-math uses (eg. 10${}^{th});

The following roles are not used in the grammar, but are used to capture the presentation style; they are typically used directly in macros that construct structured objects, or used in representing the results of parsing an expression.

STACKED

corresponds to stacked structures, such as \atop, and the presentation of binomial coefficients.

SUPERSCRIPTOP,SUBSCRIPTOP

after parsing, the operator involved in various sub/superscript constructs above will be comverted to these;

OVERACCENT,UNDERACCENT

these are special cases of the above that indicate the 2nd operand acts as an accent (typically smaller), expressions using these roles are usually directly constructed for accenting macros;

FENCED

this operator is used to represent containers enclosed by OPEN and CLOSE, possibly with punctuation, particularly when no semantic is known for the construct, such as an arbitrary list.

The content of a token is actually used in a few special cases to distinguish distinct syntactic constructs, but these roles are not assigned to the role attribute of expressions:

LANGLE,RANGLE

recognizes use of < and > in the bra-ket notation used in quantum mechanics;

LBRACE,RBRACE

recognizes use of { and } on either side of stacked or array constructions representing various kinds of cases or choices;

SCRIPTOPEN

recognizes the use of { in opening specialized set notations.