An ambiguous grammar allows some text to have more than one valid parse. Parsing matters when textual DSL content must be turned into a usable structure; the grammar defines which strings and arrangements count as valid. The supplied grammar describes the Rental record syntax but does not demonstrate a multiply parsed input or show an ambiguity-resolution strategy. section 15.1
The practical boundary of the treatment is:
- Textual DSL notation uses strings, with identifiers, quoted names, keywords, whitespace, attribute references, types, and values. section 15.1
- EBNF expresses the record-type structure through productions such as attribute, value, and recordType. section 15.1
- Ambiguity analysis and parser-conflict handling remain unspecified; the grammar is presented as a simpler, portable syntax. section 15.1
Listing 15.2 A grammar in EBNF that can parse listing 15.1
STRING: '"' [A-Za-z0-9 ]+ '"' ; #1
type: 'amount' | 'date range' | 'percentage' ; #2
WS: (' ' | '\t' | '\n')+ ; #3
attributeReference: '->' WS? STRING ;
number: [0-9]+ ('.' [0-9]+)? ;
value: attributeReference | number ;
attribute: STRING WS? ':' WS? type (WS 'initially' WS? value)? ;
recordType: WS? 'record type' WS? STRING WS?
'having attributes:' (WS? attribute)* WS? ;
Inspect the EBNF productions to see how textual Rental content is assigned a syntactic structure. section 15.1
