Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
Typedefs
apg.h File Reference

The APG header file. More...

#include <inttypes.h>
Include dependency graph for apg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

Version Information
#define APG_VERSION   "7.0"
 
#define APG_COPYRIGHT   "Copyright (c) 2021 Lowell D. Thomas, all rights reserved"
 
#define APG_LICENSE   "BSD 2-Clause"
 
Trace Control.

The parser uses these macros to call the tracing functions. If APG_TRACE is defined, these are the functions that are called. If not defined, these macros are defined as empty, generating no code at all in the parser. This prevents the parser from having to do unnecessary testing when no tracing is requested. Additionally, all tracing code is excluded from the build.

#define TRACE_DOWN(x, o, f)   if((x))vTraceDown((x), (o), (f))
 
#define TRACE_UP(x, o, s, f, p)   if((x))vTraceUp((x), (o), (s), (f), (p));
 
#define TRACE_BEGIN(x)   if((x))vTraceBegin((x))
 
#define TRACE_END(x)   if((x))vTraceEnd((x))
 
#define TRACE_DTOR(x)   if((x))vTraceDtor((x))
 
Parsing Statistics Control.

The parser uses these macros to call the statistics gathering functions. If APG_STATS is defined, these are the functions that are called. If not defined, these macros are defined as empty, generating no code at all in the parser. This prevents the parser from having to do unnecessary testing when no statistics are requested. Additionally, all statistics gathering code is excluded from the build.

#define STATS_HIT(x, o, s)   if((x))vStatsHit((x), (o), (s))
 
Back Referencing Control.

The parser uses these macros to call the back referencing functions. If APG_BKR is defined, these are the functions that are called. If not defined, these macros are defined as empty, generating no code at all in the parser. This prevents the parser from having to do unnecessary testing when no statistics are requested. Additionally, all back referencing code is excluded from the build.

Note that back referencing is compute intensive. It is used primarily in the phrase-matching application apgex.c. Unless strictly required for an application, this macro should not be defined.

#define BKR_APGEX_CHECK(e)
 
#define BKRU_CTOR(x)   vpBkruCtor((x))
 
#define BKRU_RULE_OPEN(x, i)   if((x)) vBkruRuleOpen((x), (i))
 
#define BKRU_RULE_CLOSE(x, i, s, o, p)   if((x)) vBkruRuleClose((x), (i), (s), (o), (p))
 
#define BKRU_UDT_CLOSE(x, i, s, o, p)   if((x)) vBkruUdtClose((x), (i), (s), (o), (p))
 
#define BKRU_OP_OPEN(x)   if((x)) vBkruOpOpen((x))
 
#define BKRU_OP_CLOSE(x, s)   if((x)) vBkruOpClose((x), (s))
 
#define BKRP_CTOR(x)   vpBkrpCtor((x))
 
#define BKRP_RULE_OPEN(x, i)   if((x)) vBkrpRuleOpen((x), (i))
 
#define BKRP_RULE_CLOSE(x, i, s, o, p)   if((x)) vBkrpRuleClose((x), (i), (s), (o), (p))
 
#define BKRP_UDT_CLOSE(x, i, s, o, p)   if((x)) vBkrpUdtClose((x), (i), (s), (o), (p))
 
#define BKRP_OP_OPEN(x)   if((x)) vBkrpOpOpen((x))
 
#define BKRP_OP_CLOSE(x, s)   if((x)) vBkrpOpClose((x), (s))
 
Abstract Syntax Tree (AST) Control.

The parser uses these macros to call the generate the AST. If APG_AST is defined, these are the functions that are called. If not defined, these macros are defined as empty, generating no code at all in the parser. This prevents the parser from having to do unnecessary testing when no AST is requested. Additionally, all AST code is excluded from the build.

#define AST_CLEAR(v)   if(v)vAstClear(v)
 
#define AST_RULE_OPEN(x, l, i, o)   if((x) && !(l)) vAstRuleOpen((x), (i), (o))
 
#define AST_RULE_CLOSE(x, l, i, s, o, p)   if((x) && !(l)) vAstRuleClose((x), (i), (s), (o), (p))
 
#define AST_OP_OPEN(x, l)   if((x)) if((x) && !(l)) vAstOpOpen((x))
 
#define AST_OP_CLOSE(x, l, s)   if((x) && !(l)) vAstOpClose((x), (s))
 
Partially-Predictive Parsing Table (PPPT) Control.

The parser uses these macros to call the generate the PPPT. If APG_NO_PPPT is not defined, these are the functions that are called to evaluate the PPPT values. If not defined, these macros are defined as empty, generating no code at all in the parser. This prevents the parser from having to do unnecessary testing when no PPPT is requested. Additionally, if APG_NO_PPPT is defined the API will not generate any table data.

#define PPPT_OPEN(x, o, f)
 
#define PPPT_CLOSE
 
#define PPPT_DEFINED   0
 
True/False Values.

Provides a consistent definition of true and false throughout APG.

#define APG_TRUE   1
 
#define APG_FALSE   0
 
Success/Failure Values.

In many cases it is more intuitive for a function to return "success" or "failure" so that, for example, error checking can be done simply with

if(!bApgFunc()){
//handle error
}
#define APG_SUCCESS   1
 
#define APG_FAILURE   0
 
Undefined and Infinite Values.

It is sometimes the case of needing to have an undefined or infinite value. For finite, unsigned integers this is not possible. Therefore, the maximum unsigned integer value is used to indicate these.

#define APG_UNDEFINED   ((aint)-1)
 
#define APG_INFINITE   ((aint)-1)
 
Maximum Values.
#define APG_MAX_AINT   ((aint)-2)
 Since the maximum unsigned integer value is used to indicate Infinite and Undefined values, the maximum usable integer is one less. More...
 
#define APG_MAX_ACHAR   ((achar)-1)
 

Typedefs

typedef uint_fast32_t aint
 The APG parser's unsigned integer type. More...
 
typedef uint_fast8_t achar
 achar is the type for the parser's alphabet characters. More...
 
typedef uintmax_t luint
 luint is used to cast integers suitable for the %"PRIuMAX" printf format. More...
 
typedef uint8_t abool
 abool is the APG bool type. More...
 

Detailed Description

The APG header file.

APG has a large number of options. The alphabet character and the working integer sizes are configurable. Additionally, many facilities are optional and the code for them is excluded from the build when not used. Control of these features and options is done through the use of special macros defined here and with the compiler.

For many simple parsers the default values may be sufficient and no special compile-time interactions will be necessary. However, for full control of APG in an application some or all of these macros may need to be specifically defined.

This header (or lib.h) must be included first before all other APG and application-defined header files in all applications using a parser generated by APG. With the gcc compiler, for example, the controlling macros can be defined with the -D option. e.g.

gcc -DAPG_ACHAR=16 [other options] ../myfile.c

The controlling macros are:

Definition in file apg.h.

Macro Definition Documentation

◆ APG_COPYRIGHT

#define APG_COPYRIGHT   "Copyright (c) 2021 Lowell D. Thomas, all rights reserved"

Definition at line 66 of file apg.h.

◆ APG_FAILURE

#define APG_FAILURE   0

Definition at line 308 of file apg.h.

◆ APG_FALSE

#define APG_FALSE   0

Definition at line 292 of file apg.h.

◆ APG_INFINITE

#define APG_INFINITE   ((aint)-1)

Definition at line 320 of file apg.h.

◆ APG_LICENSE

#define APG_LICENSE   "BSD 2-Clause"

Definition at line 67 of file apg.h.

◆ APG_MAX_ACHAR

#define APG_MAX_ACHAR   ((achar)-1)

Definition at line 331 of file apg.h.

◆ APG_MAX_AINT

#define APG_MAX_AINT   ((aint)-2)

Since the maximum unsigned integer value is used to indicate Infinite and Undefined values, the maximum usable integer is one less.

<

Definition at line 329 of file apg.h.

◆ APG_SUCCESS

#define APG_SUCCESS   1

Definition at line 307 of file apg.h.

◆ APG_TRUE

#define APG_TRUE   1

Definition at line 291 of file apg.h.

◆ APG_UNDEFINED

#define APG_UNDEFINED   ((aint)-1)

Definition at line 318 of file apg.h.

◆ APG_VERSION

#define APG_VERSION   "7.0"

Definition at line 65 of file apg.h.

◆ AST_CLEAR

#define AST_CLEAR (   v)    if(v)vAstClear(v)

Definition at line 252 of file apg.h.

◆ AST_OP_CLOSE

#define AST_OP_CLOSE (   x,
  l,
 
)    if((x) && !(l)) vAstOpClose((x), (s))

Definition at line 256 of file apg.h.

◆ AST_OP_OPEN

#define AST_OP_OPEN (   x,
 
)    if((x)) if((x) && !(l)) vAstOpOpen((x))

Definition at line 255 of file apg.h.

◆ AST_RULE_CLOSE

#define AST_RULE_CLOSE (   x,
  l,
  i,
  s,
  o,
 
)    if((x) && !(l)) vAstRuleClose((x), (i), (s), (o), (p))

Definition at line 254 of file apg.h.

◆ AST_RULE_OPEN

#define AST_RULE_OPEN (   x,
  l,
  i,
 
)    if((x) && !(l)) vAstRuleOpen((x), (i), (o))

Definition at line 253 of file apg.h.

◆ BKR_APGEX_CHECK

#define BKR_APGEX_CHECK (   e)

Definition at line 213 of file apg.h.

◆ BKRP_CTOR

#define BKRP_CTOR (   x)    vpBkrpCtor((x))

Definition at line 220 of file apg.h.

◆ BKRP_OP_CLOSE

#define BKRP_OP_CLOSE (   x,
 
)    if((x)) vBkrpOpClose((x), (s))

Definition at line 225 of file apg.h.

◆ BKRP_OP_OPEN

#define BKRP_OP_OPEN (   x)    if((x)) vBkrpOpOpen((x))

Definition at line 224 of file apg.h.

◆ BKRP_RULE_CLOSE

#define BKRP_RULE_CLOSE (   x,
  i,
  s,
  o,
 
)    if((x)) vBkrpRuleClose((x), (i), (s), (o), (p))

Definition at line 222 of file apg.h.

◆ BKRP_RULE_OPEN

#define BKRP_RULE_OPEN (   x,
 
)    if((x)) vBkrpRuleOpen((x), (i))

Definition at line 221 of file apg.h.

◆ BKRP_UDT_CLOSE

#define BKRP_UDT_CLOSE (   x,
  i,
  s,
  o,
 
)    if((x)) vBkrpUdtClose((x), (i), (s), (o), (p))

Definition at line 223 of file apg.h.

◆ BKRU_CTOR

#define BKRU_CTOR (   x)    vpBkruCtor((x))

Definition at line 214 of file apg.h.

◆ BKRU_OP_CLOSE

#define BKRU_OP_CLOSE (   x,
 
)    if((x)) vBkruOpClose((x), (s))

Definition at line 219 of file apg.h.

◆ BKRU_OP_OPEN

#define BKRU_OP_OPEN (   x)    if((x)) vBkruOpOpen((x))

Definition at line 218 of file apg.h.

◆ BKRU_RULE_CLOSE

#define BKRU_RULE_CLOSE (   x,
  i,
  s,
  o,
 
)    if((x)) vBkruRuleClose((x), (i), (s), (o), (p))

Definition at line 216 of file apg.h.

◆ BKRU_RULE_OPEN

#define BKRU_RULE_OPEN (   x,
 
)    if((x)) vBkruRuleOpen((x), (i))

Definition at line 215 of file apg.h.

◆ BKRU_UDT_CLOSE

#define BKRU_UDT_CLOSE (   x,
  i,
  s,
  o,
 
)    if((x)) vBkruUdtClose((x), (i), (s), (o), (p))

Definition at line 217 of file apg.h.

◆ PPPT_CLOSE

#define PPPT_CLOSE

Definition at line 276 of file apg.h.

◆ PPPT_DEFINED

#define PPPT_DEFINED   0

Definition at line 277 of file apg.h.

◆ PPPT_OPEN

#define PPPT_OPEN (   x,
  o,
 
)

Definition at line 275 of file apg.h.

◆ STATS_HIT

#define STATS_HIT (   x,
  o,
 
)    if((x))vStatsHit((x), (o), (s))

Definition at line 190 of file apg.h.

◆ TRACE_BEGIN

#define TRACE_BEGIN (   x)    if((x))vTraceBegin((x))

Definition at line 169 of file apg.h.

◆ TRACE_DOWN

#define TRACE_DOWN (   x,
  o,
 
)    if((x))vTraceDown((x), (o), (f))

Definition at line 167 of file apg.h.

◆ TRACE_DTOR

#define TRACE_DTOR (   x)    if((x))vTraceDtor((x))

Definition at line 171 of file apg.h.

◆ TRACE_END

#define TRACE_END (   x)    if((x))vTraceEnd((x))

Definition at line 170 of file apg.h.

◆ TRACE_UP

#define TRACE_UP (   x,
  o,
  s,
  f,
 
)    if((x))vTraceUp((x), (o), (s), (f), (p));

Definition at line 168 of file apg.h.

Typedef Documentation

◆ abool

abool is the APG bool type.

It is used as a space saver for variables that represent true (1) or false (0) values.

Definition at line 140 of file apg.h.

◆ achar

achar is the type for the parser's alphabet characters.

This is configurable with the APG_ACHAR macro. The default is uint_fast8_t. That is, the compiler's choice for the fastest way to handle unsigned 8-bit integers. However, this is configurable with the APG_ACHAR macro. For specific integer lengths define the APG_ACHAR macro.

  • APG_ACHAR=8 for uint8_t, unsigned 8-bit integers
  • APG_ACHAR=16 for uint16_t, unsigned 16-bit integers
  • APG_ACHAR=32 for uint32_t, unsigned 32-bit integers
  • APG_ACHAR=64 for uint64_t, unsigned 64-bit integers

For example, with the gcc compiler use the option -DAPG_ACHAR=16 for 16-bit unsigned integers. If APG_ACHAR is undefined or defined to something other than 8, 16. 32, or 64 the default is used.

Definition at line 91 of file apg.h.

◆ aint

The APG parser's unsigned integer type.

The default type is uint_fast32_t. That is, the compiler's choice for the fastest way to handle unsigned 32-bit integers. However, this is configurable with the APG_AINT macro. For specific integer lengths define the APG_AINT macro.

  • APG_AINT=8 for uint8_t, unsigned 8-bit integers (not recommended)
  • APG_AINT=16 for uint16_t, unsigned 16-bit integers
  • APG_AINT=32 for uint32_t, unsigned 32-bit integers
  • APG_AINT=64 for uint64_t, unsigned 64-bit integers

For example, with the gcc compiler use the option -DAPG_AINT=32 for 32-bit unsigned integers. If APG_AINT is undefined or defined to something other than 8, 16. 32, or 64 the default is used.

Definition at line 79 of file apg.h.

◆ luint

luint is used to cast integers suitable for the %"PRIuMAX" printf format.

Useful because the length of aint is compile-time dependent and the flag is not conveniently represtened by a variable. Avoids errors due to a printf("%u", uiSomeInt); when aint is not an uint32_t. Instead, use printf("%"PRIuMAX"", (luint)uiSomeInt);

Definition at line 133 of file apg.h.

APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.