syntax: introducing %gprec for precedence groups

It is now possible to introduce precedence groups, with precedence
relationships inside the group, but not with the outside tokens.  Ex:

%gprec arith {
  %left '+' '-'
  %left '*' '/'
  %right '^'
}

%gprec {
  %left OR
  %left AND
}

%left OTHER
%precedence OTHER2

Here, the arithmetical operators (in the "arith" group) can be compared, the
boolean operators can be compared, but OTHER can only be compared to OTHER2.

* src/gram.c, src/gram.h, src/scan-gram.l, src/parse-gram.y: {} blocks after
%gprec are understood by the lexer
* src/parse-gram.y: New syntax
* tests/input.at, tests/regression.at: Fix due to lexer change
This commit is contained in:
Valentin Tolmer
2013-08-01 14:54:30 +02:00
parent 2d8fc07778
commit f8a710c6f4
6 changed files with 59 additions and 4 deletions

View File

@@ -130,6 +130,7 @@
%token PERCENT_PREC "%prec"
%token PERCENT_DPREC "%dprec"
%token PERCENT_GPREC "%gprec"
%token PERCENT_MERGE "%merge"
/*----------------------.
@@ -178,6 +179,8 @@
%token TAG "<tag>"
%token TAG_ANY "<*>"
%token TAG_NONE "<>"
%token LBRACE "{"
%token RBRACE "}"
%union {unsigned char character;}
%type <character> CHAR
@@ -214,6 +217,7 @@
%union {named_ref *named_ref;}
%type <named_ref> named_ref.opt
%type <uniqstr> prec_group_name.opt
/*---------.
| %param. |
`---------*/
@@ -365,6 +369,7 @@ params:
grammar_declaration:
precedence_declaration
| precedence_group_declaration
| symbol_declaration
| "%start" symbol
{
@@ -457,6 +462,30 @@ symbol_declaration:
}
;
/* A group of symbols for precedence declaration */
precedence_group_declaration:
"%gprec" prec_group_name.opt
{
set_current_group ($2, &@2);
}
"{" precedence_declarations "}"
{
set_current_group (DEFAULT_GROUP_NAME, NULL);
}
;
/* Name for the precedence group. If none is present a new unique one is
generated. */
prec_group_name.opt:
%empty { $$ = new_anonymous_group_name (); }
| variable /* Just a string, maybe there's a better way? */
;
precedence_declarations:
precedence_declaration
| precedence_declarations precedence_declaration
;
precedence_declaration:
precedence_declarator tag.opt symbols.prec
{