Download slides - Formal Systems Laboratory

Transcript
19
Parsing
Mix-fix notation leads to an interesting problem, that of parsing. In
the modified PEANO-NAT* of Ex. 2, how do we parse x + y * z?
Maude has a command called parse, which parses a term using the
syntax of the most recently defined module. To see all the
parentheses, first type the command “set print with
parentheses on .” (see Subsection 17.5 in Maude’s manual).
“parse x + y * z .” reports ambiguous parsing. Use parentheses
to disambiguate parsing, such as “parse x + (y * z) .”. To give
priorities to certain operators in order to reduce the number of
parentheses, use precedence attribute when you declare operators:
op _+_ : Int Int -> Int [prec 33] .
op _*_ : Int Int -> Int [prec 31] .
The lower the precedence the stronger the binding!