In this lab you extend the syntax definition of the previous lab with disambiguation rules and layout constraints in order to ensure that the syntax definition is unambiguous.
Extend the syntax definition that you developed in the previous lab with
Section 4.1 of the ChocoPy reference manual specifies the precedence and associativity rules of the language. Translate this into associativity and priority rules in SDF3.
You need disambiguation constructs to disambiguate your syntax definition.
You can specify the associativity with attributes left
, right
, or non-assoc
(See documentation).
These attributes are added to the end of a rule:
context-free syntax
Exp.Constr1 = ... {left}
You can specify precedence in a context-free priorities
section.
In this section, you order groups of rules:
context-free priorities
{
Exp.Constr1
Exp.Constr2
} > { ... } > ...
You can also define the associativity of a group:
context-free priorities
{ left:
Exp.Constr1
Exp.Constr2
} > { ... } > ...
Finally you should also consider specifying a bracket
rule for disambiguation of expressions.
The syntax of ChocoPy is layout-sensitive.
That means that indentation and newlines are significant.
In the ChocoPy grammar in Figure 3 in the reference manual this is defined using NEWLINE
, INDENT
, and DEDENT
tokens.
Section 3.1 describes the meaning of these tokens.
Translate these tokens into layout constraints and layout declarations as presented in Lecture 3 and in the papers cited below.