LY_BEGIN(yacc, kyacc, parser, MyLangParse, Parser,y) A _IT(parser specification) is a file with the _TT(.y) suffix which specifies an LR(1) grammar (LR(1) includes LALR(1) grammars; see _LN(lr.html,LR(1) versus LALR(1))) for which a parser interface is to be generated. The specification is given as a list of BNF grammar rules . Unlike UNIX Yacc, each reduction rule is associated with a _IT(reduction method), which must be given a name. Each line of the file must have one of the following forms:
The set of valid grammar symbols consists of whatever tokens were declared in the _TI, plus whatever reduction method return types are declared as above.
The reduction method names have the form _TT(ruleName_returnType);
_EXT expects the methods to have these names. To avoid Modula-3 name
conflicts, parse types should not contain underscores.
_A(intf)_H(parser interface)
A _IT(parser interface) is a Modula-3 interface defining a type _TT(T)
representing a parser. Additionally the following types are declared:
_C(_TT(StartType <: MyLangTok.ParseType)
_TT(_TT(OtherType <: MyLangTok.ParseType)))
and all reduction method return types are declared as subtypes of either
_TT(StartType) or _TT(OtherType). Hence all _TT(ParseType)s of
importance (i.e. those appearing as parameters in reduction methods) are
either _TT(StartType)s, _TT(OtherType)s, or _TT(MyLangTok.Token)s.
In addition to the reduction methods, the parser type _TT(T) also generically contains the following:
METHODS setLex(lex: MyLangTok.Lexer): T; parse(exhaustInput: BOOLEAN := TRUE): StartType;A generated parser is initialized as often as necessary by calling its _TT(setLex) method, with a _LN(ktok.html#compat,compatible) lexer given as an argument. There is no method named _TT(init), to allow customized initialization parameters in extended lexers.
_A(exhaust) If _TT(parse) is called with _TT(exhaustInput = FALSE), then the parser will continue reading tokens until reading another token would cause a syntax error (this may or may not require peeking ahead one token. If peeking is required and the last token would cause an error, it calls _TT(lex.unget())). It returns the _TT(StartType) representing everything up to just before the error. This feature is useful for parsing a language block whose end is delimited by some token not meaningful in that language, such as an unmatched _TT('}'). _A(bib)_H(see also) S. C. Johnson, _IT(Yacc - Yet Another Compiler Compiler)
PL_END $Id: kyacc.html,v 1.2 2001-09-19 15:31:35 wagner Exp $ HTML_END