1. Basic Format
{User Declarations}
%
{Ml-YACC Declarations}
%
{Rules}
Similar to ml-Lex, {user Declarations}, user declarations are used to define custom values used in rules. We recommend that you shorten the code as much as possible.
The {ml-YACC Declarations} section is used for mandatory and optional declarations. For example, you must declare the Terminator, non-Terminator, and value types associated with them. You must define the name of the syntax analyzer and the type of the position value, which Terminator and non-terminator can be followed by the START symbol. Optional declarations include the priority of the Terminator, prohibiting the default protocol, and specifying whether the generated program contains lengthy descriptions in the. DESC file.
The {rules} part includes context-independent grammar and corresponding semantic behavior.
2. Necessary ml-YACC statement
% Name: syntax analyzer name
% Term: Terminator % nonterm: Non-Terminator
These two statements are similar to the datatype statement in ml. Do not use the ml keyword as the symbolic name.
% Term name1 [of ML-type]
| Name2 [of ML-type]
% Pos: indicates the type of the position value.
% POS<Ml-type>
3. optional declaration
% Arg: Declares the parameters passed in when the syntax analyzer is called.
% EOP: the end point after the start symbol. It must be declared in the term.
% Noshift: indicates a non-convertible symbol, that is, it cannot appear on the right of the rule.
%header (functor {parser name}LrValsFun(structure Token : TOKEN ...) )
% Left, % right, % nonassoc: Priority
% Start: Declaration start character
% Verbose: name of the description file
References: http://www.smlnj.org/doc/ML-Yacc/mlyacc002.html