[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01-symbols-list.patch
From: |
Akim Demaille |
Subject: |
01-symbols-list.patch |
Date: |
Mon, 17 Jun 2002 08:55:47 +0200 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* src/reader.h, src/reader.c (symbol_list_new): Export it.
(symbol_list_prepend): New.
* src/parse-gram.y (%union): `list' is a new member.
(symbols.1): New, replaces...
(terms_to_prec.1, nterms_to_type.1): these.
* src/symtab.h, src/symtab.c (symbol_type_set, symbol_precedence_set)
Take a location as additional argument.
Adjust all callers.
Index: src/parse-gram.y
--- src/parse-gram.y Sat, 15 Jun 2002 20:33:14 +0200 akim
+++ src/parse-gram.y Sun, 16 Jun 2002 17:40:51 +0200 akim
@@ -88,6 +88,7 @@
%union
{
symbol_t *symbol;
+ symbol_list *list;
int integer;
char *string;
associativity assoc;
@@ -144,7 +145,7 @@
%type <integer> INT
%type <symbol> ID symbol string_as_id
%type <assoc> precedence_declarator
-
+%type <list> symbols.1
%%
input:
@@ -211,17 +212,28 @@ declaration:
current_class = unknown_sym;
current_type = NULL;
}
-| "%type" TYPE {current_type = $2; } nterms_to_type.1
+| "%type" TYPE symbols.1
{
- current_type = NULL;
+ symbol_list *list;
+ for (list = $3; list; list = list->next)
+ symbol_type_set (list->sym, list->location, $2);
+ LIST_FREE (symbol_list, $3);
}
;
precedence_declaration:
- precedence_declarator type.opt
- { current_assoc = $1; ++current_prec; }
- terms_to_prec.1
- { current_assoc = non_assoc; current_type = NULL; }
+ precedence_declarator type.opt symbols.1
+ {
+ symbol_list *list;
+ ++current_prec;
+ for (list = $3; list; list = list->next)
+ {
+ symbol_type_set (list->sym, list->location, current_type);
+ symbol_precedence_set (list->sym, list->location, current_prec, $1);
+ }
+ LIST_FREE (symbol_list, $3);
+ current_type = NULL;
+ }
;
precedence_declarator:
@@ -236,23 +248,10 @@ type.opt:
;
/* One or more nonterminals to be %typed. */
-nterms_to_type.1:
- ID { symbol_type_set ($1, current_type); }
-| nterms_to_type.1 ID { symbol_type_set ($2, current_type); }
-;
-/* One or more symbols to be given a precedence/associativity. */
-terms_to_prec.1:
- symbol
- {
- symbol_type_set ($1, current_type);
- symbol_precedence_set ($1, current_prec, current_assoc);
- }
-| terms_to_prec.1 symbol
- {
- symbol_type_set ($2, current_type);
- symbol_precedence_set ($2, current_prec, current_assoc);
- }
+symbols.1:
+ symbol { $$ = symbol_list_new ($1, @1); }
+| symbols.1 symbol { $$ = symbol_list_prepend ($1, $2, @2); }
;
/* One token definition. */
@@ -264,24 +263,24 @@ type.opt:
| ID
{
symbol_class_set ($1, current_class);
- symbol_type_set ($1, current_type);
+ symbol_type_set ($1, @1, current_type);
}
| ID INT
{
symbol_class_set ($1, current_class);
- symbol_type_set ($1, current_type);
+ symbol_type_set ($1, @1, current_type);
symbol_user_token_number_set ($1, $2);
}
| ID string_as_id
{
symbol_class_set ($1, current_class);
- symbol_type_set ($1, current_type);
+ symbol_type_set ($1, @1, current_type);
symbol_make_alias ($1, $2);
}
| ID INT string_as_id
{
symbol_class_set ($1, current_class);
- symbol_type_set ($1, current_type);
+ symbol_type_set ($1, @1, current_type);
symbol_user_token_number_set ($1, $2);
symbol_make_alias ($1, $3);
}
Index: src/reader.c
--- src/reader.c Sat, 15 Jun 2002 14:24:28 +0200 akim
+++ src/reader.c Sun, 16 Jun 2002 17:16:32 +0200 akim
@@ -41,7 +41,7 @@
/* Nonzero if %union has been seen. */
int typed = 0;
-static symbol_list *
+symbol_list *
symbol_list_new (symbol_t *sym, location_t location)
{
symbol_list *res = XMALLOC (symbol_list, 1);
@@ -50,6 +50,14 @@
res->location = location;
res->action = NULL;
res->ruleprec = NULL;
+ return res;
+}
+
+symbol_list *
+symbol_list_prepend (symbol_list *list, symbol_t *symbol, location_t location)
+{
+ symbol_list *res = symbol_list_new (symbol, location);
+ res->next = list;
return res;
}
Index: src/reader.h
--- src/reader.h Fri, 14 Jun 2002 23:00:02 +0200 akim
+++ src/reader.h Sun, 16 Jun 2002 17:22:50 +0200 akim
@@ -36,6 +36,10 @@
symbol_t *ruleprec;
} symbol_list;
+symbol_list *symbol_list_new PARAMS ((symbol_t *sym, location_t location));
+symbol_list *symbol_list_prepend PARAMS ((symbol_list *list,
+ symbol_t *sym, location_t location));
+
# include "parse-gram.h"
typedef struct gram_control_s
Index: src/symtab.c
--- src/symtab.c Sat, 15 Jun 2002 15:39:16 +0200 akim
+++ src/symtab.c Sun, 16 Jun 2002 17:32:27 +0200 akim
@@ -102,12 +102,13 @@
`------------------------------------------------------------------*/
void
-symbol_type_set (symbol_t *symbol, char *type_name)
+symbol_type_set (symbol_t *symbol, location_t location, char *type_name)
{
if (type_name)
{
if (symbol->type_name)
- complain (_("type redeclaration for %s"), symbol->tag);
+ complain_at (location,
+ _("type redeclaration for %s"), symbol->tag);
symbol->type_name = type_name;
}
}
@@ -119,13 +120,14 @@
`------------------------------------------------------------------*/
void
-symbol_precedence_set (symbol_t *symbol,
+symbol_precedence_set (symbol_t *symbol, location_t location,
int prec, associativity assoc)
{
if (assoc != undef_assoc)
{
if (symbol->prec != 0)
- complain (_("redefining precedence of %s"), symbol->tag);
+ complain_at (location,
+ _("redefining precedence of %s"), symbol->tag);
symbol->prec = prec;
symbol->assoc = assoc;
}
Index: src/symtab.h
--- src/symtab.h Sat, 15 Jun 2002 15:39:16 +0200 akim
+++ src/symtab.h Sun, 16 Jun 2002 17:32:23 +0200 akim
@@ -54,12 +54,13 @@
typedef struct symbol_s symbol_t;
struct symbol_s
{
- /* The key, name of the symbol. */
+ /* The key, name of the symbol. */
char *tag;
- /* Its type. */
+
+ /* Its %type. */
char *type_name;
- /* The location of its first occurence. */
+ /* The location of its first occurence. */
location_t location;
symbol_number_t number;
@@ -106,11 +107,12 @@
/* Set the TYPE_NAME associated to SYMBOL. Does nothing if passed 0 as
TYPE_NAME. */
-void symbol_type_set PARAMS ((symbol_t *symbol, char *type_name));
+void symbol_type_set PARAMS ((symbol_t *symbol, location_t location,
+ char *type_name));
/* Set the PRECEDENCE associated to SYMBOL. Ensures that SYMBOL is a
terminal. Does nothing if invoked with UNDEF_ASSOC as ASSOC. */
-void symbol_precedence_set PARAMS ((symbol_t *symbol,
+void symbol_precedence_set PARAMS ((symbol_t *symbol, location_t location,
int prec, associativity assoc));
/* Set the CLASS associated to SYMBOL. */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 01-symbols-list.patch,
Akim Demaille <=