[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
12.4 The regular grammar
In order to work properly, the regular grammar used with an Lalr(1) grammar should follow some conventions:
- If a semantic value is to be associated with the token just
parsed, the regular grammar should return a pair whose
car
is the token name (a symbol) and thecdr
is the semantic value. - If there is no value associated with the token, the regular
grammar can return just the token name. When used in conjunction with
an Lalr grammar, regular grammar should never return
#f
as a token value. This is specially true when the regular grammar detects the end of parsing. In that case, the regular grammar must not return the#f
value. A good way to handle end-of-file is illustrated in the following example:(let ((g (regular-grammar () ... (else (let ((c (the-failure))) (if (eof-object? c) c (error 'rgc "Illegal character" c)))))) (l (lalr-grammar ...))) (read/lalrp l g (current-input-port)))
This way, the Lalr grammar will automatically handles the end-of-file.
This document was generated on March 31, 2014 using texi2html 5.0.