bison-patches
[Top][All Lists]
Advanced

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

Re: 10-exercise-parse-param.patch


From: Akim Demaille
Subject: Re: 10-exercise-parse-param.patch
Date: 21 Oct 2002 09:57:52 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

This patch demonstrates that %parse-param works correctly.  I also
have %lex-param work properly.

| +%parse-param "value_t *result", "result"
| +%parse-param "int *count",      "count"
| +
|  /* Exercise %union. */
|  %union
|  {
| @@ -120,12 +127,12 @@ m4_define([_AT_DATA_CALC_Y],
|  %%
|  input:
|    line
| -| input line
| +| input line         { ++*count; ++global_count; }
|  ;
|  
|  line:
|    '\n'
| -| exp '\n'
| +| exp '\n'           { *result = global_result = $1; }
|  ;
|  
|  exp:

| @@ -286,6 +293,8 @@ exp:
|  int
|  main (int argc, const char **argv)
|  {
| +  value_t result = 0;
| +  int count = 0;
|    yyin = NULL;
|  
|    if (argc == 2)
| @@ -302,7 +311,10 @@ exp:
|  #if YYDEBUG
|    yydebug = 1;
|  #endif
| -  yyparse ();
| +  yyparse (&result, &count);
| +  assert (global_result == result);
| +  assert (global_count  == count);
| +
|    return 0;
|  }

But I'm not sure how things should be implemented for the rest of the
routines...  Let's start with the yyerror problem: what should we pass
to it?  I would say all the %parse-param, but what about the
%lex-param?  And what if there are doubles?  Often I use yyerror from
my scanners for lexical errors, do we want to keep this possible?

Another possibility would be to cease the `yyerror' approach, and have
something like:

%error {
  location_print (@$);
  fprintf (stderr, "%s", yy_error_message);
  exit (1);
}

Something similar to %printer and %detructor.  This has another
benefit: I've always found quite painful that no default yyerror be
provided...

But of course, we have to keep POSIX compatibility, plus backward
compatibility under some form.




reply via email to

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