/* This file is automatically generated by Lemon from input grammar ** source file "datalog.lime". */ /* ** 2000-05-29 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** Driver template for the lime parser generator. ** ** The "lemon" program processes an LALR(1) input grammar file, then uses ** this template to construct a parser. The "lemon" program inserts text ** at each "%%" line. Also, any "P-a-r-s-e" identifier prefix (without the ** interstitial "-" characters) contained in this template is changed into ** the value of the %name directive from the grammar. Otherwise, the content ** of this template is copied straight through into the generated parser ** source file. ** ** The following is the concatenation of all %include directives from the ** input grammar file: */ /************ Begin %include sections from the grammar ************************/ #line 79 "datalog.lime" #include #include #include #include #include "datalog_defs.h" #include "datalog_helpers.h" #line 38 "datalog.c" /**************** End of %include directives **********************************/ /* These constants specify the various numeric values for terminal symbols. ***************** Begin token definitions *************************************/ #ifndef ATOM #define ATOM 1 #define VARIABLE 2 #define UNDERSCORE 3 #define INTEGER 4 #define FLOAT 5 #define STRING 6 #define KEYWORD 7 #define LPAREN 8 #define RPAREN 9 #define LBRACKET 10 #define RBRACKET 11 #define LBRACE 12 #define RBRACE 13 #define COMMA 14 #define DOT 15 #define PIPE 16 #define HASH_LBRACE 17 #define RULE_OP 18 #define QUERY_OP 19 #define NOT_OP 20 #define NEQ_OP 21 #define EQ_OP 22 #define LT_OP 23 #define GT_OP 24 #define LTE_OP 25 #define GTE_OP 26 #define COUNT 27 #define SUM 28 #define MIN 29 #define MAX 30 #define AVG 31 #define TRUE_K 32 #define FALSE_K 33 #define NIL_K 34 #endif /**************** End token definitions ***************************************/ /* The next sections is a series of control #defines. ** various aspects of the generated parser. ** YYCODETYPE is the data type used to store the integer codes ** that represent terminal and non-terminal symbols. ** "unsigned char" is used if there are fewer than ** 256 symbols. Larger types otherwise. ** YYNOCODE is a number of type YYCODETYPE that is not used for ** any terminal or nonterminal symbol. ** YYFALLBACK If defined, this indicates that one or more tokens ** (also known as: "terminal symbols") have fall-back ** values which should be used if the original symbol ** would not parse. This permits keywords to sometimes ** be used as identifiers, for example. ** YYACTIONTYPE is the data type used for "action codes" - numbers ** that indicate what to do in response to the next ** token. ** datalogParseTOKENTYPE is the data type used for minor type for terminal ** symbols. Background: A "minor type" is a semantic ** value associated with a terminal or non-terminal ** symbols. For example, for an "ID" terminal symbol, ** the minor type might be the name of the identifier. ** Each non-terminal can have a different minor type. ** Terminal symbols all have the same minor type, though. ** This macros defines the minor type for terminal ** symbols. ** YYMINORTYPE is the data type used for all minor types. ** This is typically a union of many types, one of ** which is datalogParseTOKENTYPE. The entry in the union ** for terminal symbols is called "yy0". ** YYSTACKDEPTH is the maximum depth of the parser's stack. If ** zero the stack is dynamically sized using realloc() ** datalogParseARG_SDECL A static variable declaration for the %extra_argument ** datalogParseARG_PDECL A parameter declaration for the %extra_argument ** datalogParseARG_PARAM Code to pass %extra_argument as a subroutine parameter ** datalogParseARG_STORE Code to store %extra_argument into yypParser ** datalogParseARG_FETCH Code to extract %extra_argument from yypParser ** datalogParseCTX_* As datalogParseARG_ except for %extra_context ** YYREALLOC Name of the realloc() function to use ** YYFREE Name of the free() function to use ** YYDYNSTACK True if stack space should be extended on heap ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. ** YYNSTATE the combined number of states. ** YYNRULE the number of rules in the grammar ** YYNTOKEN Number of terminal symbols ** YY_MAX_SHIFT Maximum value for shift actions ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions ** YY_ERROR_ACTION The yy_action[] code for syntax error ** YY_ACCEPT_ACTION The yy_action[] code for accept ** YY_NO_ACTION The yy_action[] code for no-op ** YY_MIN_REDUCE Minimum value for reduce actions ** YY_MAX_REDUCE Maximum value for reduce actions ** YY_MIN_DSTRCTR Minimum symbol value that has a destructor ** YY_MAX_DSTRCTR Maximum symbol value that has a destructor */ #ifndef INTERFACE # define INTERFACE 1 #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned char #define YYNOCODE 63 #define YYACTIONTYPE unsigned char #define datalogParseTOKENTYPE DatalogToken typedef union { int yyinit; datalogParseTOKENTYPE yy0; DlClauseList * yy34; DlClause * yy50; DlCompOp yy61; DlProgram * yy87; DlTermList * yy89; DlLiteralList * yy90; DlAggFunc yy96; DlTerm * yy105; DlLiteral * yy110; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 #endif #define datalogParseARG_SDECL DatalogParseState *pstate; #define datalogParseARG_PDECL ,DatalogParseState *pstate #define datalogParseARG_PARAM ,pstate #define datalogParseARG_FETCH DatalogParseState *pstate=yypParser->pstate; #define datalogParseARG_STORE yypParser->pstate=pstate; #undef YYREALLOC #define YYREALLOC realloc #undef YYFREE #define YYFREE free #undef YYDYNSTACK #define YYDYNSTACK 0 #undef YYSIZELIMIT #define datalogParseCTX(P) 0 #define datalogParseCTX_SDECL #define datalogParseCTX_PDECL #define datalogParseCTX_PARAM #define datalogParseCTX_FETCH #define datalogParseCTX_STORE #undef YYERRORSYMBOL #undef YYERRSYMDT #undef YYFALLBACK #define YYNSTATE 31 #define YYNRULE 65 #define YYNRULE_WITH_ACTION 65 #define YYNTOKEN 35 #define YY_MAX_SHIFT 30 #define YY_MIN_SHIFTREDUCE 92 #define YY_MAX_SHIFTREDUCE 156 #define YY_ERROR_ACTION 157 #define YY_ACCEPT_ACTION 158 #define YY_NO_ACTION 159 #define YY_MIN_REDUCE 160 #define YY_MAX_REDUCE 224 #define YY_MIN_DSTRCTR 0 #define YY_MAX_DSTRCTR 0 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) /* Define the yytestcase() macro to be a no-op if is not already defined ** otherwise. ** ** Applications can choose to define yytestcase() in the %include section ** to a macro that can assist in verifying code coverage. For production ** code the yytestcase() macro should be turned off. But it is useful ** for testing. */ #ifndef yytestcase # define yytestcase(X) #endif /* Macro to determine if stack space has the ability to grow using ** heap memory. */ #if YYSTACKDEPTH<=0 || YYDYNSTACK # define YYGROWABLESTACK 1 #else # define YYGROWABLESTACK 0 #endif /* Guarantee a minimum number of initial stack slots. */ #if YYSTACKDEPTH<=0 # undef YYSTACKDEPTH # define YYSTACKDEPTH 2 /* Need a minimum stack size */ #endif /* Next are the tables used to determine what action to take based on the ** current state and lookahead token. These tables are used to implement ** functions that take a state number and lookahead value and return an ** action integer. ** ** Suppose the action integer is N. Then the action is determined as ** follows ** ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead ** token onto the stack and goto state N. ** ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. ** ** N == YY_ERROR_ACTION A syntax error has occurred. ** ** N == YY_ACCEPT_ACTION The parser accepts its input. ** ** N == YY_NO_ACTION No such action. Denotes unused ** slots in the yy_action[] table. ** ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE ** and YY_MAX_REDUCE ** ** The action table is constructed as a single large table named yy_action[]. ** Given state S and lookahead X, the action is computed as either: ** ** (A) N = yy_action[ yy_shift_ofst[S] + X ] ** (B) N = yy_default[S] ** ** The (A) formula is preferred. The B formula is used instead if ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X. ** ** The formulas above are for computing the action when the lookahead is ** a terminal symbol. If the lookahead is a non-terminal (as occurs after ** a reduce action) then the yy_reduce_ofst[] array is used in place of ** the yy_shift_ofst[] array. ** ** The following are the tables generated in this section: ** ** yy_action[] A single table containing all actions. ** yy_lookahead[] A table containing the lookahead for each entry in ** yy_action. Used to detect hash collisions. ** yy_shift_ofst[] For each state, the offset into yy_action for ** shifting terminals. ** yy_reduce_ofst[] For each state, the offset into yy_action for ** shifting non-terminals after a reduce. ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ #define YY_ACTTAB_COUNT (342) static const YYACTIONTYPE yy_action[] = { /* 0 */ 12, 20, 132, 133, 135, 136, 137, 141, 25, 180, /* 10 */ 6, 110, 4, 28, 11, 8, 15, 5, 147, 7, /* 20 */ 19, 179, 179, 99, 101, 120, 2, 121, 122, 123, /* 30 */ 124, 125, 138, 139, 140, 24, 29, 172, 174, 175, /* 40 */ 176, 18, 177, 27, 3, 17, 197, 196, 198, 199, /* 50 */ 210, 211, 212, 30, 29, 172, 174, 175, 176, 8, /* 60 */ 177, 27, 100, 17, 197, 196, 198, 199, 210, 211, /* 70 */ 212, 134, 132, 133, 135, 136, 137, 141, 159, 159, /* 80 */ 6, 159, 4, 149, 14, 159, 159, 5, 13, 197, /* 90 */ 196, 198, 199, 210, 211, 212, 21, 219, 161, 28, /* 100 */ 160, 28, 138, 139, 140, 134, 132, 133, 135, 136, /* 110 */ 137, 141, 159, 159, 6, 145, 4, 1, 14, 1, /* 120 */ 159, 5, 159, 222, 197, 196, 198, 199, 210, 211, /* 130 */ 212, 159, 159, 9, 159, 159, 138, 139, 140, 159, /* 140 */ 115, 114, 116, 117, 118, 119, 159, 173, 174, 175, /* 150 */ 176, 159, 177, 27, 159, 17, 197, 196, 198, 199, /* 160 */ 210, 211, 212, 134, 132, 133, 135, 136, 137, 141, /* 170 */ 159, 159, 6, 159, 4, 148, 159, 159, 159, 5, /* 180 */ 159, 134, 132, 133, 135, 136, 137, 141, 159, 159, /* 190 */ 6, 159, 4, 150, 138, 139, 140, 5, 159, 134, /* 200 */ 132, 133, 135, 136, 137, 141, 159, 159, 6, 146, /* 210 */ 4, 159, 138, 139, 140, 5, 159, 134, 132, 133, /* 220 */ 135, 136, 137, 141, 159, 159, 6, 159, 4, 159, /* 230 */ 138, 139, 140, 5, 222, 197, 196, 198, 199, 210, /* 240 */ 211, 212, 159, 159, 10, 159, 159, 159, 138, 139, /* 250 */ 140, 159, 13, 197, 196, 198, 199, 210, 211, 212, /* 260 */ 159, 220, 22, 194, 197, 196, 198, 199, 210, 211, /* 270 */ 212, 158, 16, 162, 164, 165, 166, 23, 159, 159, /* 280 */ 159, 170, 159, 224, 197, 196, 198, 199, 210, 211, /* 290 */ 212, 26, 197, 196, 198, 199, 210, 211, 212, 159, /* 300 */ 159, 181, 197, 196, 198, 199, 210, 211, 212, 221, /* 310 */ 197, 196, 198, 199, 210, 211, 212, 223, 197, 196, /* 320 */ 198, 199, 210, 211, 212, 195, 197, 196, 198, 199, /* 330 */ 210, 211, 212, 163, 164, 165, 166, 23, 159, 159, /* 340 */ 159, 170, }; static const YYCODETYPE yy_lookahead[] = { /* 0 */ 48, 1, 2, 3, 4, 5, 6, 7, 45, 45, /* 10 */ 10, 9, 12, 1, 8, 8, 14, 17, 13, 14, /* 20 */ 20, 14, 15, 15, 15, 9, 18, 27, 28, 29, /* 30 */ 30, 31, 32, 33, 34, 42, 43, 44, 45, 46, /* 40 */ 47, 14, 49, 50, 14, 52, 53, 54, 55, 56, /* 50 */ 57, 58, 59, 42, 43, 44, 45, 46, 47, 8, /* 60 */ 49, 50, 15, 52, 53, 54, 55, 56, 57, 58, /* 70 */ 59, 1, 2, 3, 4, 5, 6, 7, 63, 63, /* 80 */ 10, 63, 12, 13, 14, 63, 63, 17, 52, 53, /* 90 */ 54, 55, 56, 57, 58, 59, 60, 61, 0, 1, /* 100 */ 0, 1, 32, 33, 34, 1, 2, 3, 4, 5, /* 110 */ 6, 7, 63, 63, 10, 11, 12, 19, 14, 19, /* 120 */ 63, 17, 63, 52, 53, 54, 55, 56, 57, 58, /* 130 */ 59, 63, 63, 62, 63, 63, 32, 33, 34, 63, /* 140 */ 21, 22, 23, 24, 25, 26, 63, 44, 45, 46, /* 150 */ 47, 63, 49, 50, 63, 52, 53, 54, 55, 56, /* 160 */ 57, 58, 59, 1, 2, 3, 4, 5, 6, 7, /* 170 */ 63, 63, 10, 63, 12, 13, 63, 63, 63, 17, /* 180 */ 63, 1, 2, 3, 4, 5, 6, 7, 63, 63, /* 190 */ 10, 63, 12, 13, 32, 33, 34, 17, 63, 1, /* 200 */ 2, 3, 4, 5, 6, 7, 63, 63, 10, 11, /* 210 */ 12, 63, 32, 33, 34, 17, 63, 1, 2, 3, /* 220 */ 4, 5, 6, 7, 63, 63, 10, 63, 12, 63, /* 230 */ 32, 33, 34, 17, 52, 53, 54, 55, 56, 57, /* 240 */ 58, 59, 63, 63, 62, 63, 63, 63, 32, 33, /* 250 */ 34, 63, 52, 53, 54, 55, 56, 57, 58, 59, /* 260 */ 63, 61, 51, 52, 53, 54, 55, 56, 57, 58, /* 270 */ 59, 35, 36, 37, 38, 39, 40, 41, 63, 63, /* 280 */ 63, 45, 63, 52, 53, 54, 55, 56, 57, 58, /* 290 */ 59, 52, 53, 54, 55, 56, 57, 58, 59, 63, /* 300 */ 63, 52, 53, 54, 55, 56, 57, 58, 59, 52, /* 310 */ 53, 54, 55, 56, 57, 58, 59, 52, 53, 54, /* 320 */ 55, 56, 57, 58, 59, 52, 53, 54, 55, 56, /* 330 */ 57, 58, 59, 37, 38, 39, 40, 41, 63, 63, /* 340 */ 63, 45, 35, 35, 35, 35, 35, 35, 35, 35, /* 350 */ 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, /* 360 */ 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, /* 370 */ 35, 35, 35, 35, 35, 35, 35, }; #define YY_SHIFT_COUNT (30) #define YY_SHIFT_MIN (0) #define YY_SHIFT_MAX (216) static const unsigned short int yy_shift_ofst[] = { /* 0 */ 98, 0, 0, 0, 162, 180, 198, 216, 216, 70, /* 10 */ 104, 216, 216, 216, 216, 216, 100, 119, 12, 12, /* 20 */ 7, 5, 2, 8, 9, 16, 27, 6, 51, 30, /* 30 */ 47, }; #define YY_REDUCE_COUNT (19) #define YY_REDUCE_MIN (-48) #define YY_REDUCE_MAX (296) static const short yy_reduce_ofst[] = { /* 0 */ 236, -7, 11, 103, 36, 71, 182, 200, 211, 231, /* 10 */ 231, 239, 249, 257, 265, 273, 296, -48, -37, -36, }; static const YYACTIONTYPE yy_default[] = { /* 0 */ 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, /* 10 */ 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, /* 20 */ 202, 157, 157, 157, 157, 157, 157, 157, 179, 171, /* 30 */ 157, }; /********** End of lemon-generated parsing tables *****************************/ /* The next table maps tokens (terminal symbols) into fallback tokens. ** If a construct like the following: ** ** %fallback ID X Y Z. ** ** appears in the grammar, then ID becomes a fallback token for X, Y, ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser ** but it does not parse, the type of the token is changed to ID and ** the parse is retried before an error is thrown. ** ** This feature can be used, for example, to cause some keywords in a language ** to revert to identifiers if they keyword does not apply in the context where ** it appears. */ #ifdef YYFALLBACK static const YYCODETYPE yyFallback[] = { }; #endif /* YYFALLBACK */ /* The following structure represents a single element of the ** parser's stack. Information stored includes: ** ** + The state number for the parser at this level of the stack. ** ** + The value of the token stored at this level of the stack. ** (In other words, the "major" token.) ** ** + The semantic value stored at this level of the stack. This is ** the information used by the action routines in the grammar. ** It is sometimes called the "minor" token. ** ** After the "shift" half of a SHIFTREDUCE action, the stateno field ** actually contains the reduce action for the second half of the ** SHIFTREDUCE. */ struct yyStackEntry { YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */ YYCODETYPE major; /* The major token value. This is the code ** number for the token at this stack level */ YYMINORTYPE minor; /* The user-supplied minor token value. This ** is the value of the token */ }; typedef struct yyStackEntry yyStackEntry; /* The state of the parser is completely contained in an instance of ** the following structure */ struct yyParser { yyStackEntry *yytos; /* Pointer to top element of the stack */ #ifdef YYTRACKMAXSTACKDEPTH int yyhwm; /* High-water mark of the stack */ #endif #ifndef YYNOERRORRECOVERY int yyerrcnt; /* Shifts left before out of the error */ #endif datalogParseARG_SDECL /* A place to hold %extra_argument */ datalogParseCTX_SDECL /* A place to hold %extra_context */ yyStackEntry *yystackEnd; /* Last entry in the stack */ yyStackEntry *yystack; /* The parser stack */ yyStackEntry yystk0[YYSTACKDEPTH]; /* Initial stack space */ }; typedef struct yyParser yyParser; #include #ifndef NDEBUG #include static FILE *yyTraceFILE = 0; static char *yyTracePrompt = 0; #endif /* NDEBUG */ #ifndef NDEBUG /* ** Turn parser tracing on by giving a stream to which to write the trace ** and a prompt to preface each trace message. Tracing is turned off ** by making either argument NULL ** ** Inputs: **
    **
  • A FILE* to which trace output should be written. ** If NULL, then tracing is turned off. **
  • A prefix string written at the beginning of every ** line of trace output. If NULL, then tracing is ** turned off. **
** ** Outputs: ** None. */ void datalogParseTrace(FILE *TraceFILE, char *zTracePrompt){ yyTraceFILE = TraceFILE; yyTracePrompt = zTracePrompt; if( yyTraceFILE==0 ) yyTracePrompt = 0; else if( yyTracePrompt==0 ) yyTraceFILE = 0; } #endif /* NDEBUG */ #if defined(YYCOVERAGE) || !defined(NDEBUG) /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ static const char *const yyTokenName[] = { /* 0 */ "$", /* 1 */ "ATOM", /* 2 */ "VARIABLE", /* 3 */ "UNDERSCORE", /* 4 */ "INTEGER", /* 5 */ "FLOAT", /* 6 */ "STRING", /* 7 */ "KEYWORD", /* 8 */ "LPAREN", /* 9 */ "RPAREN", /* 10 */ "LBRACKET", /* 11 */ "RBRACKET", /* 12 */ "LBRACE", /* 13 */ "RBRACE", /* 14 */ "COMMA", /* 15 */ "DOT", /* 16 */ "PIPE", /* 17 */ "HASH_LBRACE", /* 18 */ "RULE_OP", /* 19 */ "QUERY_OP", /* 20 */ "NOT_OP", /* 21 */ "NEQ_OP", /* 22 */ "EQ_OP", /* 23 */ "LT_OP", /* 24 */ "GT_OP", /* 25 */ "LTE_OP", /* 26 */ "GTE_OP", /* 27 */ "COUNT", /* 28 */ "SUM", /* 29 */ "MIN", /* 30 */ "MAX", /* 31 */ "AVG", /* 32 */ "TRUE_K", /* 33 */ "FALSE_K", /* 34 */ "NIL_K", /* 35 */ "program", /* 36 */ "clause_list", /* 37 */ "clause", /* 38 */ "fact", /* 39 */ "rule", /* 40 */ "query", /* 41 */ "head", /* 42 */ "body", /* 43 */ "literal_list", /* 44 */ "body_literal", /* 45 */ "literal", /* 46 */ "negated_literal", /* 47 */ "comparison", /* 48 */ "comp_op", /* 49 */ "aggregate_literal", /* 50 */ "aggregate_func", /* 51 */ "term_list", /* 52 */ "term", /* 53 */ "atom_term", /* 54 */ "variable_term", /* 55 */ "constant_term", /* 56 */ "edn_value", /* 57 */ "edn_vector", /* 58 */ "edn_map", /* 59 */ "edn_set", /* 60 */ "edn_map_pairs", /* 61 */ "edn_map_pair", /* 62 */ "edn_elements", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. */ static const char *const yyRuleName[] = { /* 0 */ "program ::= clause_list", /* 1 */ "program ::=", /* 2 */ "clause_list ::= clause", /* 3 */ "clause_list ::= clause_list clause", /* 4 */ "clause ::= fact", /* 5 */ "clause ::= rule", /* 6 */ "clause ::= query", /* 7 */ "fact ::= head DOT", /* 8 */ "rule ::= head RULE_OP body DOT", /* 9 */ "query ::= QUERY_OP body DOT", /* 10 */ "head ::= literal", /* 11 */ "body ::= literal_list", /* 12 */ "literal_list ::= body_literal", /* 13 */ "literal_list ::= literal_list COMMA body_literal", /* 14 */ "body_literal ::= literal", /* 15 */ "body_literal ::= negated_literal", /* 16 */ "body_literal ::= comparison", /* 17 */ "body_literal ::= aggregate_literal", /* 18 */ "literal ::= ATOM LPAREN term_list RPAREN", /* 19 */ "literal ::= ATOM", /* 20 */ "negated_literal ::= NOT_OP literal", /* 21 */ "comparison ::= term comp_op term", /* 22 */ "comp_op ::= EQ_OP", /* 23 */ "comp_op ::= NEQ_OP", /* 24 */ "comp_op ::= LT_OP", /* 25 */ "comp_op ::= GT_OP", /* 26 */ "comp_op ::= LTE_OP", /* 27 */ "comp_op ::= GTE_OP", /* 28 */ "aggregate_literal ::= aggregate_func LPAREN term COMMA literal RPAREN", /* 29 */ "aggregate_func ::= COUNT", /* 30 */ "aggregate_func ::= SUM", /* 31 */ "aggregate_func ::= MIN", /* 32 */ "aggregate_func ::= MAX", /* 33 */ "aggregate_func ::= AVG", /* 34 */ "term_list ::= term", /* 35 */ "term_list ::= term_list COMMA term", /* 36 */ "term ::= variable_term", /* 37 */ "term ::= atom_term", /* 38 */ "term ::= constant_term", /* 39 */ "term ::= edn_value", /* 40 */ "variable_term ::= VARIABLE", /* 41 */ "variable_term ::= UNDERSCORE", /* 42 */ "atom_term ::= ATOM", /* 43 */ "constant_term ::= INTEGER", /* 44 */ "constant_term ::= FLOAT", /* 45 */ "constant_term ::= STRING", /* 46 */ "constant_term ::= TRUE_K", /* 47 */ "constant_term ::= FALSE_K", /* 48 */ "constant_term ::= NIL_K", /* 49 */ "edn_value ::= KEYWORD", /* 50 */ "edn_value ::= edn_vector", /* 51 */ "edn_value ::= edn_map", /* 52 */ "edn_value ::= edn_set", /* 53 */ "edn_vector ::= LBRACKET edn_elements RBRACKET", /* 54 */ "edn_vector ::= LBRACKET RBRACKET", /* 55 */ "edn_map ::= LBRACE edn_map_pairs RBRACE", /* 56 */ "edn_map ::= LBRACE RBRACE", /* 57 */ "edn_set ::= HASH_LBRACE edn_elements RBRACE", /* 58 */ "edn_set ::= HASH_LBRACE RBRACE", /* 59 */ "edn_map_pairs ::= edn_map_pair", /* 60 */ "edn_map_pairs ::= edn_map_pairs COMMA edn_map_pair", /* 61 */ "edn_map_pair ::= term term", /* 62 */ "edn_elements ::= term", /* 63 */ "edn_elements ::= edn_elements COMMA term", /* 64 */ "edn_elements ::= edn_elements term", }; #endif /* NDEBUG */ #if YYGROWABLESTACK /* ** Try to increase the size of the parser stack. Return the number ** of errors. Return 0 on success. */ static int yyGrowStack(yyParser *p){ int oldSize = 1 + (int)(p->yystackEnd - p->yystack); int newSize; int idx; yyStackEntry *pNew; #ifdef YYSIZELIMIT int nLimit = YYSIZELIMIT(datalogParseCTX(p)); #endif newSize = oldSize*2 + 100; #ifdef YYSIZELIMIT if( newSize>nLimit ){ newSize = nLimit; if( newSize<=oldSize ) return 1; } #endif idx = (int)(p->yytos - p->yystack); if( p->yystack==p->yystk0 ){ pNew = YYREALLOC(0, newSize*sizeof(pNew[0]), datalogParseCTX(p)); if( pNew==0 ) return 1; memcpy(pNew, p->yystack, oldSize*sizeof(pNew[0])); }else{ pNew = YYREALLOC(p->yystack, newSize*sizeof(pNew[0]), datalogParseCTX(p)); if( pNew==0 ) return 1; } p->yystack = pNew; p->yytos = &p->yystack[idx]; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n", yyTracePrompt, oldSize, newSize); } #endif p->yystackEnd = &p->yystack[newSize-1]; return 0; } #endif /* YYGROWABLESTACK */ #if !YYGROWABLESTACK /* For builds that do no have a growable stack, yyGrowStack always ** returns an error. */ # define yyGrowStack(X) 1 #endif /* Datatype of the argument to the memory allocated passed as the ** second argument to datalogParseAlloc() below. This can be changed by ** putting an appropriate #define in the %include section of the input ** grammar. */ #ifndef YYMALLOCARGTYPE # define YYMALLOCARGTYPE size_t #endif /* Initialize a new parser that has already been allocated. */ void datalogParseInit(void *yypRawParser datalogParseCTX_PDECL){ yyParser *yypParser = (yyParser*)yypRawParser; datalogParseCTX_STORE #ifdef YYTRACKMAXSTACKDEPTH yypParser->yyhwm = 0; #endif yypParser->yystack = yypParser->yystk0; yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1]; #ifndef YYNOERRORRECOVERY yypParser->yyerrcnt = -1; #endif yypParser->yytos = yypParser->yystack; yypParser->yystack[0].stateno = 0; yypParser->yystack[0].major = 0; } #ifndef datalogParse_ENGINEALWAYSONSTACK /* ** This function allocates a new parser. ** The only argument is a pointer to a function which works like ** malloc. ** ** Inputs: ** A pointer to the function used to allocate memory. ** ** Outputs: ** A pointer to a parser. This pointer is used in subsequent calls ** to datalogParse and datalogParseFree. */ void *datalogParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) datalogParseCTX_PDECL){ yyParser *yypParser; yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); if( yypParser ){ datalogParseCTX_STORE datalogParseInit(yypParser datalogParseCTX_PARAM); } return (void*)yypParser; } #endif /* datalogParse_ENGINEALWAYSONSTACK */ /* The following function deletes the "minor type" or semantic value ** associated with a symbol. The symbol can be either a terminal ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is ** a pointer to the value to be deleted. The code used to do the ** deletions is derived from the %destructor and/or %token_destructor ** directives of the input grammar. */ static void yy_destructor( yyParser *yypParser, /* The parser */ YYCODETYPE yymajor, /* Type code for object to destroy */ YYMINORTYPE *yypminor /* The object to be destroyed */ ){ datalogParseARG_FETCH datalogParseCTX_FETCH switch( yymajor ){ /* Here is inserted the actions which take place when a ** terminal or non-terminal is destroyed. This can happen ** when the symbol is popped from the stack during a ** reduce or during error processing or when a parser is ** being destroyed before it is finished parsing. ** ** Note: during a reduce, the only symbols destroyed are those ** which appear on the RHS of the rule, but which are *not* used ** inside the C code. */ /********* Begin destructor definitions ***************************************/ /********* End destructor definitions *****************************************/ default: break; /* If no destructor action specified: do nothing */ } } /* ** Pop the parser's stack once. ** ** If there is a destructor routine associated with the token which ** is popped from the stack, then call it. */ static void yy_pop_parser_stack(yyParser *pParser){ yyStackEntry *yytos; assert( pParser->yytos!=0 ); assert( pParser->yytos > pParser->yystack ); yytos = pParser->yytos--; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sPopping %s\n", yyTracePrompt, yyTokenName[yytos->major]); } #endif yy_destructor(pParser, yytos->major, &yytos->minor); } /* ** Clear all secondary memory allocations from the parser */ void datalogParseFinalize(void *p){ yyParser *pParser = (yyParser*)p; /* In-lined version of calling yy_pop_parser_stack() for each ** element left in the stack */ yyStackEntry *yytos = pParser->yytos; while( yytos>pParser->yystack ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sPopping %s\n", yyTracePrompt, yyTokenName[yytos->major]); } #endif if( yytos->major>=YY_MIN_DSTRCTR ){ yy_destructor(pParser, yytos->major, &yytos->minor); } yytos--; } #if YYGROWABLESTACK if( pParser->yystack!=pParser->yystk0 ){ YYFREE(pParser->yystack, datalogParseCTX(pParser)); } #endif } #ifndef datalogParse_ENGINEALWAYSONSTACK /* ** Deallocate and destroy a parser. Destructors are called for ** all stack elements before shutting the parser down. ** ** If the YYPARSEFREENEVERNULL macro exists (for example because it ** is defined in a %include section of the input grammar) then it is ** assumed that the input pointer is never NULL. */ void datalogParseFree( void *p, /* The parser to be deleted */ void (*freeProc)(void*) /* Function used to reclaim memory */ ){ #ifndef YYPARSEFREENEVERNULL if( p==0 ) return; #endif datalogParseFinalize(p); (*freeProc)(p); } #endif /* datalogParse_ENGINEALWAYSONSTACK */ /* ** Return the peak depth of the stack for a parser. */ #ifdef YYTRACKMAXSTACKDEPTH int datalogParseStackPeak(void *p){ yyParser *pParser = (yyParser*)p; return pParser->yyhwm; } #endif /* This array of booleans keeps track of the parser statement ** coverage. The element yycoverage[X][Y] is set when the parser ** is in state X and has a lookahead token Y. In a well-tested ** systems, every element of this matrix should end up being set. */ #if defined(YYCOVERAGE) static unsigned char yycoverage[YYNSTATE][YYNTOKEN]; #endif /* ** Write into out a description of every state/lookahead combination that ** ** (1) has not been used by the parser, and ** (2) is not a syntax error. ** ** Return the number of missed state/lookahead combinations. */ #if defined(YYCOVERAGE) int datalogParseCoverage(FILE *out){ int stateno, iLookAhead, i; int nMissed = 0; for(stateno=0; statenoYY_MAX_SHIFT ) return stateno; assert( stateno <= YY_SHIFT_COUNT ); #if defined(YYCOVERAGE) yycoverage[stateno][iLookAhead] = 1; #endif do{ i = yy_shift_ofst[stateno]; assert( i>=0 ); assert( i<=YY_ACTTAB_COUNT ); assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); assert( iLookAhead!=YYNOCODE ); assert( iLookAhead < YYNTOKEN ); i += iLookAhead; assert( i<(int)YY_NLOOKAHEAD ); if( yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ assert( iLookAhead %s\n", yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); } #endif assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ iLookAhead = iFallback; continue; } #endif #ifdef YYWILDCARD { int j = i - iLookAhead + YYWILDCARD; assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); } #endif /* NDEBUG */ return yy_action[j]; } } #endif /* YYWILDCARD */ return yy_default[stateno]; }else{ assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) ); return yy_action[i]; } }while(1); } /* ** Find the appropriate action for a parser given the non-terminal ** look-ahead token iLookAhead. */ static YYACTIONTYPE yy_find_reduce_action( YYACTIONTYPE stateno, /* Current state number */ YYCODETYPE iLookAhead /* The look-ahead token */ ){ int i; #ifdef YYERRORSYMBOL if( stateno>YY_REDUCE_COUNT ){ return yy_default[stateno]; } #else assert( stateno<=YY_REDUCE_COUNT ); #endif i = yy_reduce_ofst[stateno]; assert( iLookAhead!=YYNOCODE ); i += iLookAhead; #ifdef YYERRORSYMBOL if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ return yy_default[stateno]; } #else assert( i>=0 && iyytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will execute if the parser ** stack every overflows */ /******** Begin %stack_overflow code ******************************************/ /******** End %stack_overflow code ********************************************/ datalogParseARG_STORE /* Suppress warning about unused %extra_argument var */ datalogParseCTX_STORE } /* ** Print tracing information for a SHIFT action */ #ifndef NDEBUG static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){ if( yyTraceFILE ){ if( yyNewStateyytos->major], yyNewState); }else{ fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n", yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], yyNewState - YY_MIN_REDUCE); } } } #else # define yyTraceShift(X,Y,Z) #endif /* ** Perform a shift action. */ static void yy_shift( yyParser *yypParser, /* The parser to be shifted */ YYACTIONTYPE yyNewState, /* The new state to shift in */ YYCODETYPE yyMajor, /* The major token to shift in */ datalogParseTOKENTYPE yyMinor /* The minor token to shift in */ ){ yyStackEntry *yytos; yypParser->yytos++; #ifdef YYTRACKMAXSTACKDEPTH if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ yypParser->yyhwm++; assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) ); } #endif yytos = yypParser->yytos; if( yytos>yypParser->yystackEnd ){ if( yyGrowStack(yypParser) ){ yypParser->yytos--; yyStackOverflow(yypParser); return; } yytos = yypParser->yytos; assert( yytos <= yypParser->yystackEnd ); } if( yyNewState > YY_MAX_SHIFT ){ yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; } yytos->stateno = yyNewState; yytos->major = yyMajor; yytos->minor.yy0 = yyMinor; yyTraceShift(yypParser, yyNewState, "Shift"); } /* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side ** of that rule */ static const YYCODETYPE yyRuleInfoLhs[] = { 35, /* (0) program ::= clause_list */ 35, /* (1) program ::= */ 36, /* (2) clause_list ::= clause */ 36, /* (3) clause_list ::= clause_list clause */ 37, /* (4) clause ::= fact */ 37, /* (5) clause ::= rule */ 37, /* (6) clause ::= query */ 38, /* (7) fact ::= head DOT */ 39, /* (8) rule ::= head RULE_OP body DOT */ 40, /* (9) query ::= QUERY_OP body DOT */ 41, /* (10) head ::= literal */ 42, /* (11) body ::= literal_list */ 43, /* (12) literal_list ::= body_literal */ 43, /* (13) literal_list ::= literal_list COMMA body_literal */ 44, /* (14) body_literal ::= literal */ 44, /* (15) body_literal ::= negated_literal */ 44, /* (16) body_literal ::= comparison */ 44, /* (17) body_literal ::= aggregate_literal */ 45, /* (18) literal ::= ATOM LPAREN term_list RPAREN */ 45, /* (19) literal ::= ATOM */ 46, /* (20) negated_literal ::= NOT_OP literal */ 47, /* (21) comparison ::= term comp_op term */ 48, /* (22) comp_op ::= EQ_OP */ 48, /* (23) comp_op ::= NEQ_OP */ 48, /* (24) comp_op ::= LT_OP */ 48, /* (25) comp_op ::= GT_OP */ 48, /* (26) comp_op ::= LTE_OP */ 48, /* (27) comp_op ::= GTE_OP */ 49, /* (28) aggregate_literal ::= aggregate_func LPAREN term COMMA literal RPAREN */ 50, /* (29) aggregate_func ::= COUNT */ 50, /* (30) aggregate_func ::= SUM */ 50, /* (31) aggregate_func ::= MIN */ 50, /* (32) aggregate_func ::= MAX */ 50, /* (33) aggregate_func ::= AVG */ 51, /* (34) term_list ::= term */ 51, /* (35) term_list ::= term_list COMMA term */ 52, /* (36) term ::= variable_term */ 52, /* (37) term ::= atom_term */ 52, /* (38) term ::= constant_term */ 52, /* (39) term ::= edn_value */ 54, /* (40) variable_term ::= VARIABLE */ 54, /* (41) variable_term ::= UNDERSCORE */ 53, /* (42) atom_term ::= ATOM */ 55, /* (43) constant_term ::= INTEGER */ 55, /* (44) constant_term ::= FLOAT */ 55, /* (45) constant_term ::= STRING */ 55, /* (46) constant_term ::= TRUE_K */ 55, /* (47) constant_term ::= FALSE_K */ 55, /* (48) constant_term ::= NIL_K */ 56, /* (49) edn_value ::= KEYWORD */ 56, /* (50) edn_value ::= edn_vector */ 56, /* (51) edn_value ::= edn_map */ 56, /* (52) edn_value ::= edn_set */ 57, /* (53) edn_vector ::= LBRACKET edn_elements RBRACKET */ 57, /* (54) edn_vector ::= LBRACKET RBRACKET */ 58, /* (55) edn_map ::= LBRACE edn_map_pairs RBRACE */ 58, /* (56) edn_map ::= LBRACE RBRACE */ 59, /* (57) edn_set ::= HASH_LBRACE edn_elements RBRACE */ 59, /* (58) edn_set ::= HASH_LBRACE RBRACE */ 60, /* (59) edn_map_pairs ::= edn_map_pair */ 60, /* (60) edn_map_pairs ::= edn_map_pairs COMMA edn_map_pair */ 61, /* (61) edn_map_pair ::= term term */ 62, /* (62) edn_elements ::= term */ 62, /* (63) edn_elements ::= edn_elements COMMA term */ 62, /* (64) edn_elements ::= edn_elements term */ }; /* For rule J, yyRuleInfoNRhs[J] contains the negative of the number ** of symbols on the right-hand side of that rule. */ static const signed char yyRuleInfoNRhs[] = { -1, /* (0) program ::= clause_list */ 0, /* (1) program ::= */ -1, /* (2) clause_list ::= clause */ -2, /* (3) clause_list ::= clause_list clause */ -1, /* (4) clause ::= fact */ -1, /* (5) clause ::= rule */ -1, /* (6) clause ::= query */ -2, /* (7) fact ::= head DOT */ -4, /* (8) rule ::= head RULE_OP body DOT */ -3, /* (9) query ::= QUERY_OP body DOT */ -1, /* (10) head ::= literal */ -1, /* (11) body ::= literal_list */ -1, /* (12) literal_list ::= body_literal */ -3, /* (13) literal_list ::= literal_list COMMA body_literal */ -1, /* (14) body_literal ::= literal */ -1, /* (15) body_literal ::= negated_literal */ -1, /* (16) body_literal ::= comparison */ -1, /* (17) body_literal ::= aggregate_literal */ -4, /* (18) literal ::= ATOM LPAREN term_list RPAREN */ -1, /* (19) literal ::= ATOM */ -2, /* (20) negated_literal ::= NOT_OP literal */ -3, /* (21) comparison ::= term comp_op term */ -1, /* (22) comp_op ::= EQ_OP */ -1, /* (23) comp_op ::= NEQ_OP */ -1, /* (24) comp_op ::= LT_OP */ -1, /* (25) comp_op ::= GT_OP */ -1, /* (26) comp_op ::= LTE_OP */ -1, /* (27) comp_op ::= GTE_OP */ -6, /* (28) aggregate_literal ::= aggregate_func LPAREN term COMMA literal RPAREN */ -1, /* (29) aggregate_func ::= COUNT */ -1, /* (30) aggregate_func ::= SUM */ -1, /* (31) aggregate_func ::= MIN */ -1, /* (32) aggregate_func ::= MAX */ -1, /* (33) aggregate_func ::= AVG */ -1, /* (34) term_list ::= term */ -3, /* (35) term_list ::= term_list COMMA term */ -1, /* (36) term ::= variable_term */ -1, /* (37) term ::= atom_term */ -1, /* (38) term ::= constant_term */ -1, /* (39) term ::= edn_value */ -1, /* (40) variable_term ::= VARIABLE */ -1, /* (41) variable_term ::= UNDERSCORE */ -1, /* (42) atom_term ::= ATOM */ -1, /* (43) constant_term ::= INTEGER */ -1, /* (44) constant_term ::= FLOAT */ -1, /* (45) constant_term ::= STRING */ -1, /* (46) constant_term ::= TRUE_K */ -1, /* (47) constant_term ::= FALSE_K */ -1, /* (48) constant_term ::= NIL_K */ -1, /* (49) edn_value ::= KEYWORD */ -1, /* (50) edn_value ::= edn_vector */ -1, /* (51) edn_value ::= edn_map */ -1, /* (52) edn_value ::= edn_set */ -3, /* (53) edn_vector ::= LBRACKET edn_elements RBRACKET */ -2, /* (54) edn_vector ::= LBRACKET RBRACKET */ -3, /* (55) edn_map ::= LBRACE edn_map_pairs RBRACE */ -2, /* (56) edn_map ::= LBRACE RBRACE */ -3, /* (57) edn_set ::= HASH_LBRACE edn_elements RBRACE */ -2, /* (58) edn_set ::= HASH_LBRACE RBRACE */ -1, /* (59) edn_map_pairs ::= edn_map_pair */ -3, /* (60) edn_map_pairs ::= edn_map_pairs COMMA edn_map_pair */ -2, /* (61) edn_map_pair ::= term term */ -1, /* (62) edn_elements ::= term */ -3, /* (63) edn_elements ::= edn_elements COMMA term */ -2, /* (64) edn_elements ::= edn_elements term */ }; static void yy_accept(yyParser*); /* Forward Declaration */ /* ** Perform a reduce action and the shift that must immediately ** follow the reduce. ** ** The yyLookahead and yyLookaheadToken parameters provide reduce actions ** access to the lookahead token (if any). The yyLookahead will be YYNOCODE ** if the lookahead token has already been consumed. As this procedure is ** only called from one place, optimizing compilers will in-line it, which ** means that the extra parameters have no performance impact. */ static YYACTIONTYPE yy_reduce( yyParser *yypParser, /* The parser */ unsigned int yyruleno, /* Number of the rule by which to reduce */ int yyLookahead, /* Lookahead token, or YYNOCODE if none */ datalogParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ datalogParseCTX_PDECL /* %extra_context */ ){ int yygoto; /* The next state */ YYACTIONTYPE yyact; /* The next action */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ datalogParseARG_FETCH (void)yyLookahead; (void)yyLookaheadToken; yymsp = yypParser->yytos; switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example ** follows: ** case 0: ** #line ** { ... } // User supplied code ** #line ** break; */ /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* program ::= clause_list */ #line 218 "datalog.lime" { yylhsminor.yy87 = dl_make_program(pstate, yymsp[0].minor.yy34); } #line 1225 "datalog.c" yymsp[0].minor.yy87 = yylhsminor.yy87; break; case 1: /* program ::= */ #line 222 "datalog.lime" { yymsp[1].minor.yy87 = dl_make_program(pstate, NULL); } #line 1233 "datalog.c" break; case 2: /* clause_list ::= clause */ #line 228 "datalog.lime" { yylhsminor.yy34 = dl_clause_list_create(yymsp[0].minor.yy50); } #line 1240 "datalog.c" yymsp[0].minor.yy34 = yylhsminor.yy34; break; case 3: /* clause_list ::= clause_list clause */ #line 232 "datalog.lime" { yylhsminor.yy34 = dl_clause_list_append(yymsp[-1].minor.yy34, yymsp[0].minor.yy50); } #line 1248 "datalog.c" yymsp[-1].minor.yy34 = yylhsminor.yy34; break; case 4: /* clause ::= fact */ case 5: /* clause ::= rule */ yytestcase(yyruleno==5); case 6: /* clause ::= query */ yytestcase(yyruleno==6); #line 238 "datalog.lime" { yylhsminor.yy50 = yymsp[0].minor.yy50; } #line 1256 "datalog.c" yymsp[0].minor.yy50 = yylhsminor.yy50; break; case 7: /* fact ::= head DOT */ #line 249 "datalog.lime" { yylhsminor.yy50 = dl_make_fact(pstate, yymsp[-1].minor.yy110); } #line 1264 "datalog.c" yymsp[-1].minor.yy50 = yylhsminor.yy50; break; case 8: /* rule ::= head RULE_OP body DOT */ #line 260 "datalog.lime" { yylhsminor.yy50 = dl_make_rule(pstate, yymsp[-3].minor.yy110, yymsp[-1].minor.yy90); } #line 1272 "datalog.c" yymsp[-3].minor.yy50 = yylhsminor.yy50; break; case 9: /* query ::= QUERY_OP body DOT */ #line 270 "datalog.lime" { yymsp[-2].minor.yy50 = dl_make_query(pstate, yymsp[-1].minor.yy90); } #line 1280 "datalog.c" break; case 10: /* head ::= literal */ #line 276 "datalog.lime" { yylhsminor.yy110 = yymsp[0].minor.yy110; } #line 1287 "datalog.c" yymsp[0].minor.yy110 = yylhsminor.yy110; break; case 11: /* body ::= literal_list */ #line 282 "datalog.lime" { yylhsminor.yy90 = yymsp[0].minor.yy90; } #line 1295 "datalog.c" yymsp[0].minor.yy90 = yylhsminor.yy90; break; case 12: /* literal_list ::= body_literal */ #line 288 "datalog.lime" { yylhsminor.yy90 = dl_literal_list_create(yymsp[0].minor.yy110); } #line 1303 "datalog.c" yymsp[0].minor.yy90 = yylhsminor.yy90; break; case 13: /* literal_list ::= literal_list COMMA body_literal */ #line 292 "datalog.lime" { yylhsminor.yy90 = dl_literal_list_append(yymsp[-2].minor.yy90, yymsp[0].minor.yy110); } #line 1311 "datalog.c" yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 14: /* body_literal ::= literal */ case 15: /* body_literal ::= negated_literal */ yytestcase(yyruleno==15); case 16: /* body_literal ::= comparison */ yytestcase(yyruleno==16); case 17: /* body_literal ::= aggregate_literal */ yytestcase(yyruleno==17); #line 298 "datalog.lime" { yylhsminor.yy110 = yymsp[0].minor.yy110; } #line 1320 "datalog.c" yymsp[0].minor.yy110 = yylhsminor.yy110; break; case 18: /* literal ::= ATOM LPAREN term_list RPAREN */ #line 309 "datalog.lime" { yylhsminor.yy110 = dl_make_literal(pstate, yymsp[-3].minor.yy0.str, yymsp[-1].minor.yy89); } #line 1328 "datalog.c" yymsp[-3].minor.yy110 = yylhsminor.yy110; break; case 19: /* literal ::= ATOM */ #line 314 "datalog.lime" { yylhsminor.yy110 = dl_make_literal(pstate, yymsp[0].minor.yy0.str, NULL); } #line 1336 "datalog.c" yymsp[0].minor.yy110 = yylhsminor.yy110; break; case 20: /* negated_literal ::= NOT_OP literal */ #line 323 "datalog.lime" { yymsp[-1].minor.yy110 = dl_make_negated(pstate, yymsp[0].minor.yy110); } #line 1344 "datalog.c" break; case 21: /* comparison ::= term comp_op term */ #line 334 "datalog.lime" { yylhsminor.yy110 = dl_make_comparison(pstate, yymsp[-1].minor.yy61, yymsp[-2].minor.yy105, yymsp[0].minor.yy105); } #line 1351 "datalog.c" yymsp[-2].minor.yy110 = yylhsminor.yy110; break; case 22: /* comp_op ::= EQ_OP */ #line 338 "datalog.lime" { yymsp[0].minor.yy61 = DL_COMP_EQ; } #line 1357 "datalog.c" break; case 23: /* comp_op ::= NEQ_OP */ #line 339 "datalog.lime" { yymsp[0].minor.yy61 = DL_COMP_NEQ; } #line 1362 "datalog.c" break; case 24: /* comp_op ::= LT_OP */ #line 340 "datalog.lime" { yymsp[0].minor.yy61 = DL_COMP_LT; } #line 1367 "datalog.c" break; case 25: /* comp_op ::= GT_OP */ #line 341 "datalog.lime" { yymsp[0].minor.yy61 = DL_COMP_GT; } #line 1372 "datalog.c" break; case 26: /* comp_op ::= LTE_OP */ #line 342 "datalog.lime" { yymsp[0].minor.yy61 = DL_COMP_LTE; } #line 1377 "datalog.c" break; case 27: /* comp_op ::= GTE_OP */ #line 343 "datalog.lime" { yymsp[0].minor.yy61 = DL_COMP_GTE; } #line 1382 "datalog.c" break; case 28: /* aggregate_literal ::= aggregate_func LPAREN term COMMA literal RPAREN */ #line 351 "datalog.lime" { yylhsminor.yy110 = dl_make_aggregate(pstate, yymsp[-5].minor.yy96, yymsp[-3].minor.yy105, yymsp[-1].minor.yy110); } #line 1389 "datalog.c" yymsp[-5].minor.yy110 = yylhsminor.yy110; break; case 29: /* aggregate_func ::= COUNT */ #line 355 "datalog.lime" { yymsp[0].minor.yy96 = DL_AGG_COUNT; } #line 1395 "datalog.c" break; case 30: /* aggregate_func ::= SUM */ #line 356 "datalog.lime" { yymsp[0].minor.yy96 = DL_AGG_SUM; } #line 1400 "datalog.c" break; case 31: /* aggregate_func ::= MIN */ #line 357 "datalog.lime" { yymsp[0].minor.yy96 = DL_AGG_MIN; } #line 1405 "datalog.c" break; case 32: /* aggregate_func ::= MAX */ #line 358 "datalog.lime" { yymsp[0].minor.yy96 = DL_AGG_MAX; } #line 1410 "datalog.c" break; case 33: /* aggregate_func ::= AVG */ #line 359 "datalog.lime" { yymsp[0].minor.yy96 = DL_AGG_AVG; } #line 1415 "datalog.c" break; case 34: /* term_list ::= term */ case 62: /* edn_elements ::= term */ yytestcase(yyruleno==62); #line 363 "datalog.lime" { yylhsminor.yy89 = dl_term_list_create(yymsp[0].minor.yy105); } #line 1423 "datalog.c" yymsp[0].minor.yy89 = yylhsminor.yy89; break; case 35: /* term_list ::= term_list COMMA term */ case 63: /* edn_elements ::= edn_elements COMMA term */ yytestcase(yyruleno==63); #line 367 "datalog.lime" { yylhsminor.yy89 = dl_term_list_append(yymsp[-2].minor.yy89, yymsp[0].minor.yy105); } #line 1432 "datalog.c" yymsp[-2].minor.yy89 = yylhsminor.yy89; break; case 36: /* term ::= variable_term */ case 37: /* term ::= atom_term */ yytestcase(yyruleno==37); case 38: /* term ::= constant_term */ yytestcase(yyruleno==38); case 39: /* term ::= edn_value */ yytestcase(yyruleno==39); case 50: /* edn_value ::= edn_vector */ yytestcase(yyruleno==50); case 51: /* edn_value ::= edn_map */ yytestcase(yyruleno==51); case 52: /* edn_value ::= edn_set */ yytestcase(yyruleno==52); #line 378 "datalog.lime" { yylhsminor.yy105 = yymsp[0].minor.yy105; } #line 1444 "datalog.c" yymsp[0].minor.yy105 = yylhsminor.yy105; break; case 40: /* variable_term ::= VARIABLE */ #line 390 "datalog.lime" { yylhsminor.yy105 = dl_make_variable(pstate, yymsp[0].minor.yy0.str); } #line 1452 "datalog.c" yymsp[0].minor.yy105 = yylhsminor.yy105; break; case 41: /* variable_term ::= UNDERSCORE */ #line 394 "datalog.lime" { yymsp[0].minor.yy105 = dl_make_anon_variable(pstate); } #line 1460 "datalog.c" break; case 42: /* atom_term ::= ATOM */ #line 403 "datalog.lime" { yylhsminor.yy105 = dl_make_atom(pstate, yymsp[0].minor.yy0.str); } #line 1467 "datalog.c" yymsp[0].minor.yy105 = yylhsminor.yy105; break; case 43: /* constant_term ::= INTEGER */ #line 409 "datalog.lime" { yylhsminor.yy105 = dl_make_integer(pstate, yymsp[0].minor.yy0.str); } #line 1475 "datalog.c" yymsp[0].minor.yy105 = yylhsminor.yy105; break; case 44: /* constant_term ::= FLOAT */ #line 413 "datalog.lime" { yylhsminor.yy105 = dl_make_float(pstate, yymsp[0].minor.yy0.str); } #line 1483 "datalog.c" yymsp[0].minor.yy105 = yylhsminor.yy105; break; case 45: /* constant_term ::= STRING */ #line 417 "datalog.lime" { yylhsminor.yy105 = dl_make_string(pstate, yymsp[0].minor.yy0.str); } #line 1491 "datalog.c" yymsp[0].minor.yy105 = yylhsminor.yy105; break; case 46: /* constant_term ::= TRUE_K */ #line 421 "datalog.lime" { yymsp[0].minor.yy105 = dl_make_boolean(pstate, 1); } #line 1499 "datalog.c" break; case 47: /* constant_term ::= FALSE_K */ #line 425 "datalog.lime" { yymsp[0].minor.yy105 = dl_make_boolean(pstate, 0); } #line 1506 "datalog.c" break; case 48: /* constant_term ::= NIL_K */ #line 429 "datalog.lime" { yymsp[0].minor.yy105 = dl_make_nil(pstate); } #line 1513 "datalog.c" break; case 49: /* edn_value ::= KEYWORD */ #line 445 "datalog.lime" { yylhsminor.yy105 = dl_make_keyword(pstate, yymsp[0].minor.yy0.str); } #line 1520 "datalog.c" yymsp[0].minor.yy105 = yylhsminor.yy105; break; case 53: /* edn_vector ::= LBRACKET edn_elements RBRACKET */ #line 455 "datalog.lime" { yymsp[-2].minor.yy105 = dl_make_vector(pstate, yymsp[-1].minor.yy89); } #line 1528 "datalog.c" break; case 54: /* edn_vector ::= LBRACKET RBRACKET */ #line 459 "datalog.lime" { yymsp[-1].minor.yy105 = dl_make_vector(pstate, NULL); } #line 1535 "datalog.c" break; case 55: /* edn_map ::= LBRACE edn_map_pairs RBRACE */ #line 465 "datalog.lime" { yymsp[-2].minor.yy105 = dl_make_map(pstate, yymsp[-1].minor.yy89); } #line 1542 "datalog.c" break; case 56: /* edn_map ::= LBRACE RBRACE */ #line 469 "datalog.lime" { yymsp[-1].minor.yy105 = dl_make_map(pstate, NULL); } #line 1549 "datalog.c" break; case 57: /* edn_set ::= HASH_LBRACE edn_elements RBRACE */ #line 475 "datalog.lime" { yymsp[-2].minor.yy105 = dl_make_set(pstate, yymsp[-1].minor.yy89); } #line 1556 "datalog.c" break; case 58: /* edn_set ::= HASH_LBRACE RBRACE */ #line 479 "datalog.lime" { yymsp[-1].minor.yy105 = dl_make_set(pstate, NULL); } #line 1563 "datalog.c" break; case 59: /* edn_map_pairs ::= edn_map_pair */ #line 485 "datalog.lime" { yylhsminor.yy89 = yymsp[0].minor.yy89; } #line 1570 "datalog.c" yymsp[0].minor.yy89 = yylhsminor.yy89; break; case 60: /* edn_map_pairs ::= edn_map_pairs COMMA edn_map_pair */ #line 489 "datalog.lime" { yylhsminor.yy89 = dl_term_list_concat(yymsp[-2].minor.yy89, yymsp[0].minor.yy89); } #line 1578 "datalog.c" yymsp[-2].minor.yy89 = yylhsminor.yy89; break; case 61: /* edn_map_pair ::= term term */ #line 494 "datalog.lime" { yylhsminor.yy89 = dl_term_list_create(yymsp[-1].minor.yy105); yylhsminor.yy89 = dl_term_list_append(yylhsminor.yy89, yymsp[0].minor.yy105); } #line 1587 "datalog.c" yymsp[-1].minor.yy89 = yylhsminor.yy89; break; case 64: /* edn_elements ::= edn_elements term */ #line 509 "datalog.lime" { yylhsminor.yy89 = dl_term_list_append(yymsp[-1].minor.yy89, yymsp[0].minor.yy105); } #line 1595 "datalog.c" yymsp[-1].minor.yy89 = yylhsminor.yy89; break; default: break; /********** End reduce actions ************************************************/ }; assert( yyrulenoYY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) ); /* It is not possible for a REDUCE to be followed by an error */ assert( yyact!=YY_ERROR_ACTION ); yymsp += yysize+1; yypParser->yytos = yymsp; yymsp->stateno = (YYACTIONTYPE)yyact; yymsp->major = (YYCODETYPE)yygoto; yyTraceShift(yypParser, yyact, "... then shift"); return yyact; } /* ** The following code executes when the parse fails */ #ifndef YYNOERRORRECOVERY static void yy_parse_failed( yyParser *yypParser /* The parser */ ){ datalogParseARG_FETCH datalogParseCTX_FETCH #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); } #endif while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will be executed whenever the ** parser fails */ /************ Begin %parse_failure code ***************************************/ #line 95 "datalog.lime" pstate->error = 1; if (pstate->errMsg == NULL) { pstate->errMsg = "Datalog parse failure"; } #line 1646 "datalog.c" /************ End %parse_failure code *****************************************/ datalogParseARG_STORE /* Suppress warning about unused %extra_argument variable */ datalogParseCTX_STORE } #endif /* YYNOERRORRECOVERY */ /* ** The following code executes when a syntax error first occurs. */ static void yy_syntax_error( yyParser *yypParser, /* The parser */ int yymajor, /* The major type of the error token */ datalogParseTOKENTYPE yyminor /* The minor type of the error token */ ){ datalogParseARG_FETCH datalogParseCTX_FETCH #define TOKEN yyminor /************ Begin %syntax_error code ****************************************/ #line 88 "datalog.lime" pstate->error = 1; if (pstate->errMsg == NULL) { pstate->errMsg = "syntax error in Datalog program"; } #line 1671 "datalog.c" /************ End %syntax_error code ******************************************/ datalogParseARG_STORE /* Suppress warning about unused %extra_argument variable */ datalogParseCTX_STORE } /* ** The following is executed when the parser accepts */ static void yy_accept( yyParser *yypParser /* The parser */ ){ datalogParseARG_FETCH datalogParseCTX_FETCH #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); } #endif #ifndef YYNOERRORRECOVERY yypParser->yyerrcnt = -1; #endif assert( yypParser->yytos==yypParser->yystack ); /* Here code is inserted which will be executed whenever the ** parser accepts */ /*********** Begin %parse_accept code *****************************************/ /*********** End %parse_accept code *******************************************/ datalogParseARG_STORE /* Suppress warning about unused %extra_argument variable */ datalogParseCTX_STORE } /* The main parser program. ** The first argument is a pointer to a structure obtained from ** "datalogParseAlloc" which describes the current state of the parser. ** The second argument is the major token number. The third is ** the minor token. The fourth optional argument is whatever the ** user wants (and specified in the grammar) and is available for ** use by the action routines. ** ** Inputs: **
    **
  • A pointer to the parser (an opaque structure.) **
  • The major token number. **
  • The minor token number. **
  • An option argument of a grammar-specified type. **
** ** Outputs: ** None. */ void datalogParse( void *yyp, /* The parser */ int yymajor, /* The major token code number */ datalogParseTOKENTYPE yyminor /* The value for the token */ datalogParseARG_PDECL /* Optional %extra_argument parameter */ ){ YYMINORTYPE yyminorunion; YYACTIONTYPE yyact; /* The parser action. */ #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) int yyendofinput; /* True if we are at the end of input */ #endif #ifdef YYERRORSYMBOL int yyerrorhit = 0; /* True if yymajor has invoked an error */ #endif yyParser *yypParser = (yyParser*)yyp; /* The parser */ datalogParseCTX_FETCH datalogParseARG_STORE assert( yypParser->yytos!=0 ); #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) yyendofinput = (yymajor==0); #endif yyact = yypParser->yytos->stateno; #ifndef NDEBUG if( yyTraceFILE ){ if( yyact < YY_MIN_REDUCE ){ fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", yyTracePrompt,yyTokenName[yymajor],yyact); }else{ fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE); } } #endif while(1){ /* Exit by "break" */ assert( yypParser->yytos>=yypParser->yystack ); assert( yyact==yypParser->yytos->stateno ); yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); if( yyact >= YY_MIN_REDUCE ){ unsigned int yyruleno = yyact - YY_MIN_REDUCE; /* Reduce by this rule */ #ifndef NDEBUG assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ); if( yyTraceFILE ){ int yysize = yyRuleInfoNRhs[yyruleno]; if( yysize ){ fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", yyTracePrompt, yyruleno, yyRuleName[yyruleno], yyrulenoyytos[yysize].stateno); }else{ fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n", yyTracePrompt, yyruleno, yyRuleName[yyruleno], yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ yypParser->yyhwm++; assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack)); } #endif if( yypParser->yytos>=yypParser->yystackEnd ){ if( yyGrowStack(yypParser) ){ yyStackOverflow(yypParser); break; } } } yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor datalogParseCTX_PARAM); }else if( yyact <= YY_MAX_SHIFTREDUCE ){ yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor); #ifndef YYNOERRORRECOVERY yypParser->yyerrcnt--; #endif break; }else if( yyact==YY_ACCEPT_ACTION ){ yypParser->yytos--; yy_accept(yypParser); return; }else{ assert( yyact == YY_ERROR_ACTION ); yyminorunion.yy0 = yyminor; #ifdef YYERRORSYMBOL int yymx; #endif #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); } #endif #ifdef YYERRORSYMBOL /* A syntax error has occurred. ** The response to an error depends upon whether or not the ** grammar defines an error token "ERROR". ** ** This is what we do if the grammar does define ERROR: ** ** * Call the %syntax_error function. ** ** * Begin popping the stack until we enter a state where ** it is legal to shift the error symbol, then shift ** the error symbol. ** ** * Set the error count to three. ** ** * Begin accepting and shifting new tokens. No new error ** processing will occur until three tokens have been ** shifted successfully. ** */ if( yypParser->yyerrcnt<0 ){ yy_syntax_error(yypParser,yymajor,yyminor); } yymx = yypParser->yytos->major; if( yymx==YYERRORSYMBOL || yyerrorhit ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sDiscard input token %s\n", yyTracePrompt,yyTokenName[yymajor]); } #endif yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion); yymajor = YYNOCODE; }else{ while( yypParser->yytos > yypParser->yystack ){ yyact = yy_find_reduce_action(yypParser->yytos->stateno, YYERRORSYMBOL); if( yyact<=YY_MAX_SHIFTREDUCE ) break; yy_pop_parser_stack(yypParser); } if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){ yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yy_parse_failed(yypParser); #ifndef YYNOERRORRECOVERY yypParser->yyerrcnt = -1; #endif yymajor = YYNOCODE; }else if( yymx!=YYERRORSYMBOL ){ yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor); } } yypParser->yyerrcnt = 3; yyerrorhit = 1; if( yymajor==YYNOCODE ) break; yyact = yypParser->yytos->stateno; #elif defined(YYNOERRORRECOVERY) /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to ** do any kind of error recovery. Instead, simply invoke the syntax ** error routine and continue going as if nothing had happened. ** ** Applications can set this macro (for example inside %include) if ** they intend to abandon the parse upon the first syntax error seen. */ yy_syntax_error(yypParser,yymajor, yyminor); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); break; #else /* YYERRORSYMBOL is not defined */ /* This is what we do if the grammar does not define ERROR: ** ** * Report an error message, and throw away the input token. ** ** * If the input token is $, then fail the parse. ** ** As before, subsequent error messages are suppressed until ** three input tokens have been successfully shifted. */ if( yypParser->yyerrcnt<=0 ){ yy_syntax_error(yypParser,yymajor, yyminor); } yypParser->yyerrcnt = 3; yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); if( yyendofinput ){ yy_parse_failed(yypParser); #ifndef YYNOERRORRECOVERY yypParser->yyerrcnt = -1; #endif } break; #endif } } #ifndef NDEBUG if( yyTraceFILE ){ yyStackEntry *i; char cDiv = '['; fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){ fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]); cDiv = ' '; } fprintf(yyTraceFILE,"]\n"); } #endif return; } /* ** Return the fallback token corresponding to canonical token iToken, or ** 0 if iToken has no fallback. */ int datalogParseFallback(int iToken){ #ifdef YYFALLBACK assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) ); return yyFallback[iToken]; #else (void)iToken; return 0; #endif }