From 3f7797419e4d7493e1364290a5b127d1cb45e3bf Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Sun, 14 Apr 2019 12:04:23 -0300 Subject: Removed 'unsigned char' limit on number of rules in grammars Added a new tree-type node 'TXInfo', which follows 'TRule' nodes, to store extra information about a node. (In this case, the rule number, with an 'unsigned short' field.) --- lpprint.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'lpprint.c') diff --git a/lpprint.c b/lpprint.c index df62cbe..397785e 100644 --- a/lpprint.c +++ b/lpprint.c @@ -60,7 +60,8 @@ void printinst (const Instruction *op, const Instruction *p) { "ret", "end", "choice", "jmp", "call", "open_call", "commit", "partial_commit", "back_commit", "failtwice", "fail", "giveup", - "fullcapture", "opencapture", "closecapture", "closeruntime" + "fullcapture", "opencapture", "closecapture", "closeruntime", + "--" }; printf("%02ld: %s ", (long)(p - op), names[p->i.code]); switch ((Opcode)p->i.code) { @@ -151,7 +152,7 @@ static const char *tagnames[] = { "rep", "seq", "choice", "not", "and", - "call", "opencall", "rule", "grammar", + "call", "opencall", "rule", "xinfo", "grammar", "behind", "capture", "run-time" }; @@ -159,6 +160,7 @@ static const char *tagnames[] = { void printtree (TTree *tree, int ident) { int i; + int sibs = numsiblings[tree->tag]; for (i = 0; i < ident; i++) printf(" "); printf("%s", tagnames[tree->tag]); switch (tree->tag) { @@ -176,24 +178,26 @@ void printtree (TTree *tree, int ident) { break; } case TOpenCall: case TCall: { - assert(sib2(tree)->tag == TRule); - printf(" key: %d (rule: %d)\n", tree->key, sib2(tree)->cap); + assert(sib1(sib2(tree))->tag == TXInfo); + printf(" key: %d (rule: %d)\n", tree->key, sib1(sib2(tree))->u.n); break; } case TBehind: { printf(" %d\n", tree->u.n); - printtree(sib1(tree), ident + 2); break; } case TCapture: { printf(" kind: '%s' key: %d\n", capkind(tree->cap), tree->key); - printtree(sib1(tree), ident + 2); break; } case TRule: { - printf(" n: %d key: %d\n", tree->cap, tree->key); - printtree(sib1(tree), ident + 2); - break; /* do not print next rule as a sibling */ + printf(" key: %d\n", tree->key); + sibs = 1; /* do not print 'sib2' (next rule) as a sibling */ + break; + } + case TXInfo: { + printf(" n: %d\n", tree->u.n); + break; } case TGrammar: { TTree *rule = sib1(tree); @@ -203,18 +207,17 @@ void printtree (TTree *tree, int ident) { rule = sib2(rule); } assert(rule->tag == TTrue); /* sentinel */ + sibs = 0; /* siblings already handled */ break; } - default: { - int sibs = numsiblings[tree->tag]; + default: printf("\n"); - if (sibs >= 1) { - printtree(sib1(tree), ident + 2); - if (sibs >= 2) - printtree(sib2(tree), ident + 2); - } break; - } + } + if (sibs >= 1) { + printtree(sib1(tree), ident + 2); + if (sibs >= 2) + printtree(sib2(tree), ident + 2); } } -- cgit v1.2.3-55-g6feb