DTC: Remove the need for the GLR Parser.

Previously, there were a few shift/reduce and reduce/reduce
errors in the grammar that were being handled by the not-so-popular
GLR Parser technique.

Flip a right-recursive stack-abusing rule into a left-recursive
stack-friendly rule and clear up three messes in one shot: No more
conflicts, no need for the GLR parser, and friendlier stackness.
Compensate by reversing the property list on the node.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
This commit is contained in:
Jon Loeliger 2007-10-22 16:09:56 -05:00
parent 3bef796b44
commit 7b3fb789d2
4 changed files with 19 additions and 5 deletions

View file

@ -207,7 +207,6 @@ clean: libfdt_clean tests_clean
%.tab.c %.tab.h %.output: %.y %.tab.c %.tab.h %.output: %.y
@$(VECHO) BISON $@ @$(VECHO) BISON $@
@$(VECHO) ---- Expect 2 s/r and 2 r/r. ----
$(BISON) -d $< $(BISON) -d $<
FORCE: FORCE:

View file

@ -18,7 +18,6 @@
* USA * USA
*/ */
%glr-parser
%locations %locations
%{ %{
@ -126,9 +125,9 @@ proplist:
{ {
$$ = NULL; $$ = NULL;
} }
| propdef proplist | proplist propdef
{ {
$$ = chain_property($1, $2); $$ = chain_property($2, $1);
} }
; ;

1
dtc.h
View file

@ -180,6 +180,7 @@ struct node {
struct property *build_property(char *name, struct data val, char *label); struct property *build_property(char *name, struct data val, char *label);
struct property *chain_property(struct property *first, struct property *list); struct property *chain_property(struct property *first, struct property *list);
struct property *reverse_properties(struct property *first);
struct node *build_node(struct property *proplist, struct node *children); struct node *build_node(struct property *proplist, struct node *children);
struct node *name_node(struct node *node, char *name, char *label); struct node *name_node(struct node *node, char *name, char *label);

View file

@ -46,6 +46,21 @@ struct property *chain_property(struct property *first, struct property *list)
return first; return first;
} }
struct property *reverse_properties(struct property *first)
{
struct property *p = first;
struct property *head = NULL;
struct property *next;
while (p) {
next = p->next;
p->next = head;
head = p;
p = next;
}
return head;
}
struct node *build_node(struct property *proplist, struct node *children) struct node *build_node(struct property *proplist, struct node *children)
{ {
struct node *new = xmalloc(sizeof(*new)); struct node *new = xmalloc(sizeof(*new));
@ -53,7 +68,7 @@ struct node *build_node(struct property *proplist, struct node *children)
memset(new, 0, sizeof(*new)); memset(new, 0, sizeof(*new));
new->proplist = proplist; new->proplist = reverse_properties(proplist);
new->children = children; new->children = children;
for_each_child(new, child) { for_each_child(new, child) {