Skip to content

Grammar

Luca Marceca edited this page Feb 12, 2024 · 2 revisions

Introduction

The input grammar format is an easy variation of EBNF. The BNF format used corresponds to the 4-tuple (V, A, P, S). V is a set of non-terminals (vocabulary), A is the alphabet, P the production rules and S the start symbol.

Basic principle
It is important that any further modifications to these formats have no influence on the following definitions in order to enforce down-/upward compatibility. Whenever Parssist expands its grammar (and this will often be the case) this rule will be strictly adhered to.

Explanation of the 4-tuple definition (V, A, P, S)

Vocabulary (V)

Non-terminals must begin with a capital letter to show that it is a non-terminal. As soon as it is to the left of the production, this implies the initialization of a non-terminal. As the application therefore automatically knows which symbols have been initialized as non-terminals, it is not necessary to explicitly specify a quantity. Possibly, however, later on in type-1 languages where terminals may also be on the left-hand side. At the moment all non-terminals have to be defined in the lexer file! There is no auto recognizer yet.

Alphabet (A)

The alphabet defines the terminal symbols. These are also defined in the lexer file.

Production rules (P)

The syntax of the production rules is defined as follows:

NONTERMINAL -> [TERMINAL | NONTERMINAL]

The square brackets indicate optional elements and are not part of the syntax. In order to learn the notation, the operators are now described in more detail.

Production Rule Arrow Operator

Production rules are therefore generally declared with an arrow (->). It does not matter how many spaces are defined before and after the symbol, but it is important that the arrow symbol is defined together as one symbol.

Empty Symbol Operator

The empty symbol, which is normally marked as an epsilon, is marked with a dollar sign ($).

Pipe Operator

In the example above you can see that production rules are not limited to just one definition rule. This is a modification that we use to avoid defining the syntax unnecessarily long. The pipe symbol (|) indicates the other rules.

Startsymbol (S)

At the moment, the first non-terminal definition symbol is automaticaly used as the start symbol.

Clone this wiki locally