Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
|
Go to the documentation of this file.
46 #include "../api/api.h"
47 #include "../api/apip.h"
48 #include "../api/attributes.h"
49 #include "../api/semantics.h"
51 #include "../library/parserp.h"
61 int main(
int argc,
char **argv) {
62 static void* vpApi = NULL;
63 static void* vpCfg = NULL;
64 static void* vpMem = NULL;
67 const char* cpGrammar;
73 printf(
"APG CATCH BLOCK\n");
76 printf(
"EXCEPTION INFORMATION\n");
83 printf(
"memory allocation error\n");
105 if (spConfig->
bHelp) {
120 XTHROW(&e,
"no input file specified, use --input=filename");
130 printf(
"HTML formatted grammar written to \"%s\"\n", spConfig->
cpGrammarHtml);
136 printf(
"line ends of input converted to LF at: %s\n", spConfig->
cpLfOut);
140 printf(
"line ends of input converted to CRLF at: %s\n", spConfig->
cpCrLfOut);
157 if (spConfig->
bDra) {
163 printf(
"PPPT SIZES\n");
164 printf(
" alphabet min char: %"PRIuMAX
"\n", sSize.
luiAcharMin);
165 printf(
" alphabet max char: %"PRIuMAX
"\n", sSize.
luiAcharMax);
166 printf(
"number of PPPT maps: %"PRIuMAX
"\n", sSize.
luiMaps);
167 printf(
" PPPT map size: %"PRIuMAX
"\n", sSize.
luiMapSize);
169 printf(
" PPPT total size: OVERFLOW\n");
171 printf(
" PPPT total size: %"PRIuMAX
"\n", sSize.
luiTableSize);
185 printf(
"ATTRIBUTE ERRORS DETECTED\n");
202 printf(
"generated parser output to: %s\n", spConfig->
cpOutput);
void vConfigDefault(void *vpCtx, char *cpFileName)
Prints a default configuration file.
#define XCTOR(e)
This macro will initialize an exception structure and prepare entry to the "try" block.
char ** cppInput
array of uiInputFiles input file names
aint uiPRules
the number of protected rule names found
void vApiOutput(void *vpCtx, const char *cpOutput)
Generate a source and header file that can be used to construct a parser for the specified SABNF gram...
void vMemDtor(void *vpCtx)
Destroys a Memory component. Frees all memory allocated.
abool try
True for the try block, false for the catch block.
abool bDo
display the opcodes for each rule in human-readable form
void vApiAttrsToAscii(void *vpCtx, const char *cpMode, const char *cpFileName)
Display all rule attributes.
void vApiPpptSize(void *vpCtx, pppt_size *spSize)
Compute the size of the PPPT maps and the number of bytes for the entire table.
char * cpDefaultConfig
if non-n=NULL, generate a default configuration file using this file name
aint uiInputFiles
the number of input files found
This data controls the flow of the main program of the APG parser generator.
abool bHelp
the help flag, if set the help screen is printed and processing stops
void * vpApiCtor(exception *spEx)
Construct an API component context (object).
void vUtilPrintMsgs(void *vpMsgs)
Display the list of messages in a message object to stdout.
abool bDp
display the PPPT size
void vApiInValidate(void *vpCtx, abool bStrict)
Scans the input SABNF grammar for invalid characters and line ends.
abool bNoPppt
if set, Partially-Predictive Parsing Tables (PPPTs) will not be produced
luint luiMapSize
The size, in bytes, of a single PPPT table entry (map).
void vConfigHelp(void)
Prints the help screen when requested or if there is a command line options error.
void vApiOpcodes(void *vpCtx)
Parse the SABNF grammar and translate its AST into opcodes for all the rules.
const config * spConfigOptions(void *vpCtx, int iArgCount, char **cppArgs)
Reads the command line arguments and parses them into a configuration structure.
void vApiDtor(void *vpCtx)
The API component destructor.
void * vpApiGetErrorLog(void *vpCtx)
Get the internal message log.
luint luiAcharMax
The maximum character size in the grammar alphabet.
#define XTHROW(ctx, msg)
Exception throw macro.
abool bDc
display the complete configuration as found on command line or configuration file
abool bStrict
if set, the grammar is treated as strict ABNF
uint_fast32_t aint
The APG parser's unsigned integer type.
luint luiMaps
The number of maps needed.
int main(int argc, char **argv)
The executable from this main function is the ABNF Parser Generator application, APG.
char * cpLfOut
if non-null, the file name for the converted LF line ends file
void vConfigVersion(void)
Display the version number.
char * cpGrammarHtml
if non-null, the file name for the HTML version of the annotated input grammar
void vApiSyntax(void *vpCtx, abool bStrict)
Parse the SABNF grammar to validate that the grammar structure is valid.
abool bDra
display the grammar rule/UDT names alphabetically
A structure to describe the type and location of a caught exception.
abool bDg
display an annotated version of the input grammar
luint luiTableSize
The memory requirement, in bytes, of the full table.
char * cpCrLfOut
if non-null, the file name for the converted CRLF line ends file
void vApiRulesToAscii(void *vpCtx, const char *cpMode, const char *cpFileName)
Display rules and UDTs in human-readable format in ASCII format.
abool bApiAttrs(void *vpCtx)
Computes the grammar's attributes.
char ** cppPRules
array of protected rule names
Size information for the **P**artially-**P**redictive **P**arsing **T**ables (PPPT) data.
void * vpMemCtor(exception *spException)
Construct a memory component.
const char * cpApiInFile(void *vpCtx, const char *cpFileName)
Reads an SABNF grammar byte stream from a file.
void vConfigDisplay(const config *spConfig, int iArgCount, char **cppArgs)
Displays the full configuration as determined from the command line or command file arguments.
abool bDr
display grammar rule/UDT names in the order they occur in the grammar
luint luiAcharMin
The minimum character size in the grammar alphabet.
abool bVersion
the version flag, if set the version number is printed and processing stops
void vApiAttrsErrorsToAscii(void *vpCtx, const char *cpMode, const char *cpFileName)
Display all rule attributes with errors.
void vApiInToAscii(void *vpCtx, const char *cpFileName)
Display the input lines with line numbers and character offsets.
void vApiOpcodesToAscii(void *vpCtx, const char *cpFileName)
Display all opcodes in human-readable format.
#define APG_MAX_AINT
Since the maximum unsigned integer value is used to indicate Infinite and Undefined values,...
The configuration object header file.
void vApiInToHtml(void *vpCtx, const char *cpFileName, const char *cpTitle)
Display the input lines with line numbers and character offsets.
void vConfigDtor(void *vpCtx)
The configuration destructor.
char * cpOutput
the path name for the generated C source & header files
void vUtilConvertLineEnds(exception *spEx, const char *cpString, const char *cpEnd, const char *cpFileName)
Convert all line ending characters.
abool bDa
display grammar attributes
void vUtilPrintException(exception *spEx)
Prints exception information from an exception structure.
void * vpConfigCtor(exception *spEx)
Constructs a configuration object to hold all data relating to this instance of the configuration.
void vApiPppt(void *vpCtx, char **cppProtectedRules, aint uiProtectedRules)
Compute the Partially-Predictive Parsing Tables.
APG Version 7.0 is licensed under the
2-Clause BSD License,
an Open Source Initiative Approved License.