13.2.1 An Introduction to the Grammar Definition Dialog


Grammar Definition dialog
Grammar Definition dialog

The figure Grammar Definition dialog shows the Grammar Definition dialog. In the title bar of the Grammar Definition dialog Ascolog Insight displays the currently loaded grammar definition file. Open the Help menu and select Info to learn more about the commands of the Grammar Definition dialog's menu. In the File menu you find useful commands for working with the grammar definition file. Table Grammar Definition dialog/File menu lists these commands.

Grammar Definition dialog/File menu
File menu Description
New

Creates a new grammar which treats log files as plain text, i.e. no headers are identified and each line is considered to be a log record. Therefore Ascolog Insight adds the sof and eof terminal symbols and for the header a nonterminal symbol which is empty.

Load Loads a grammar definition file (file extension: “.gdf”). A previously loaded grammar definition file will be closed and any changes that were not stored will be discarded.
Merge/File

Merges a grammar definition from a grammar definition file with the current terminal and nonterminal symbols.

Terminals:

If a terminal symbol with the same name exists in both grammars and if it has the same definition in both grammars this terminal symbol will only occur once in the merged grammar. If a terminal symbol with the same name exists in both grammars but the definitions are different both terminal symbols will be copied to the merged grammar. You will have to decide what definition you want to keep.

Nonterminals:

How nonterminal symbols with the same name are handled is defined in the Options menu by the option Nonterminals/Progressive Merge.

Merge/Top

This command is similar to Merge/File but one of the sources won't be a grammar definition file but the topmost grammar from the grammar stack. Use the Push and Pop commands of the File menu to manipulate the grammar stack.

Save & Apply Saves the current terminals and nonterminals to the grammar definition file displayed in the title bar and immediately applies this grammar.
Save As

Saves the current terminals and nonterminals to a grammar definition file. The Save Grammar Definition File dialog will be opened where you have to provide the location and the name for the grammar definition file.

Push

Stores the current grammar definition (terminals, nonterminals and production rules which are currently displayed in the dialog) to the grammar stack. You can put several grammar definitions to the grammar stack.

Pop Fetches the topmost grammar definition from the grammar stack and replaces the current grammar definition with this topmost grammar definition.
Exit Closes the Grammar Definition dialog without saving the grammar definition.

The commands of the Terminals menu are described in table Grammar Definition dialog/Options/Terminals menu.

Grammar Definition dialog/Options/Terminals menu
Options/Terminals menu Description
Lock

This option is also available as check box directly above the Terminals list. If you provide a text sample and press the Scan button Ascolog Insight will create the necessary terminal symbols. Terminal symbols that have already existed before the scan was triggered are kept when Lock is checked. Otherwise they are removed.

Include Predefined

When you provide a text sample and press the Scan button Ascolog Insight will create a grammar definition. If you tick this option it will consider the predefined terminals (e.g. for timestamps, alphanumeric character sequences, etc.), when creating the grammar. For most use cases enabling this option makes perfectly sense.

A reason for not enabling this option is that you want to use your own terminal definitions which are not compatible with the predefined terminal definitions.

Remove Unreferenced

Removes unreferenced terminals (displayed in light gray) from the Terminals list. Unreferenced terminals are terminals which do not occur in a production rule or macros which do not occur in a terminal definition.

Add Predefined Adds predefined terminals to the Terminals list. Predefined terminals are available for timestamps, spaces, paths, file names or alphanumeric character sequences.

The commands of the Nonterminals menu are described in table Grammar Definition dialog/Options/Nonterminals menu.

Grammar Definition dialog/Options/Nonterminals menu
Options/Nonterminals menu Description
Progressive Merge

Nonterminal symbols that exist in grammars which shall be merged will be combined using the logical OR (the OR is represented by “|”):

Merging HEADER ::=NONTERMINAL_1 and HEADER::=NONTERMINAL_2 will yield HEADER::=NONTERMINAL_1 | NONTERMINAL_2

Default Postfix Options When you provide a text sample and press the Scan button Ascolog Insight will usually create several nonterminal symbols. The names will start with “NT” which stands for NonTerminal. The following options define how Ascolog Insight will create postfixes to generate distinct names for the nonterminal symbols.
Default Postfix > Number An increasing number will be used for the end of the nonterminal's name, e.g. NT_1, NT_2, NT_3, etc.
Default Postfix > Hash A hash value will be used for the end of the nonterminal's name, e.g. NT_19A96BEA, NT_19A96BEB, etc.
Default Postfix > GUID

A GUID (Global Unique Identifier) will be used for the end of the nonterminal's name, e.g.

NT_F9CBB411-1DCB-4077-A535-EB6B221AE9EE,

NT_F9CBB411-1DCB-4077-A535-EB6B221AE9EE,

etc.

Remove Unreferenced

Remove unreferenced nonterminals (displayed in light gray) from the Nonterminals list.

Unreferenced nonterminals are nonterminals which do not occur in a production rule.

Terminal symbols, nonterminal symbols and production rules are case-sensitive.

On the right side of the Terminals and Nonterminals list (see Grammar Definition dialog) you can find the commands which allow you to modify these lists. The commands are described in table Manipulating grammar definitions.

Manipulating grammar definitions
Command Description
Add Adds a terminal or nonterminal symbol to the end of the list.
Insert Inserts a terminal or nonterminal symbol before the selected symbol.
Edit Starts the Edit dialog of the selected nonterminal or terminal symbol.
Clear Removes all terminals or nonterminals from the list.
Remove Removes the terminal or nonterminal that is selected from the list.
Arrow up Moves the selected terminal or nonterminal one position up in the list.
Arrow down Moves the selected terminal or nonterminal one position down in the list.

In the Status line of the Grammar definition dialog Ascolog Insight displays information about the status of the grammar and the text sample if provided. When everything is correct the text Valid is displayed, otherwise an error message is displayed. The most important messages with their description are displayed in table Most important grammar status messages.

Most important grammar status messages
Message Status
Valid The provided text sample is valid according to the grammar definition.
Incomplete – Nonterminal: <name of the first nonterminal symbol which is missing>

The provided parts of the text sample are correct but some parts are missing.

This message is also displayed when no text sample is provided.

Text mismatch <additional information> This message is displayed when the provided text sample does not match the grammar. Depending on the error additional information is displayed.
Invalid first-set A grammar is defined that is not of type LL(1).