/[bison]/bison/src/parse-gram.y
ViewVC logotype

Diff of /bison/src/parse-gram.y

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

revision 1.35 by eggert, Wed Dec 11 06:40:51 2002 UTC revision 1.36 by eggert, Tue Dec 24 07:44:40 2002 UTC
# Line 58  static void gram_error (location const * Line 58  static void gram_error (location const *
58          print_token_value (File, Type, &Value)          print_token_value (File, Type, &Value)
59  static void print_token_value (FILE *, int, YYSTYPE const *);  static void print_token_value (FILE *, int, YYSTYPE const *);
60    
61  static void add_param (char const *, char const *, location);  static void add_param (char const *, char *, location);
62    
63  symbol_class current_class = unknown_sym;  symbol_class current_class = unknown_sym;
64  uniqstr current_type = 0;  uniqstr current_type = 0;
# Line 66  symbol *current_lhs; Line 66  symbol *current_lhs;
66  location current_lhs_location;  location current_lhs_location;
67  assoc current_assoc;  assoc current_assoc;
68  int current_prec = 0;  int current_prec = 0;
 braced_code current_braced_code = action_braced_code;  
69  %}  %}
70    
71    
# Line 90  braced_code current_braced_code = action Line 89  braced_code current_braced_code = action
89  %token PERCENT_NTERM       "%nterm"  %token PERCENT_NTERM       "%nterm"
90    
91  %token PERCENT_TYPE        "%type"  %token PERCENT_TYPE        "%type"
92  %token PERCENT_DESTRUCTOR  "%destructor"  %token PERCENT_DESTRUCTOR  "%destructor {...}"
93  %token PERCENT_PRINTER     "%printer"  %token PERCENT_PRINTER     "%printer {...}"
94    
95  %token PERCENT_UNION       "%union"  %token PERCENT_UNION       "%union {...}"
96    
97  %token PERCENT_LEFT        "%left"  %token PERCENT_LEFT        "%left"
98  %token PERCENT_RIGHT       "%right"  %token PERCENT_RIGHT       "%right"
# Line 116  braced_code current_braced_code = action Line 115  braced_code current_braced_code = action
115    PERCENT_EXPECT        "%expect"    PERCENT_EXPECT        "%expect"
116    PERCENT_FILE_PREFIX   "%file-prefix"    PERCENT_FILE_PREFIX   "%file-prefix"
117    PERCENT_GLR_PARSER    "%glr-parser"    PERCENT_GLR_PARSER    "%glr-parser"
118    PERCENT_LEX_PARAM     "%lex-param"    PERCENT_LEX_PARAM     "%lex-param {...}"
119    PERCENT_LOCATIONS     "%locations"    PERCENT_LOCATIONS     "%locations"
120    PERCENT_NAME_PREFIX   "%name-prefix"    PERCENT_NAME_PREFIX   "%name-prefix"
121    PERCENT_NO_LINES      "%no-lines"    PERCENT_NO_LINES      "%no-lines"
122    PERCENT_OUTPUT        "%output"    PERCENT_OUTPUT        "%output"
123    PERCENT_PARSE_PARAM   "%parse-param"    PERCENT_PARSE_PARAM   "%parse-param {...}"
124    PERCENT_PURE_PARSER   "%pure-parser"    PERCENT_PURE_PARSER   "%pure-parser"
125    PERCENT_SKELETON      "%skeleton"    PERCENT_SKELETON      "%skeleton"
126    PERCENT_START         "%start"    PERCENT_START         "%start"
# Line 143  braced_code current_braced_code = action Line 142  braced_code current_braced_code = action
142    
143    
144  %type <chars> STRING string_content  %type <chars> STRING string_content
145                BRACED_CODE code_content action                "%destructor {...}"
146                  "%lex-param {...}"
147                  "%parse-param {...}"
148                  "%printer {...}"
149                  "%union {...}"
150                  BRACED_CODE action
151                PROLOGUE EPILOGUE                PROLOGUE EPILOGUE
152  %type <uniqstr> TYPE  %type <uniqstr> TYPE
153  %type <integer> INT  %type <integer> INT
# Line 176  declaration: Line 180  declaration:
180  | "%expect" INT                            { expected_conflicts = $2; }  | "%expect" INT                            { expected_conflicts = $2; }
181  | "%file-prefix" "=" string_content        { spec_file_prefix = $3; }  | "%file-prefix" "=" string_content        { spec_file_prefix = $3; }
182  | "%glr-parser"                            { glr_parser = 1; }  | "%glr-parser"                            { glr_parser = 1; }
183  | "%lex-param" code_content                { add_param ("lex_param", $2, @2); }  | "%lex-param {...}"                       { add_param ("lex_param", $1, @1); }
184  | "%locations"                             { locations_flag = 1; }  | "%locations"                             { locations_flag = 1; }
185  | "%name-prefix" "=" string_content        { spec_name_prefix = $3; }  | "%name-prefix" "=" string_content        { spec_name_prefix = $3; }
186  | "%no-lines"                              { no_lines_flag = 1; }  | "%no-lines"                              { no_lines_flag = 1; }
187  | "%output" "=" string_content             { spec_outfile = $3; }  | "%output" "=" string_content             { spec_outfile = $3; }
188  | "%parse-param" code_content           { add_param ("parse_param", $2, @2); }  | "%parse-param {...}"                   { add_param ("parse_param", $1, @1); }
189  | "%pure-parser"                           { pure_parser = 1; }  | "%pure-parser"                           { pure_parser = 1; }
190  | "%skeleton" string_content               { skeleton = $2; }  | "%skeleton" string_content               { skeleton = $2; }
191  | "%token-table"                           { token_table_flag = 1; }  | "%token-table"                           { token_table_flag = 1; }
# Line 197  grammar_declaration: Line 201  grammar_declaration:
201      {      {
202        grammar_start_symbol_set ($2, @2);        grammar_start_symbol_set ($2, @2);
203      }      }
204  | "%union" BRACED_CODE  | "%union {...}"
205      {      {
206        typed = 1;        typed = 1;
207        MUSCLE_INSERT_INT ("stype_line", @2.start.line);        MUSCLE_INSERT_INT ("stype_line", @1.start.line);
208        muscle_insert ("stype", $2);        muscle_insert ("stype", $1);
209      }      }
210  | "%destructor"  | "%destructor {...}" symbols.1
     { current_braced_code = destructor_braced_code; }  
   BRACED_CODE symbols.1  
211      {      {
212        symbol_list *list;        symbol_list *list;
213        for (list = $4; list; list = list->next)        for (list = $2; list; list = list->next)
214          symbol_destructor_set (list->sym, $3, @3);          symbol_destructor_set (list->sym, $1, @1);
215        symbol_list_free ($4);        symbol_list_free ($2);
216        current_braced_code = action_braced_code;      }
217      }  | "%printer {...}" symbols.1
 | "%printer"  
     { current_braced_code = printer_braced_code; }  
   BRACED_CODE symbols.1  
218      {      {
219        symbol_list *list;        symbol_list *list;
220        for (list = $4; list; list = list->next)        for (list = $2; list; list = list->next)
221          symbol_printer_set (list->sym, $3, list->location);          symbol_printer_set (list->sym, $1, list->location);
222        symbol_list_free ($4);        symbol_list_free ($2);
       current_braced_code = action_braced_code;  
223      }      }
224  ;  ;
225    
# Line 394  string_content: Line 392  string_content:
392      };      };
393    
394    
 /* A BRACED_CODE used for its contents.  Strip the braces. */  
 code_content:  
   BRACED_CODE  
     {  
       $$ = $1 + 1;  
       $$[strlen ($$) - 1] = '\0';  
     };  
   
   
395  epilogue.opt:  epilogue.opt:
396    /* Nothing.  */    /* Nothing.  */
397  | "%%" EPILOGUE  | "%%" EPILOGUE
# Line 449  lloc_default (YYLTYPE const *rhs, int n) Line 438  lloc_default (YYLTYPE const *rhs, int n)
438     declaration DECL and location LOC.  */     declaration DECL and location LOC.  */
439    
440  static void  static void
441  add_param (char const *type, char const *decl, location loc)  add_param (char const *type, char *decl, location loc)
442  {  {
443    static char const alphanum[] =    static char const alphanum[] =
444      "0123456789"      "0123456789"
# Line 458  add_param (char const *type, char const Line 447  add_param (char const *type, char const
447      "_";      "_";
448    char const *alpha = alphanum + 10;    char const *alpha = alphanum + 10;
449    char const *name_start = NULL;    char const *name_start = NULL;
450    char const *p;    char *p;
451    
452    for (p = decl; *p; p++)    for (p = decl; *p; p++)
453      if ((p == decl || ! strchr (alphanum, p[-1])) && strchr (alpha, p[0]))      if ((p == decl || ! strchr (alphanum, p[-1])) && strchr (alpha, p[0]))
454        name_start = p;        name_start = p;
455    
456      /* Strip the surrounding '{' and '}'.  */
457      decl++;
458      p[-1] = '\0';
459    
460    if (! name_start)    if (! name_start)
461      complain_at (loc, _("missing identifier in parameter declaration"));      complain_at (loc, _("missing identifier in parameter declaration"));
462    else    else
# Line 486  add_param (char const *type, char const Line 479  add_param (char const *type, char const
479    scanner_last_string_free ();    scanner_last_string_free ();
480  }  }
481    
482  /*------------------------------------------------------------------.  /*----------------------------------------------------.
483  | When debugging the parser, display tokens' locations and values.  |  | When debugging the parser, display tokens' values.  |
484  `------------------------------------------------------------------*/  `----------------------------------------------------*/
485    
486  static void  static void
487  print_token_value (FILE *file, int type, YYSTYPE const *value)  print_token_value (FILE *file, int type, YYSTYPE const *value)
# Line 513  print_token_value (FILE *file, int type, Line 506  print_token_value (FILE *file, int type,
506        break;        break;
507    
508      case BRACED_CODE:      case BRACED_CODE:
509        case PERCENT_DESTRUCTOR:
510        case PERCENT_LEX_PARAM:
511        case PERCENT_PARSE_PARAM:
512        case PERCENT_PRINTER:
513        case PERCENT_UNION:
514      case PROLOGUE:      case PROLOGUE:
515      case EPILOGUE:      case EPILOGUE:
516        fprintf (file, " = {{ %s }}", value->chars);        fprintf (file, " = {{ %s }}", value->chars);
# Line 529  gram_error (location const *loc, char co Line 527  gram_error (location const *loc, char co
527  {  {
528    complain_at (*loc, "%s", msg);    complain_at (*loc, "%s", msg);
529  }  }
530    
531    char const *
532    token_name (int type)
533    {
534      return yytname[type];
535    }

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