Chapter 4:Syntax Analysis

Examples

. String of balanced parentheses

S ( S ) S | ε

. Grammar

list list + digit | list - digit | digit

digit 0 | 1 | . | 9 Consists of the language which is a list of digit separated by + or -.

S ( S ) S | ε

is the grammar for a string of balanced parentheses.

For example, consider the string: (( )( )). It can be derived as:

S (S)S ((S)S)S (( )S)S (( )(S)S)S (( )( )S)S (( )( ))S (( )( ))

Similarly,

list list + digit

| list - digit

| digit digit 0 | 1 | . | 9

is the grammar for a string of digits separated by + or -.