bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Java push parser


From: Akim Demaille
Subject: Re: Java push parser
Date: Mon, 21 Jan 2013 14:30:45 +0100

Le 15 janv. 2013 à 20:31, Dennis Heimbigner <address@hidden> a écrit :

> 3. push.texi - text to be inserted somewhere into the
>               bison documentation. It gives a brief
>               description on using the push features.

@node Java Push Parser Interface
@subsection Java Push Parser Interface

(The current push parsing interface is experimental and may evolve. More user 
feedback will help to stabilize it.)

Normally, Bison generates a pull parser for Java.
The following Bison declaration says that you want the parser to be a push
parser (@pxref{%define Summary,,api.push-pull}):

@example
%define api.push-pull push
@end example

Most of the discussion about the
Java pull Parser Interface,
(@pxref{Java Parser Interface})
applies to the push parser interface as well.

@deftypemethod {YYParser} {void} push_parse ({int} @var{token}, {Object} 
@var{yylval}, {Location} @var{yyloc})
@deftypemethodx {YYParser} {void} push_parse ({int} @var{token}, {Object} 
@var{yylval}, {Position} @var{yypos})
The primary difference with respect to 
a pull parser is that the parser method
@code{push_parse} is invoked repeatedly to parse each token.
This function is available if either the
"%define api.push-pull push" or "%define api.push-pull both"
declaration is used (@pxref{%define Summary,,api.push-pull}).
The @code{Location} and @code{Position} parameters are
available only if location tracking is active.

The value returned by the @code{push_parse} method
is one of the following four values:
@code{YYABORT}, @code{YYACCEPT}, @code{YYERROR}, or @code{YYMORE}.
This new value,
@code{YYMORE}, may be returned if more input is required to finish
parsing the grammar.
@end deftypemethod

If api.push-pull is declared as @code{both}, then the generated parser
class will also implement the @code{parse} method. This method's
body is a loop that repeatedly invokes the scanner and then
passes the values obtained from the scanner to the @code{push_parse}
method.

There is one additional complication.
Technically, the push parser does not need to know about the scanner
(i.e. an object implementing the @code{YYParser.Lexer} interface),
but it does need access to the @code{yyerror} method.
The current approach (and subject to change) is to require
the @code{YYParser} constructor to be given an object implementing
the @code{YYParser.Lexer} interface. This object need only
implement the @code{yyerror} method; the other methods can be stubbed
since they will never be invoked.
The simplest way to do this is to add code like this to your
.y file.

@example
%code lexer @{
public Object getLVal() {return null;}
public int yylex() {return 0;}
public void yyerror(String s) {System.err.println(s);}
@}
@end example




reply via email to

[Prev in Thread] Current Thread [Next in Thread]