/[bison]/bison/src/scan-gram.l
ViewVC logotype

Diff of /bison/src/scan-gram.l

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

revision 1.43 by eggert, Wed Nov 13 06:40:35 2002 UTC revision 1.44 by eggert, Wed Nov 27 18:34:14 2002 UTC
# Line 32  Line 32 
32  #include "gram.h"  #include "gram.h"
33  #include "reader.h"  #include "reader.h"
34    
 /* Each time we match a string, move the end cursor to its end. */  
35  #define YY_USER_INIT                            \  #define YY_USER_INIT                            \
36  do {                                            \  do {                                            \
37    LOCATION_RESET (*yylloc);                     \    LOCATION_RESET (*loc);                        \
38    yylloc->file = current_file;                  \    loc->file = current_file;                     \
    /* This is only to avoid GCC warnings. */    \  
   if (yycontrol) {;};                           \  
39  } while (0)  } while (0)
40    
41  #define YY_USER_ACTION  extend_location (yylloc, yytext, yyleng);  /* Each time we match a string, move the end cursor to its end. */
42  #define YY_STEP         LOCATION_STEP (*yylloc)  #define STEP  LOCATION_STEP (*loc)
43    
44    #define YY_USER_ACTION  extend_location (loc, yytext, yyleng);
45    
46  #define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))  #define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
47    
# Line 135  extend_location (location_t *loc, char c Line 134  extend_location (location_t *loc, char c
134     keep (to construct ID, STRINGS etc.).  Use the following macros to     keep (to construct ID, STRINGS etc.).  Use the following macros to
135     use it.     use it.
136    
137     Use YY_OBS_GROW to append what has just been matched, and     Use STRING_GROW to append what has just been matched, and
138     YY_OBS_FINISH to end the string (it puts the ending 0).     STRING_FINISH to end the string (it puts the ending 0).
139     YY_OBS_FINISH also stores this string in LAST_STRING, which can be     STRING_FINISH also stores this string in LAST_STRING, which can be
140     used, and which is used by YY_OBS_FREE to free the last string.  */     used, and which is used by STRING_FREE to free the last string.  */
141    
142  static struct obstack string_obstack;  static struct obstack string_obstack;
143    
# Line 146  static struct obstack string_obstack; Line 145  static struct obstack string_obstack;
145  static char *last_string;  static char *last_string;
146    
147    
148  #define YY_OBS_GROW   \  #define STRING_GROW   \
149    obstack_grow (&string_obstack, yytext, yyleng)    obstack_grow (&string_obstack, yytext, yyleng)
150    
151  #define YY_OBS_FINISH                                   \  #define STRING_FINISH                                   \
152    do {                                                  \    do {                                                  \
153      obstack_1grow (&string_obstack, '\0');              \      obstack_1grow (&string_obstack, '\0');              \
154      last_string = obstack_finish (&string_obstack);     \      last_string = obstack_finish (&string_obstack);     \
155    } while (0)    } while (0)
156    
157  #define YY_OBS_FREE \  #define STRING_FREE \
158    obstack_free (&string_obstack, last_string)    obstack_free (&string_obstack, last_string)
159    
160  void  void
161  scanner_last_string_free (void)  scanner_last_string_free (void)
162  {  {
163    YY_OBS_FREE;    STRING_FREE;
164  }  }
165    
166  /* Within well-formed rules, RULE_LENGTH is the number of values in  /* Within well-formed rules, RULE_LENGTH is the number of values in
# Line 210  splice  (\\[ \f\t\v]*\n)* Line 209  splice  (\\[ \f\t\v]*\n)*
209    
210    /* At each yylex invocation, mark the current position as the    /* At each yylex invocation, mark the current position as the
211       start of the next token.  */       start of the next token.  */
212    YY_STEP;    STEP;
213  %}  %}
214    
215    
# Line 255  splice  (\\[ \f\t\v]*\n)* Line 254  splice  (\\[ \f\t\v]*\n)*
254    "%yacc"                 return PERCENT_YACC;    "%yacc"                 return PERCENT_YACC;
255    
256    {directive}             {    {directive}             {
257      complain_at (*yylloc, _("invalid directive: %s"), quote (yytext));      complain_at (*loc, _("invalid directive: %s"), quote (yytext));
258      YY_STEP;      STEP;
259    }    }
260    
261    ^"#line "{int}" \"".*"\"\n" {    ^"#line "{int}" \"".*"\"\n" {
262      handle_syncline (yytext + sizeof "#line " - 1, yylloc);      handle_syncline (yytext + sizeof "#line " - 1, loc);
263      YY_STEP;      STEP;
264    }    }
265    
266    "="                     return EQUAL;    "="                     return EQUAL;
# Line 270  splice  (\\[ \f\t\v]*\n)* Line 269  splice  (\\[ \f\t\v]*\n)*
269    ","                     return COMMA;    ","                     return COMMA;
270    ";"                     return SEMICOLON;    ";"                     return SEMICOLON;
271    
272    [ \f\n\t\v]  YY_STEP;    [ \f\n\t\v]  STEP;
273    
274    {id}        {    {id}        {
275      yylval->symbol = symbol_get (yytext, *yylloc);      val->symbol = symbol_get (yytext, *loc);
276      rule_length++;      rule_length++;
277      return ID;      return ID;
278    }    }
# Line 284  splice  (\\[ \f\t\v]*\n)* Line 283  splice  (\\[ \f\t\v]*\n)*
283      num = strtoul (yytext, 0, 10);      num = strtoul (yytext, 0, 10);
284      if (INT_MAX < num || errno)      if (INT_MAX < num || errno)
285        {        {
286          complain_at (*yylloc, _("integer out of range: %s"), quote (yytext));          complain_at (*loc, _("integer out of range: %s"), quote (yytext));
287          num = INT_MAX;          num = INT_MAX;
288        }        }
289      yylval->integer = num;      val->integer = num;
290      return INT;      return INT;
291    }    }
292    
293    /* Characters.  We don't check there is only one.  */    /* Characters.  We don't check there is only one.  */
294    "'"         YY_OBS_GROW; BEGIN SC_ESCAPED_CHARACTER;    "'"         STRING_GROW; BEGIN SC_ESCAPED_CHARACTER;
295    
296    /* Strings. */    /* Strings. */
297    "\""        YY_OBS_GROW; BEGIN SC_ESCAPED_STRING;    "\""        STRING_GROW; BEGIN SC_ESCAPED_STRING;
298    
299    /* Comments. */    /* Comments. */
300    "/*"        BEGIN SC_YACC_COMMENT;    "/*"        BEGIN SC_YACC_COMMENT;
301    "//".*      YY_STEP;    "//".*      STEP;
302    
303    /* Prologue. */    /* Prologue. */
304    "%{"        BEGIN SC_PROLOGUE;    "%{"        BEGIN SC_PROLOGUE;
305    
306    /* Code in between braces.  */    /* Code in between braces.  */
307    "{"         YY_OBS_GROW; braces_level = 0; BEGIN SC_BRACED_CODE;    "{"         STRING_GROW; braces_level = 0; BEGIN SC_BRACED_CODE;
308    
309    /* A type. */    /* A type. */
310    "<"{tag}">" {    "<"{tag}">" {
311      obstack_grow (&string_obstack, yytext + 1, yyleng - 2);      obstack_grow (&string_obstack, yytext + 1, yyleng - 2);
312      YY_OBS_FINISH;      STRING_FINISH;
313      yylval->struniq = struniq_new (last_string);      val->struniq = struniq_new (last_string);
314      YY_OBS_FREE;      STRING_FREE;
315      return TYPE;      return TYPE;
316    }    }
317    
# Line 324  splice  (\\[ \f\t\v]*\n)* Line 323  splice  (\\[ \f\t\v]*\n)*
323    }    }
324    
325    . {    . {
326      complain_at (*yylloc, _("invalid character: %s"), quote (yytext));      complain_at (*loc, _("invalid character: %s"), quote (yytext));
327      YY_STEP;      STEP;
328    }    }
329  }  }
330    
# Line 337  splice  (\\[ \f\t\v]*\n)* Line 336  splice  (\\[ \f\t\v]*\n)*
336  <SC_YACC_COMMENT>  <SC_YACC_COMMENT>
337  {  {
338    "*/" {    "*/" {
339      YY_STEP;      STEP;
340      BEGIN INITIAL;      BEGIN INITIAL;
341    }    }
342    
343    .|\n     ;    .|\n     ;
344    <<EOF>>  unexpected_end_of_file (yylloc, "*/");    <<EOF>>  unexpected_end_of_file (loc, "*/");
345  }  }
346    
347    
# Line 352  splice  (\\[ \f\t\v]*\n)* Line 351  splice  (\\[ \f\t\v]*\n)*
351    
352  <SC_COMMENT>  <SC_COMMENT>
353  {  {
354    "*"{splice}"/"  YY_OBS_GROW; BEGIN c_context;    "*"{splice}"/"  STRING_GROW; BEGIN c_context;
355    <<EOF>>         unexpected_end_of_file (yylloc, "*/");    <<EOF>>         unexpected_end_of_file (loc, "*/");
356  }  }
357    
358    
# Line 363  splice  (\\[ \f\t\v]*\n)* Line 362  splice  (\\[ \f\t\v]*\n)*
362    
363  <SC_LINE_COMMENT>  <SC_LINE_COMMENT>
364  {  {
365    "\n"           YY_OBS_GROW; BEGIN c_context;    "\n"           STRING_GROW; BEGIN c_context;
366    {splice}       YY_OBS_GROW;    {splice}       STRING_GROW;
367    <<EOF>>        BEGIN c_context;    <<EOF>>        BEGIN c_context;
368  }  }
369    
# Line 377  splice  (\\[ \f\t\v]*\n)* Line 376  splice  (\\[ \f\t\v]*\n)*
376  <SC_ESCAPED_STRING>  <SC_ESCAPED_STRING>
377  {  {
378    "\"" {    "\"" {
379      YY_OBS_GROW;      STRING_GROW;
380      YY_OBS_FINISH;      STRING_FINISH;
381      yylval->string = last_string;      val->string = last_string;
382      rule_length++;      rule_length++;
383      BEGIN INITIAL;      BEGIN INITIAL;
384      return STRING;      return STRING;
385    }    }
386    
387    .|\n      YY_OBS_GROW;    .|\n      STRING_GROW;
388    <<EOF>>   unexpected_end_of_file (yylloc, "\"");    <<EOF>>   unexpected_end_of_file (loc, "\"");
389  }  }
390    
391    /*---------------------------------------------------------------.    /*---------------------------------------------------------------.
# Line 397  splice  (\\[ \f\t\v]*\n)* Line 396  splice  (\\[ \f\t\v]*\n)*
396  <SC_ESCAPED_CHARACTER>  <SC_ESCAPED_CHARACTER>
397  {  {
398    "'" {    "'" {
399      YY_OBS_GROW;      STRING_GROW;
400      YY_OBS_FINISH;      STRING_FINISH;
401      yylval->symbol = symbol_get (last_string, *yylloc);      val->symbol = symbol_get (last_string, *loc);
402      symbol_class_set (yylval->symbol, token_sym, *yylloc);      symbol_class_set (val->symbol, token_sym, *loc);
403      symbol_user_token_number_set (yylval->symbol,      symbol_user_token_number_set (val->symbol,
404                                    (unsigned char) last_string[1], *yylloc);                                    (unsigned char) last_string[1], *loc);
405      YY_OBS_FREE;      STRING_FREE;
406      rule_length++;      rule_length++;
407      BEGIN INITIAL;      BEGIN INITIAL;
408      return ID;      return ID;
409    }    }
410    
411    .|\n      YY_OBS_GROW;    .|\n      STRING_GROW;
412    <<EOF>>   unexpected_end_of_file (yylloc, "'");    <<EOF>>   unexpected_end_of_file (loc, "'");
413  }  }
414    
415    
# Line 424  splice  (\\[ \f\t\v]*\n)* Line 423  splice  (\\[ \f\t\v]*\n)*
423      unsigned long c = strtoul (yytext + 1, 0, 8);      unsigned long c = strtoul (yytext + 1, 0, 8);
424      if (UCHAR_MAX < c)      if (UCHAR_MAX < c)
425        {        {
426          complain_at (*yylloc, _("invalid escape sequence: %s"),          complain_at (*loc, _("invalid escape sequence: %s"),
427                       quote (yytext));                       quote (yytext));
428          YY_STEP;          STEP;
429        }        }
430      else      else
431        obstack_1grow (&string_obstack, c);        obstack_1grow (&string_obstack, c);
# Line 438  splice  (\\[ \f\t\v]*\n)* Line 437  splice  (\\[ \f\t\v]*\n)*
437      c = strtoul (yytext + 2, 0, 16);      c = strtoul (yytext + 2, 0, 16);
438      if (UCHAR_MAX < c || errno)      if (UCHAR_MAX < c || errno)
439        {        {
440          complain_at (*yylloc, _("invalid escape sequence: %s"),          complain_at (*loc, _("invalid escape sequence: %s"),
441                       quote (yytext));                       quote (yytext));
442          YY_STEP;          STEP;
443        }        }
444      else      else
445        obstack_1grow (&string_obstack, c);        obstack_1grow (&string_obstack, c);
# Line 461  splice  (\\[ \f\t\v]*\n)* Line 460  splice  (\\[ \f\t\v]*\n)*
460      int c = convert_ucn_to_byte (yytext);      int c = convert_ucn_to_byte (yytext);
461      if (c < 0)      if (c < 0)
462        {        {
463          complain_at (*yylloc, _("invalid escape sequence: %s"),          complain_at (*loc, _("invalid escape sequence: %s"),
464                       quote (yytext));                       quote (yytext));
465          YY_STEP;          STEP;
466        }        }
467      else      else
468        obstack_1grow (&string_obstack, c);        obstack_1grow (&string_obstack, c);
469    }    }
470    \\(.|\n)      {    \\(.|\n)      {
471      complain_at (*yylloc, _("unrecognized escape sequence: %s"),      complain_at (*loc, _("unrecognized escape sequence: %s"),
472                   quote (yytext));                   quote (yytext));
473      YY_OBS_GROW;      STRING_GROW;
474    }    }
475  }  }
476    
# Line 483  splice  (\\[ \f\t\v]*\n)* Line 482  splice  (\\[ \f\t\v]*\n)*
482    
483  <SC_CHARACTER>  <SC_CHARACTER>
484  {  {
485    "'"                   YY_OBS_GROW; BEGIN c_context;    "'"                   STRING_GROW; BEGIN c_context;
486    \\{splice}[^$@\[\]]   YY_OBS_GROW;    \\{splice}[^$@\[\]]   STRING_GROW;
487    <<EOF>>               unexpected_end_of_file (yylloc, "'");    <<EOF>>               unexpected_end_of_file (loc, "'");
488  }  }
489    
490    
# Line 496  splice  (\\[ \f\t\v]*\n)* Line 495  splice  (\\[ \f\t\v]*\n)*
495    
496  <SC_STRING>  <SC_STRING>
497  {  {
498    "\""                  YY_OBS_GROW; BEGIN c_context;    "\""                  STRING_GROW; BEGIN c_context;
499    \\{splice}[^$@\[\]]   YY_OBS_GROW;    \\{splice}[^$@\[\]]   STRING_GROW;
500    <<EOF>>               unexpected_end_of_file (yylloc, "\"");    <<EOF>>               unexpected_end_of_file (loc, "\"");
501  }  }
502    
503    
# Line 508  splice  (\\[ \f\t\v]*\n)* Line 507  splice  (\\[ \f\t\v]*\n)*
507    
508  <SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE>  <SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE>
509  {  {
510    "'"             YY_OBS_GROW; c_context = YY_START; BEGIN SC_CHARACTER;    "'"             STRING_GROW; c_context = YY_START; BEGIN SC_CHARACTER;
511    "\""            YY_OBS_GROW; c_context = YY_START; BEGIN SC_STRING;    "\""            STRING_GROW; c_context = YY_START; BEGIN SC_STRING;
512    "/"{splice}"*"  YY_OBS_GROW; c_context = YY_START; BEGIN SC_COMMENT;    "/"{splice}"*"  STRING_GROW; c_context = YY_START; BEGIN SC_COMMENT;
513    "/"{splice}"/"  YY_OBS_GROW; c_context = YY_START; BEGIN SC_LINE_COMMENT;    "/"{splice}"/"  STRING_GROW; c_context = YY_START; BEGIN SC_LINE_COMMENT;
514  }  }
515    
516    
# Line 522  splice  (\\[ \f\t\v]*\n)* Line 521  splice  (\\[ \f\t\v]*\n)*
521    
522  <SC_BRACED_CODE>  <SC_BRACED_CODE>
523  {  {
524    "{"|"<"{splice}"%"  YY_OBS_GROW; braces_level++;    "{"|"<"{splice}"%"  STRING_GROW; braces_level++;
525    "%"{splice}">"      YY_OBS_GROW; braces_level--;    "%"{splice}">"      STRING_GROW; braces_level--;
526    "}" {    "}" {
527      YY_OBS_GROW;      STRING_GROW;
528      braces_level--;      braces_level--;
529      if (braces_level < 0)      if (braces_level < 0)
530        {        {
531          YY_OBS_FINISH;          STRING_FINISH;
532          yylval->string = last_string;          val->string = last_string;
533          rule_length++;          rule_length++;
534          BEGIN INITIAL;          BEGIN INITIAL;
535          return BRACED_CODE;          return BRACED_CODE;
# Line 539  splice  (\\[ \f\t\v]*\n)* Line 538  splice  (\\[ \f\t\v]*\n)*
538    
539    /* Tokenize `<<%' correctly (as `<<' `%') rather than incorrrectly    /* Tokenize `<<%' correctly (as `<<' `%') rather than incorrrectly
540       (as `<' `<%').  */       (as `<' `<%').  */
541    "<"{splice}"<"  YY_OBS_GROW;    "<"{splice}"<"  STRING_GROW;
542    
543    "$"("<"{tag}">")?(-?[0-9]+|"$") { handle_dollar (current_braced_code,    "$"("<"{tag}">")?(-?[0-9]+|"$") { handle_dollar (current_braced_code,
544                                                     yytext, *yylloc); }                                                     yytext, *loc); }
545    "@"(-?[0-9]+|"$")               { handle_at (current_braced_code,    "@"(-?[0-9]+|"$")               { handle_at (current_braced_code,
546                                                 yytext, *yylloc); }                                                 yytext, *loc); }
547    
548    <<EOF>>  unexpected_end_of_file (yylloc, "}");    <<EOF>>  unexpected_end_of_file (loc, "}");
549  }  }
550    
551    
# Line 557  splice  (\\[ \f\t\v]*\n)* Line 556  splice  (\\[ \f\t\v]*\n)*
556  <SC_PROLOGUE>  <SC_PROLOGUE>
557  {  {
558    "%}" {    "%}" {
559      YY_OBS_FINISH;      STRING_FINISH;
560      yylval->string = last_string;      val->string = last_string;
561      BEGIN INITIAL;      BEGIN INITIAL;
562      return PROLOGUE;      return PROLOGUE;
563    }    }
564    
565    <<EOF>>  unexpected_end_of_file (yylloc, "%}");    <<EOF>>  unexpected_end_of_file (loc, "%}");
566  }  }
567    
568    
# Line 575  splice  (\\[ \f\t\v]*\n)* Line 574  splice  (\\[ \f\t\v]*\n)*
574  <SC_EPILOGUE>  <SC_EPILOGUE>
575  {  {
576    <<EOF>> {    <<EOF>> {
577      YY_OBS_FINISH;      STRING_FINISH;
578      yylval->string = last_string;      val->string = last_string;
579      BEGIN INITIAL;      BEGIN INITIAL;
580      return EPILOGUE;      return EPILOGUE;
581    }    }
# Line 594  splice  (\\[ \f\t\v]*\n)* Line 593  splice  (\\[ \f\t\v]*\n)*
593    \@    obstack_sgrow (&string_obstack, "@@");    \@    obstack_sgrow (&string_obstack, "@@");
594    \[    obstack_sgrow (&string_obstack, "@{");    \[    obstack_sgrow (&string_obstack, "@{");
595    \]    obstack_sgrow (&string_obstack, "@}");    \]    obstack_sgrow (&string_obstack, "@}");
596    .|\n  YY_OBS_GROW;    .|\n  STRING_GROW;
597  }  }
598    
599    

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.44

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