/[bison]/bison/src/reader.c
ViewVC logotype

Diff of /bison/src/reader.c

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

revision 1.171 by akim, Thu May 2 14:33:48 2002 UTC revision 1.172 by akim, Thu May 2 15:06:46 2002 UTC
# Line 45  typedef struct symbol_list Line 45  typedef struct symbol_list
45    const char *action;    const char *action;
46    int action_line;    int action_line;
47    
   /* The guard is attached to the LHS of a rule. */  
   const char *guard;  
   int guard_line;  
48    symbol_t *ruleprec;    symbol_t *ruleprec;
49  } symbol_list;  } symbol_list;
50    
# Line 80  symbol_list_new (symbol_t *sym) Line 77  symbol_list_new (symbol_t *sym)
77    res->line = lineno;    res->line = lineno;
78    res->action = NULL;    res->action = NULL;
79    res->action_line = 0;    res->action_line = 0;
   res->guard = NULL;  
   res->guard_line = 0;  
80    res->ruleprec = NULL;    res->ruleprec = NULL;
81    return res;    return res;
82  }  }
# Line 1273  read_declarations (void) Line 1268  read_declarations (void)
1268  | values in the current rule so far, which says where to find `$0'  |  | values in the current rule so far, which says where to find `$0'  |
1269  | with respect to the top of the stack.                             |  | with respect to the top of the stack.                             |
1270  |                                                                   |  |                                                                   |
1271  | This routine is used both for actions and guards.  Only           |  | This routine is used for actions.                                 |
 | ACTION_OBSTACK is used, but this is fine, since we use only       |  
 | pointers to relevant portions inside this obstack.                |  
1272  `------------------------------------------------------------------*/  `------------------------------------------------------------------*/
1273    
1274  static void  static void
# Line 1341  parse_action (symbol_list *rule, int rul Line 1334  parse_action (symbol_list *rule, int rul
1334    rule->action = obstack_finish (&action_obstack);    rule->action = obstack_finish (&action_obstack);
1335  }  }
1336    
   
 static void  
 parse_guard (symbol_list *rule, int rule_length)  
 {  
   token_t t = lex ();  
   if (t != tok_left_curly)  
     complain (_("invalid %s declaration"), "%guard");  
   rule->guard_line = lineno;  
   parse_braces (rule, rule_length);  
   rule->guard = obstack_finish (&action_obstack);  
 }  
   
1337    
1338    
1339  /*-------------------------------------------------------------------.  /*-------------------------------------------------------------------.
# Line 1384  gensym (void) Line 1365  gensym (void)
1365  | null pointer instead of a symbol to terminate the rule.  The next  |  | null pointer instead of a symbol to terminate the rule.  The next  |
1366  | symbol is the lhs of the following rule.                           |  | symbol is the lhs of the following rule.                           |
1367  |                                                                    |  |                                                                    |
1368  | All guards and actions are copied out to the appropriate files,    |  | All actions are copied out, labelled by the rule number they apply |
1369  | labelled by the rule number they apply to.                         |  | to.                                                                |
1370  |                                                                    |  |                                                                    |
1371  | Bison used to allow some %directives in the rules sections, but    |  | Bison used to allow some %directives in the rules sections, but    |
1372  | this is no longer consider appropriate: (i) the documented grammar |  | this is no longer consider appropriate: (i) the documented grammar |
# Line 1582  readgram (void) Line 1563  readgram (void)
1563              t = lex ();              t = lex ();
1564            }            }
1565    
         if (t == tok_guard)  
           {  
             if (!semantic_parser)  
               complain (_("%%guard present but %%semantic_parser not specified"));  
   
             parse_guard (crule, rulelength);  
             t = lex ();  
           }  
   
1566          if (t == tok_left_curly)          if (t == tok_left_curly)
1567            {            {
1568              /* This case never occurs -wjh */              /* This case never occurs -wjh */
# Line 1791  packgram (void) Line 1763  packgram (void)
1763        rules[ruleno].useful = TRUE;        rules[ruleno].useful = TRUE;
1764        rules[ruleno].action = p->action;        rules[ruleno].action = p->action;
1765        rules[ruleno].action_line = p->action_line;        rules[ruleno].action_line = p->action_line;
       rules[ruleno].guard = p->guard;  
       rules[ruleno].guard_line = p->guard_line;  
1766    
1767        p = p->next;        p = p->next;
1768        while (p && p->sym)        while (p && p->sym)
# Line 1829  packgram (void) Line 1799  packgram (void)
1799      ritem_print (stderr);      ritem_print (stderr);
1800  }  }
1801    
1802  /*-------------------------------------------------------------------.  /*------------------------------------------------------------------.
1803  | Read in the grammar specification and record it in the format      |  | Read in the grammar specification and record it in the format     |
1804  | described in gram.h.  All guards are copied into the GUARD_OBSTACK |  | described in gram.h.  All actions are copied into ACTION_OBSTACK, |
1805  | and all actions into ACTION_OBSTACK, in each case forming the body |  | in each case forming the body of a C function (YYACTION) which    |
1806  | of a C function (YYGUARD or YYACTION) which contains a switch      |  | contains a switch statement to decide which action to execute.    |
1807  | statement to decide which guard or action to execute.              |  `------------------------------------------------------------------*/
 `-------------------------------------------------------------------*/  
1808    
1809  void  void
1810  reader (void)  reader (void)
# Line 1889  reader (void) Line 1858  reader (void)
1858      }      }
1859    
1860    /* Read in the grammar, build grammar in list form.  Write out    /* Read in the grammar, build grammar in list form.  Write out
1861       guards and actions.  */       actions.  */
1862    readgram ();    readgram ();
1863    /* Some C code is given at the end of the grammar file. */    /* Some C code is given at the end of the grammar file. */
1864    read_additionnal_code ();    read_additionnal_code ();

Legend:
Removed from v.1.171  
changed lines
  Added in v.1.172

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