Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
|
Go to the documentation of this file.
43 #include "../api/api.h"
44 #include "../api/apip.h"
45 #include "../api/attributes.h"
64 #ifdef TRACE_ATTRIBUTES
66 #include "../utilities/utilities.h"
67 static aint s_uiTreeDepth = 0;
68 static void vRuleOpen(
attrs_ctx* spAtt,
const char* cpRuleName);
72 static void vIndent(
aint uiIndent);
73 #define TRACE_RULE_OPEN(x,n) vRuleOpen((x), (n))
74 #define TRACE_RULE_CLOSE(x,n,a) vRuleClose((x), (n), (a))
75 #define TRACE_OPCODE_OPEN(x,o) vOpcodeOpen((x), (o))
76 #define TRACE_OPCODE_CLOSE(x,o,a) vOpcodeClose((x), (o), (a))
77 #define TRACE_OPCODE_CLOSE(x,o,a) vOpcodeClose((x), (o), (a))
78 #define TRACE_PRINT_ATTRS(x,t) vPrintAttrs((x), (t))
80 #define TRACE_RULE_OPEN(x,n)
81 #define TRACE_RULE_CLOSE(x,n,a)
82 #define TRACE_OPCODE_OPEN(x,o)
83 #define TRACE_PRINT_ATTRS(x,t)
84 #define TRACE_OPCODE_CLOSE(x,o,a)
116 for(ui = 0; ui < uiRuleCount; ui++){
118 for(uj = 0; uj < uiRuleCount; uj++){
124 vRuleAttrs(spAtt, ui, &sAttr);
135 for(ui = 0; ui < uiRuleCount; ui++){
185 *spAttrs = *spRuleAttrs;
186 }
else if (!spRuleAttrs->
bIsOpen) {
190 vOpcodeAttrs(spAtt, spOp, spAttrs);
217 switch (spOp->
uiId) {
219 vAltAttrs(spAtt, spOp, spAttrs);
222 vCatAttrs(spAtt, spOp, spAttrs);
225 vOpcodeAttrs(spAtt, (spOp + 1), spAttrs);
232 vRuleAttrs(spAtt, spOp->
uiIndex, spAttrs);
235 vBkrAttrs(spAtt, spOp, spAttrs);
241 vOpcodeAttrs(spAtt, (spOp + 1), spAttrs);
277 for (ui = 0; ui < uiCount; ui++) {
279 vOpcodeAttrs(spAtt, spChildOp, &saChildren[ui]);
288 for (ui = 0; ui < uiCount; ui++) {
289 if (saChildren[ui].bEmpty ==
APG_TRUE) {
292 if (saChildren[ui].bFinite ==
APG_TRUE) {
295 if (saChildren[ui].bLeft ==
APG_TRUE) {
298 if (saChildren[ui].bNested ==
APG_TRUE) {
301 if (saChildren[ui].bRight ==
APG_TRUE) {
304 if (saChildren[ui].bCyclic ==
APG_TRUE) {
315 for (ui = 0; ui < uiCount; ui++, spChild++) {
317 vOpcodeAttrs(spAtt, spChildOp, spChild);
319 spChild = &saChildAttrs[0];
320 spAttrs->
bCyclic = bIsCatCyclic(spChild, uiCount);
321 spAttrs->
bLeft = bIsCatLeft(spChild, uiCount);
322 spAttrs->
bNested = bIsCatNested(spChild, uiCount);
323 spAttrs->
bRight = bIsCatRight(spChild, uiCount);
324 spAttrs->
bEmpty = bIsCatEmpty(spChild, uiCount);
325 spAttrs->
bFinite = bIsCatFinite(spChild, uiCount);
331 for (; ui < uiCount; ui++) {
343 for (; ui < uiCount; ui++) {
344 if (spChild[ui].bEmpty !=
APG_TRUE) {
355 for (; ui < uiCount; ui++) {
356 if (spChild[ui].bFinite !=
APG_TRUE) {
366 for (; ui < uiCount; ui++) {
367 if (spChild[ui].bLeft ==
APG_TRUE) {
371 }
else if (!spChild[ui].bEmpty) {
382 for (ui = uiCount; ui > 0; ui--) {
384 if (spChild[uii].bRight ==
APG_TRUE) {
388 }
else if (!spChild[uii].bEmpty) {
415 for (ui = 0; ui < uiCount; ui++) {
423 for (ui = 0; ui < uiCount; ui++) {
426 for (uj = ui + 1; uj < uiCount; uj++) {
428 if (!bEmptyOnly(spAj)) {
436 for (ui = uiCount; ui > 0; ui--) {
437 spAi = &spChild[ui - 1];
439 for (uj = ui; uj > 0; uj--) {
440 spAj = &spChild[uj - 1];
441 if (!bEmptyOnly(spAj)) {
449 for (ui = 0; ui < uiCount; ui++) {
451 if (!spAi->
bEmpty && !bIsRecursive(spAi)) {
452 for (uj = ui + 1; uj < uiCount; uj++) {
454 if (bIsRecursive(spAj)) {
455 for (uk = uj + 1; uk < uiCount; uk++) {
457 if (!spAk->
bEmpty && !bIsRecursive(spAk)) {
489 #ifdef TRACE_ATTRIBUTES
490 static const char* s_cpTrue =
"yes";
491 static const char* s_cpFalse =
"no";
492 static const char* s_cpUndef =
"undef";
493 static const char * cpBool(
abool aTF) {
502 static void vRuleOpen(
attrs_ctx* spAtt,
const char* cpRuleName) {
503 vIndent(s_uiTreeDepth);
504 printf(
"%s: open\n", cpRuleName);
509 vIndent(s_uiTreeDepth);
510 printf(
"%s: (l:%s, n:%s, r:%s, e:%s, f:%s, cyclic:%s)\n", cpRuleName,
515 vIndent(s_uiTreeDepth);
521 vIndent(s_uiTreeDepth);
522 printf(
"%s: (l:%s, n:%s, r:%s, e:%s, f:%s, cyclic:%s)\n",
cpUtilOpName(spOp->
uiId),
526 static void vIndent(
aint uiIndent) {
abool bRight
APG_TRUE if the rule is right recursive.
abool bLeaf
APG_TRUE if this is a leaf rule (appears for a second time on a branch)
api_rule * spRules
Points to an array of rule structures.
abool bFinite
APG_TRUE if the rule is finite.
api_op * spOpcodes
Pointer to the array of opcodes for the SANF grammar.
aint uiAcharLength
number of characters in TLS/TBS strings
Private header for the SABNF parser.
The API will construct an attributes object. This is the attribute object's context.
#define TRACE_RULE_OPEN(x, n)
Working attribute information about a each rule.
abool bEmpty
APG_TRUE if the rule can be empty.
aint uiStartRule
The grammar start rule.
#define ID_ALT
alternation
const char * cpUtilOpName(aint uiId)
Convert an opcode identifier to a human-readable opcode name.
#define ID_BKR
back reference to a previously matched rule or UDT name
#define ID_UDT
user-defined terminal
aint uiChildCount
number of children for this ALT or CAT operator
aint uiMRGroup
the group number, if this is a member of a mutually-recursive group (there may be multiple groups)
abool bNested
APG_TRUE if the rule is nested recursive.
The recursive attributes of a single SABNF grammra rule.
abool bLeft
APG_TRUE if the rule is left recursive.
#define ID_NOT
negative look ahead
#define ID_AND
positive look ahead
abool bFinite
APG_TRUE if the rule is finite.
const char * cpRuleName
the rule name for these attributes
#define XTHROW(ctx, msg)
Exception throw macro.
luint luiMin
minimum value for REP and TRG opcodes
api_udt * spUdts
Points to an array of UDT structures, if one or more UDTs are referenced in the SABNF grammar.
aint uiRuleCount
The number of rules in the SABNF grammar and in the array.
uint_fast32_t aint
The APG parser's unsigned integer type.
#define ID_CAT
concatenation
#define ID_TRG
terminal range
api_attr * spErrorAttrs
An array of all rule attributes that have errors. (i.e. left recursive)
api * spApi
Pointer to the parent API context.
aint uiIndex
index of this referenced rule or UDT
#define TRACE_OPCODE_OPEN(x, o)
#define TRACE_OPCODE_CLOSE(x, o, a)
aint uiRecursiveType
ID_ATTR_N, ID_ATTR_R, ID_ATTR_MR, ID_ATTR_NMR, or ID_ATTR_RMR.
aint uiRecursiveType
ID_ATTR_N, ID_ATTR_R, ID_ATTR_MR, ID_ATTR_NMR, or ID_ATTR_RMR.
char * cpRuleName
the rule name for these attributes
#define TRACE_RULE_CLOSE(x, n, a)
API information about each opcode.
#define ID_BKA
positive look behind
abool bLeft
APG_TRUE if the rule is left recursive.
abool bRight
APG_TRUE if the rule is right recursive.
abool bCyclic
APG_TRUE if the rule is cyclic.
exception * spException
Pointer to the exception context inherited from the parent API.
aint uiId
type of opcode, ID_ALT, etc.
#define ID_TLS
terminal literal string
abool bNested
APG_TRUE if the rule is nested recursive.
aint uiEmpty
APG_TRUE if this UDT can be empty, APG_FALSE otherwise
api_attr_w * spWorkingAttrs
An array of private attribute structures.
#define ID_BKN
negative look behind
uint8_t abool
abool is the APG bool type.
abool bCyclic
APG_TRUE if the rule is cyclic.
aint uiRuleIndex
the index of the rule for these attributes
aint uiBkrIndex
if BKR, this is the index to the rule or UDT that is being back referenced
aint uiMRGroup
the group number, if this is a member of a mutually-recursive group (there may be multiple groups)
void vRuleAttributes(attrs_ctx *spAtt)
Computes the attributes of each rule in the grammar.
abool bEmpty
APG_TRUE if the rule can be empty.
aint * uipChildIndex
pointer to the first child index of this ALT or CAT operator
api_attr_w * spAttrs
An array of private attribute structures used in their construction.
#define ID_ABG
anchor - beginning of string
aint uiOpOffset
offset into the opcode table to the first opcode of this rule
aint uiEmpty
APG_TRUE if this UDT can be empty, APG_FALSE otherwise
#define ID_TBS
terminal binary string
aint uiRuleIndex
the index of the rule for these attributes
api_attr * spPublicAttrs
When attributes a complete, the public version strips some of the unneeded variables used only in con...
aint uiErrorCount
The number of rules that have attribute errors.
#define ID_AEN
anchor - end of string
APG Version 7.0 is licensed under the
2-Clause BSD License,
an Open Source Initiative Approved License.