Download The Compiler Generator Coco/R

Transcript
28
be derived fairly simply from the simple Driver.frame, and some hints for doing so
can be found in section 10.7.2 of Compiling with C# and Java [Terry04].
3.5 Grammar Tests
Coco/R checks if the grammar in the compiler specification is well-formed. This
includes the following tests:
Completeness
For every nonterminal symbol there must be a production. If a nonterminal
not have a production Coco/R prints the message
X
does
No production for X
Lack of redundancy
If the grammar contains productions for a nonterminal X that does not occur in any
other productions derived from the start symbol Coco/R prints the message
X cannot be reached
Derivability
If the grammar contains nonterminals that cannot be derived into a sequence of
terminals, such as in
X = Y ';'.
Y = '(' X ')'.
Coco/R prints the messages
X cannot be derived to terminals
Y cannot be derived to terminals
Lack of circularity
If the grammar contains circular productions, i.e. if nonterminals can be derived
into themselves (directly or indirectly) such as in
A = [ a ] B.
B = ( C| b ).
C = A { c }.
Coco/R prints the messages
A --> B
B --> C
C --> A
Lack of ambiguity
If two or more tokens are declared so that they can have the same structure and thus
cannot be distinguished by the scanner, as in the following example, where the
input 123 could either be recognized as an integer or as a float:
TOKENS
integer = digit { digit }.
float
= digit { digit } [ '.' { digit } ].
Coco/R prints the message
Tokens integer and float cannot be distinguished
In all these cases the compiler specification is erroneous and no scanner and parser is
generated.