mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
examples: don't use yysyntax_error_arguments
Suggested by Adrian Vogelsgesang. https://lists.gnu.org/archive/html/bison-patches/2020-02/msg00069.html * data/skeletons/lalr1.java (Context.EMPTY, Context.getToken): New. (Context.yyntokens): Rename as... (Context.NTOKENS): this. Because (i) all the Java coding styles recommend upper case for constants, and (ii) the Java Skeleton exposes Lexer.EOF, not Lexer.YYEOF. * data/skeletons/yacc.c (yyparse_context_token): New. * examples/c/bistromathic/parse.y (yyreport_syntax_error): Don't use yysyntax_error_arguments. * examples/java/calc/Calc.y (yyreportSyntaxError): Likewise.
This commit is contained in:
@@ -108,15 +108,20 @@ class CalcLexer implements Calc.Lexer {
|
||||
|
||||
public void yyreportSyntaxError (Calc.Context ctx)
|
||||
{
|
||||
final int ARGMAX = 10;
|
||||
int[] arg = new int[ARGMAX];
|
||||
int n = ctx.yysyntaxErrorArguments (arg, ARGMAX);
|
||||
System.err.print (ctx.getLocation () + ": syntax error");
|
||||
for (int i = 1; i < n; ++i)
|
||||
System.err.print ((i == 1 ? ": expected " : " or ")
|
||||
+ ctx.yysymbolName (arg[i]));
|
||||
if (n != 0)
|
||||
System.err.print (" before " + ctx.yysymbolName (arg[0]));
|
||||
{
|
||||
final int TOKENMAX = 10;
|
||||
int[] arg = new int[TOKENMAX];
|
||||
int n = ctx.yyexpectedTokens (arg, TOKENMAX);
|
||||
for (int i = 0; i < n; ++i)
|
||||
System.err.print ((i == 0 ? ": expected " : " or ")
|
||||
+ ctx.yysymbolName (arg[i]));
|
||||
}
|
||||
{
|
||||
int lookahead = ctx.getToken ();
|
||||
if (lookahead != ctx.EMPTY)
|
||||
System.err.print (" before " + ctx.yysymbolName (lookahead));
|
||||
}
|
||||
System.err.println ("");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user