/[bison]/bison/tests/calc.at
ViewVC logotype

Diff of /bison/tests/calc.at

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.35 by akim, Sun Oct 20 11:17:20 2002 UTC revision 1.36 by akim, Sun Oct 20 16:09:47 2002 UTC
# Line 53  AT_DATA([calc.y], Line 53  AT_DATA([calc.y],
53  char *strcat(char *dest, const char *src);  char *strcat(char *dest, const char *src);
54  #endif  #endif
55  #include <ctype.h>  #include <ctype.h>
56    #include <assert.h>
57    
58  extern void perror (const char *s);  extern void perror (const char *s);
59    
60  /* Exercise pre-prologue dependency to %union.  */  /* Exercise pre-prologue dependency to %union.  */
61  typedef int value_t;  typedef int value_t;
62    
63    value_t global_result = 0;
64    int global_count = 0;
65    
66  %}  %}
67    
68    %parse-param "value_t *result", "result"
69    %parse-param "int *count",      "count"
70    
71  /* Exercise %union. */  /* Exercise %union. */
72  %union  %union
73  {  {
# Line 120  static void yyungetc (LEX_PRE_FORMALS in Line 127  static void yyungetc (LEX_PRE_FORMALS in
127  %%  %%
128  input:  input:
129    line    line
130  | input line  | input line         { ++*count; ++global_count; }
131  ;  ;
132    
133  line:  line:
134    '\n'    '\n'
135  | exp '\n'  | exp '\n'           { *result = global_result = $1; }
136  ;  ;
137    
138  exp:  exp:
# Line 134  exp: Line 141  exp:
141    {    {
142       if ($1 != $3)       if ($1 != $3)
143         fprintf (stderr, "calc: error: %d != %d\n", $1, $3);         fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
144       $$ = $1 == $3;       $$ = $1;
145    }    }
146  | exp '+' exp        { $$ = $1 + $3;        }  | exp '+' exp        { $$ = $1 + $3;        }
147  | exp '-' exp        { $$ = $1 - $3;        }  | exp '-' exp        { $$ = $1 - $3;        }
# Line 286  power (int base, int exponent) Line 293  power (int base, int exponent)
293  int  int
294  main (int argc, const char **argv)  main (int argc, const char **argv)
295  {  {
296      value_t result = 0;
297      int count = 0;
298    yyin = NULL;    yyin = NULL;
299    
300    if (argc == 2)    if (argc == 2)
# Line 302  main (int argc, const char **argv) Line 311  main (int argc, const char **argv)
311  #if YYDEBUG  #if YYDEBUG
312    yydebug = 1;    yydebug = 1;
313  #endif  #endif
314    yyparse ();    yyparse (&result, &count);
315      assert (global_result == result);
316      assert (global_count  == count);
317    
318    return 0;    return 0;
319  }  }
320  ]])  ]])
# Line 435  _AT_CHECK_CALC([$1], Line 447  _AT_CHECK_CALC([$1],
447  1 - (2 - 3) = 2  1 - (2 - 3) = 2
448    
449  2^2^3 = 256  2^2^3 = 256
450  (2^2)^3 = 64], [486])  (2^2)^3 = 64],
451                   [486])
452    
453  # Some parse errors.  # Some parse errors.
454  _AT_CHECK_CALC_ERROR([$1], [0 0], [11],  _AT_CHECK_CALC_ERROR([$1], [0 0], [11],
# Line 463  _AT_CHECK_CALC_ERROR([$1], [(1 ++ 2) + ( Line 476  _AT_CHECK_CALC_ERROR([$1], [(1 ++ 2) + (
476  1.15-1.16: parse error, unexpected "number"  1.15-1.16: parse error, unexpected "number"
477  calc: error: 0 != 1])  calc: error: 0 != 1])
478    
 # Add a studid example demonstrating that Bison can further improve the  
 # error message.  FIXME: Fix this ridiculous message.  
 _AT_CHECK_CALC_ERROR([$1], [()], [21],  
 [1.2-1.3: parse error, unexpected ')', expecting "number" or '-' or '('])  
   
479  AT_CLEANUP  AT_CLEANUP
480  ])# AT_CHECK_CALC  ])# AT_CHECK_CALC
481    

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26