XML grammar format |
StructureThe grammar declares the productions, which are used to generate greater aggregations of the tokens, like sentences in the natural language. In the first part of the grammar, you can specify the priorities of the terminals. Next to the priorities, you can specify the associativities of the terminals. And as the last part, the grammar must specified, which symbol should be the start symbol, which is similar to the root element of the generated XML document. <grammar> <priority> <terminal symbol="..."/> <terminal symbol="..."/> </priority> <associativity symbol="..." type="..."/> <associativity symbol="..." type="..."/> <production symbol="...">[definition of the production]</production> <production symbol="...">[definition of the production]</production> <production symbol="...">[definition of the production]</production> <start symbol="[Name of start symbol]"/> </grammar> PrioritiesThe section 'priority' defines the priority of the terminals. The terminals, which occurs first in this section, gets a higher priority as the following terminals. <priority> <terminal symbol="WORD"/> <terminal symbol="NUMBER"/> </priority> AssociativitiesBy using the 'associativity' element, you can declare, which asssociativity the terminal should get. <associativity symbol="WORD" type="left"/> <associativity symbol="NUMBER" type="right"/> <associativity symbol="PUNCTATION" type="nonassoc"/> ProductionsA Production arranges tokens in a structure. It is defined by a sequence of symbols <production symbol="Name of of the production"> <nonterminal symbol="symbol1"/><terminal symbol="symbol2"/><nonterminal symbol="symbol3"/> </production> Terminals refers to a terminal symbol of name specified by the symbol attribute. Similarly nonterminal refers to a nonterminal symbol. Here is an example which reads a line of words. <production symbol="line"> <nonterminal symbol="line"/><terminal symbol="WORD"/> </production> <production symbol="line"> <terminal symbol="word"/> </production> PrecedenceThe precedence of a production can be specified by the attribute 'precedence'. It is used to define precedences of the productions. This means that the production gets the same priority as a specified terminal. If you dont't specify the precedence, the production will get the priority of the last terminal of the definition <production symbol="line" precedence="WORD"> <nonterminal symbol="line"/><terminal symbol="WORD"/> </production> Error productionsError productions allow to control the level of error recovery. These productions use a special error symbol as placeholder, which can hold the text, which could not be parse by any other part of the grammar. <production symbol="line"> <error/><terminal symbol="CR"/> </production> |