mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
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:
parent
3bef796b44
commit
7b3fb789d2
4 changed files with 19 additions and 5 deletions
1
Makefile
1
Makefile
|
@ -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:
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
* USA
|
||||
*/
|
||||
|
||||
%glr-parser
|
||||
%locations
|
||||
|
||||
%{
|
||||
|
@ -126,9 +125,9 @@ proplist:
|
|||
{
|
||||
$$ = NULL;
|
||||
}
|
||||
| propdef proplist
|
||||
| proplist propdef
|
||||
{
|
||||
$$ = chain_property($1, $2);
|
||||
$$ = chain_property($2, $1);
|
||||
}
|
||||
;
|
||||
|
||||
|
|
1
dtc.h
1
dtc.h
|
@ -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
17
livetree.c
|
@ -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)
|
|||
|
||||
memset(new, 0, sizeof(*new));
|
||||
|
||||
new->proplist = proplist;
|
||||
new->proplist = reverse_properties(proplist);
|
||||
new->children = children;
|
||||
|
||||
for_each_child(new, child) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue