# BNF for ParseCpsl.jj

## NON-TERMINALS

    //////////////
    // the grammar
    //////////////

MultiPhaseTransducer
MultiPhaseTransducer | ::= | ( <multiphase> <ident> )? ( ( SinglePhaseTransducer )+ | ( <phases> ( <path> )+ ) ) <EOF>

    // MultiPhaseTransducer

SinglePhaseTransducer
SinglePhaseTransducer | ::= | <phase> <ident> ( <input> ( <ident> )* )? ( <option> ( <ident> <assign> ( <ident> | <bool> ) )* )? ( ( Rule ) | MacroDef )*

    // SinglePhaseTransducer

Rule
Rule | ::= | <rule> <ident> ( <priority> <integer> )? LeftHandSide "-->" RightHandSide

    // Rule

MacroDef
MacroDef | ::= | <macro> <ident> ( PatternElement | Action )

    // MacroDef

LeftHandSide
LeftHandSide | ::= | ConstraintGroup

    // LeftHandSide

    // we pass the lhs down so we can add bindings in CPEs, and the cg
    // so we can add PEs and create disjunctions here

ConstraintGroup
ConstraintGroup | ::= | ( PatternElement )+ ( <bar> ( PatternElement )+ )*

    // ConstraintGroup

PatternElement
PatternElement | ::= | ( <ident> | BasicPatternElement | ComplexPatternElement )

    // PatternElement

BasicPatternElement
BasicPatternElement | ::= | ( ( <leftBrace> Constraint ( <comma> Constraint )* <rightBrace> ) | ( <string> ) )

    // BasicPatternElement

ComplexPatternElement
ComplexPatternElement | ::= | <leftBracket> ConstraintGroup <rightBracket> ( <kleeneOp> )? ( <colon> ( <ident> | <integer> ) )?

    // ComplexPatternElement

Constraint
Constraint | ::= | ( <pling> )? <ident> ( <period> <ident> <equals> AttrVal )?

    // Constraint

    // attribute values: strings, identifers (=strings), integers, floats,
    //                   booleans

AttrVal
AttrVal | ::= | ( <string> | <ident> | <integer> | <floatingPoint> | <bool> )

RightHandSide
RightHandSide | ::= | Action ( <comma> Action )*

    // RightHandSide

    // actions return 2 strings, one for the name of the block, and
    // one for the block itself. if the name is null, it is an anonymous block

Action
Action | ::= | ( NamedJavaBlock | AnonymousJavaBlock | AssignmentExpression | <ident> )

    // Action

NamedJavaBlock
NamedJavaBlock | ::= | <colon> <ident> <leftBrace> ConsumeBlock

    // NamedJavaBlock

AnonymousJavaBlock
AnonymousJavaBlock | ::= | <leftBrace> ConsumeBlock

    // AnonymousJavaBlock

AssignmentExpression
AssignmentExpression | ::= | ( <colon> | <colonplus> ) <ident> <period> <ident> <assign> <leftBrace> ( <ident> <assign> ( AttrVal | ( <colon> <ident> <period> <ident> <period> <ident> ) ) ( <comma> )? )* <rightBrace>

    // AssignmentExpression

ConsumeBlock
ConsumeBlock | ::= | java code