Google

"http://www.w3.org/TR/html4/loose.dtd"> >

Chapter 13
Parser

13.1 Interface with the lexer

The lexer produces a list of tokens (see 6.3). The parser save the number of the current token. Each time a token is matched (_eat method), the current token number is incremented. This counter does not appear in the generated code. It is handled by the _eat method.

13.2 Sequences of subexpressions

There is nothing particular about sequences (see 7.6). A sequence of expressions is translated into a sequence of Python statements (see 14.3.3).

13.3 Alternatives between subexpressions

Alternatives (see 7.8) are tried in the order of their declaration. The first match will stop the search. When a branch fails (i.e. a call to the _eat method raises a TPGWrongMatch exception) the alternative control structure catches the exception and tries the next branch. On the last branch the exception is not catched in order to be handled by an outer choice point (see 14.3.5).

13.4 Repetitions

Repetitions (see 7.9) use the same scheme as alternatives. The TPGWrongMatch exception stops the loop when raised (see 14.3.6).