Beaver defines a simple interface that it expect scanners will follow in order to feed it with tokens. A compliant scanner extends beaver.core.Scanner
class end behaves according to the "contract" defined by that base class:
nextToken
method.nextToken
, so in the end at
least end-of-file token should be returned.Most scanner generators are flexible enough to be able to fulfill this contract. For example, this is how JFlex specification may define a Beaver compliant scanner:
import beaver.Symbol; import beaver.Scanner; import example.ExampleParser.Terminals; %% %class LanguageScanner %extends Scanner %function nextToken %type Symbol %yylexthrow Scanner.Exception %eofval{ return new Symbol(Terminals.EOF, "end-of-file"); %eofval} // ... %%