Browse Source

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>
main
Jon Loeliger 17 years ago
parent
commit
7b3fb789d2
  1. 1
      Makefile
  2. 5
      dtc-parser.y
  3. 1
      dtc.h
  4. 17
      livetree.c

1
Makefile

@ -207,7 +207,6 @@ clean: libfdt_clean tests_clean @@ -207,7 +207,6 @@ clean: libfdt_clean tests_clean

%.tab.c %.tab.h %.output: %.y
@$(VECHO) BISON $@
@$(VECHO) ---- Expect 2 s/r and 2 r/r. ----
$(BISON) -d $<

FORCE:

5
dtc-parser.y

@ -18,7 +18,6 @@ @@ -18,7 +18,6 @@
* USA
*/

%glr-parser
%locations

%{
@ -126,9 +125,9 @@ proplist: @@ -126,9 +125,9 @@ proplist:
{
$$ = NULL;
}
| propdef proplist
| proplist propdef
{
$$ = chain_property($1, $2);
$$ = chain_property($2, $1);
}
;


1
dtc.h

@ -180,6 +180,7 @@ struct node { @@ -180,6 +180,7 @@ struct node {

struct property *build_property(char *name, struct data val, char *label);
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 *name_node(struct node *node, char *name, char *label);

17
livetree.c

@ -46,6 +46,21 @@ struct property *chain_property(struct property *first, struct property *list) @@ -46,6 +46,21 @@ struct property *chain_property(struct property *first, struct property *list)
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 *new = xmalloc(sizeof(*new));
@ -53,7 +68,7 @@ struct node *build_node(struct property *proplist, struct node *children) @@ -53,7 +68,7 @@ struct node *build_node(struct property *proplist, struct node *children)

memset(new, 0, sizeof(*new));

new->proplist = proplist;
new->proplist = reverse_properties(proplist);
new->children = children;

for_each_child(new, child) {

Loading…
Cancel
Save