13.2.3 Nonterminals and Production Rules

In the Grammar Definition dialog there is also a list labeled Nonterminals. This list contains the nonterminal symbols and production rules of the grammar. The production rules define how to transform a single non-terminal symbol (Name column on the left) to one or more non-terminal or terminal symbols (Production column on the right).

The process of identifying the pieces of information of a log and building a data structure (parse tree) is called syntactic analysis or parsing. During parsing the correct syntax of the log is checked. The result of the syntactic analysis is a parse tree. The syntactic analysis is based on the grammar's production rules.

When you press the Clear button all nonterminal symbols will be removed. Pressing the Remove button only deletes the currently selected nonterminal symbol. Press the Arrow Up or Arrow Down button to move the selected nonterminal symbol one position up or down in the list.

When you press the Add, Insert or Edit button of the Nonterminals list the Layout Definition Nonterminal dialog shown in figure Layout Definition Nonterminal dialog will open. In the case you pressed the Edit button the dialog will display the current settings of the selected nonterminal symbol otherwise the fields will be blank.

Layout Definition Nonterminal dialog
Layout Definition Nonterminal dialog

In the Name field enter the name of the nonterminal symbol. In the Definitions field you must define the production rule which describes how to process the nonterminal symbol. If you tick the Optional check box the nonterminal symbol will be optional. Making a nonterminal symbol optional means appending the OR operator “|” and the empty terminal “epsilon”.

In production rules spaces are used to separate the terminal and nonterminal elements (like in figure Layout Definition Nonterminal dialog between alphanum and “|”). Spaces also improve the readability of a production rule for humans. If you actually want to use spaces in production rules that are part of the formal language and match spaces from the log file you must define a terminal of type separator that defines spaces and use this terminal in the production rule (see Notations used by the Grammar Definition dialog, space terminal symbol).

The Layout Definition Nonterminal dialog also has another useful feature which is called Update grammar dependencies. If this check box is ticked and you change the name of the nonterminal all occurrences of this nonterminal (e.g. in production rules) will also be changed to the new name.

Besides name and definition you must also set the type of the nonterminal symbol. The available types are described in table Nonterminal types.

Nonterminal types
Type Icon Description
Evaluate A tree graph symbol with a yellow root node and two red leaves nodes The information that is represented by this nonterminal is evaluated and will be displayed in its own column in the Log window.

A tree symbol with a white root node and two white leaf nodes

The information that is represented by this nonterminal is skipped and thus cannot be displayed in a column of the Log window.

The figure Notations used by the Grammar Definition dialog shows the use of nonterminals and production rules in the Grammar Definition dialog.

Notations used by the Grammar Definition dialog
Notations used by the Grammar Definition dialog

The application only allows grammars that are of type LL(1). When a LL(1) grammar is used the parser only needs to look at the next token to make a parsing decision (decide what production rule has to be applied). If a user creates a grammar in the grammar definition window which is not of type LL(1) an error message is displayed.

The production rules of example Invalid production rules in LL(1) are not allowed in LL(1) and create the error message “Invalid first-set”. The reason is that the parser has to look at the second token of the next two tokens to make a parsing decision because the first token must be alphanumeric in both cases:

NONTERMINAL_1 ::= NONTERMINAL_2 terminal_a | NONTERMINAL_2 terminal_b

NONTERMINAL_1 ::= alphanum

NONTERMINAL_2 ::= alphanum

Invalid production rules in LL(1)