Commit Graph
4 Commits
Author SHA1 Message Date
Valentin Tolmer d8de391c38 syntax: introducing %precr to add specific precedence relations
It is now possible to add specific precedence relations between two symbols,
or a symbol and a group, with the %precr keyword:

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

%precr '^' > arith
%precr OR AND > '^'

Here, the symbol ^ is of higher priority than the the ones in arith, but of
lower priority than both OR and AND. OR and '+', for example, cannot be
compared.

* src/parse-gram.y, src/scan-gram.l: Lexer and grammar implementation of
%precr.
* src/symtab.c, src/symtab.h: implementation of the addition of single link
precedence relationships.
2013-08-01 15:24:52 +02:00
Valentin Tolmer f8a710c6f4 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
2013-08-01 15:24:52 +02:00
Valentin Tolmer 2d8fc07778 conflicts: switch to partial order precedence system
Even though it is not yet fully deployed, this commit lays the ground for
the partial order precedence system, by changing to a graph-based order and
introducing precedence groups (only the default one can be used for now).

* src/symtab.h (struct symbol): Removed extra fields
* src/symtab.h: New function declarations
* src/symtab.c: New functions for precedence and groups, new hash table for
groups
* src/AnnotationList.c, src/conflicts.c, src/gram.c, src/print-xml.c,
* src/symtab.c: Adaptation to the new prec_node structure
* tests/existing.at (GAWK LALR): Fix
2013-08-01 15:24:52 +02:00
Valentin Tolmer a910d26cfb introduction of the new structures to prepare for partial order precedence
New structures: symgroup, prec_link, prec_node, and an enum of the
precedence relation operators.  Symbols have two more fields to prepare for
the precedence graph and grouping to come.

* src/symtab.h (struct symbol): Two new fields
* src/symtab.h: New structures
2013-08-01 15:24:52 +02:00