Lab 2: Disambiguation

Project
September 15, 2020

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.

Objectives

Extend the syntax definition that you developed in the previous lab with

  1. Disambiguation rules
  2. Layout constraints

Disambiguation Rules

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.

Layout Constraints

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.

References