[NEXT] [PREV]
HANDBOOK
/ GENTLE PRIMER
/ Describing Syntax
/Syntax Definitions 

Gentle
Applications Concepts Examples Handbook Support Download

Using this grammatical interpretation of rules we can write 'rule' Program : Declarationpart Statementpartwhich states that a Program is given by a Declarationpart and a Statementpart. We also need basic symbols of the language that are not defined by rules. These symbols are called terminal symbols or tokens and are written as strings denoting themselves. For example, 'rule' Statement : "IF" Expression "THEN" Statement "ELSE" StatementHere, "IF", "THEN", and "ELSE" are terminal symbols. Grammatical symbols such as Statement that are defined by rules are called nonterminal symbols. A grammar not only describes what is a valid text of a language, but also imposes a structure on the text. A grammar is given by a set of terminal symbols, a set of nonterminal symbols, and a set of rules. Rules have the form:
Given the rule for Statement and assuming that x>y is an expression and that x:=xy and y:=yx are statements, we can construct the more complex statement IF x>y THEN x:=xy ELSE y:=yxThe distinction between tokens and nonterminals reflects the fact that the analysis of the input text is generally decomposed into two (interleaved) steps: First the input is partitioned into tokens (lexical analysis), then the token stream is structured into hierarchical phrases (syntax analysis). Different techniques are used for each task. 