27 #include "CallbacksGrammar.h"
72 for(; i < uiIndent; i++){fprintf(spOut,
" ");}
86 FILE* spOut = spParserData->
spOut;
87 fprintf(spParserData->
spOut,
"\n");
88 fprintf(spParserData->
spOut,
"uiFile: pre-parse processing\n");
89 fprintf(spParserData->
spOut,
"uiFile: initialize the callback data\n");
91 spParserData->spOut = spOut;
95 fprintf(spParserData->spOut,
"\n");
96 fprintf(spParserData->spOut,
"uiFile: post-parse processing\n");
97 fprintf(spParserData->spOut,
"uiFile: display the collected data\n");
99 fprintf(spParserData->spOut,
"uiFile: %3lu = lines\n", (
printf_uint)spParserData->uiLineNo);
100 fprintf(spParserData->spOut,
"uiFile: %3lu = blank lines\n", (
printf_uint)spParserData->uiBlankLines);
101 fprintf(spParserData->spOut,
"uiFile: %3lu = hexidecimal numbers rejected semantically\n", (
printf_uint)spParserData->uiHexNumOverrides);
102 fprintf(spParserData->spOut,
"uiFile: %3lu = SemiComments rejected\n", (
printf_uint)spParserData->uiSemiCommentsRejected);
103 fprintf(spParserData->spOut,
"uiFile: %3lu = SemiComments\n", (
printf_uint)spParserData->uiSemiComments);
104 fprintf(spParserData->spOut,
"uiFile: %3lu = CppComments\n", (
printf_uint)spParserData->uiCppComments);
105 fprintf(spParserData->spOut,
"uiFile: %3lu = CComments\n", (
printf_uint)spParserData->uiCComments);
106 fprintf(spParserData->spOut,
"uiFile: %3lu = errors\n", (
printf_uint)spParserData->uiLineErrors);
107 if(spParserData->uiLineErrors){
109 fprintf(spParserData->spOut,
"uiFile: errors at lines (one-based)\n");
110 for(i = 0; i < spParserData->uiLineErrors; i++){
111 fprintf(spParserData->spOut,
"uiFile: %lu\n", (
printf_uint)spParserData->uiaErrorLineNos[i]);
117 fprintf(spParserData->spOut,
"uiFile: error: state = EMPTY\n");
121 fprintf(spParserData->spOut,
"uiFile: error: state = NOMATCH\n");
140 FILE* spOut = spAstData->
spOut;
142 spAstData->
spOut = spOut;
143 fprintf(spAstData->
spOut,
"\n");
328 if(uiPhraseLength == 0){
332 for(i = 0; i < uiPhraseLength; i++){
334 uiErrorLength = i + 1;
338 if(i+1<uiPhraseLength && acpPhrase[i+1] == (
apg_achar)10){
339 uiErrorLength = i + 2;
342 uiErrorLength = i + 1;
393 char caInputString[uiBufferSize];
397 APG_CALLBACK saRuleTranslations[RULE_COUNT_CALLBACKSGRAMMAR];
398 APG_CALLBACK saUdtTranslations[UDT_COUNT_CALLBACKSGRAMMAR];
399 APG_CALLBACK saRuleCallbacks[RULE_COUNT_CALLBACKSGRAMMAR];
400 APG_CALLBACK saUdtCallbacks[UDT_COUNT_CALLBACKSGRAMMAR];
403 void* vpParser = NULL;
404 char* cpInFile =
"Callbacks.input";
405 char* cpOutFile =
"Callbacks.output";
409 spOut = fopen(cpOutFile,
"w");
411 printf(
"%s - output redirect file for vDemoCallbacks\n", cpOutFile);
413 printf(
"could not open output file \"%s\" - using stdout instead\n", cpOutFile);
417 fprintf(spOut,
"*** LICENSE NOTICE ***\n");
420 fprintf(spOut,
"\n*** DEMO CALLBACKS ***\n");
421 fprintf(spOut,
" - parsing\n");
422 fprintf(spOut,
" - adding callback functions to selected rules\n");
423 fprintf(spOut,
" - overriding the syntax semantically\n");
424 fprintf(spOut,
" - pre-branch syntax error detections\n");
425 fprintf(spOut,
" - post-branch semantically overriding the syntax\n");
426 fprintf(spOut,
" - adding the required callback functions for the UDTs defined in the grammar\n");
427 fprintf(spOut,
" - Abstract Syntax Tree (AST) translation\n");
428 fprintf(spOut,
" - translating rule AST nodes\n");
429 fprintf(spOut,
" - translating UDT AST nodes\n");
430 fprintf(spOut,
" - using the same callback function for both parsing and AST translation\n");
431 fprintf(spOut,
" - using the different callback functions for parsing and AST translation\n");
438 memset((
void*)&caInputString[0], 0, uiBufferSize);
442 uiTest =
uiGetFile(cpInFile, (
void*)&caInputString[0]);
444 caInputString[uiStrLen] = 0;
446 fprintf(spOut,
"\n*** THE INPUT STRING\n");
450 vCharToAChar(&acaParserString[0], &caInputString[0], uiStrLen);
453 memset((
void*)saRuleCallbacks, 0,
sizeof(saRuleCallbacks));
454 memset((
void*)saUdtCallbacks, 0,
sizeof(saUdtCallbacks));
455 saRuleCallbacks[RULE_CALLBACKSGRAMMAR_FILE] =
uiFileParser;
456 saRuleCallbacks[RULE_CALLBACKSGRAMMAR_BLANKLINE] =
uiBlankLine;
457 saRuleCallbacks[RULE_CALLBACKSGRAMMAR_LINEEND] =
uiLineEnd;
458 saRuleCallbacks[RULE_CALLBACKSGRAMMAR_HEXNUM] =
uiHexNum;
459 saRuleCallbacks[RULE_CALLBACKSGRAMMAR_CCOMMENT] =
uiCComment;
460 saRuleCallbacks[RULE_CALLBACKSGRAMMAR_CPPCOMMENT] =
uiCppComment;
461 saRuleCallbacks[RULE_CALLBACKSGRAMMAR_SEMICOMMENT] =
uiSemiComment;
466 memset((
void*)saRuleTranslations, 0,
sizeof(saRuleTranslations));
467 memset((
void*)saUdtTranslations, 0,
sizeof(saUdtTranslations));
469 saRuleTranslations[RULE_CALLBACKSGRAMMAR_FILE] =
uiFileAst;
470 saRuleTranslations[RULE_CALLBACKSGRAMMAR_HEXNUM] =
uiHexNum;
471 saRuleTranslations[RULE_CALLBACKSGRAMMAR_DECNUM] =
uiDecNum;
476 sParserData.
spOut = spOut;
477 sAstData.
spOut = spOut;
478 uiTest =
uiParserSyntaxAnalysis(vpParser, RULE_CALLBACKSGRAMMAR_FILE, &acaParserString[0], uiStrLen, &sParserData);
482 fprintf(spOut,
"\n*** PARSER STATE\n");
487 fprintf(spOut,
"\n*** AST NODES DISPLAY\n");
491 fprintf(spOut,
"\n*** AST TRANSLATIONS\n");
496 fprintf(spOut,
"\n*** DEMO CALLBACKS - test ended successfully ***\n");
497 if(spOut != stdout){fclose(spOut);}