%{ // command line xxbison -ouparser.cpp -d -v uparser.yy #ifdef DEBUG #include #endif #include "ParseHook.h" #define YYSTYPE TreeItem* #define YYPARSE_PARAM parm #define YYLEX_PARAM parm #define yylex ScanFunc #define yyparse Parser #define YYERROR_VERBOSE #define YY_ #define YY_LOCATION_PRINT namespace u { int ScanFunc(void* yy_val_ptr, YYLTYPE* yylloc_param, void* parm); #ifndef yyerror #define yyerror(a) ParseError(parm, ctx->m_vS, ctx->m_vSp, &yylval, a, &yylloc) #endif //extern "C" void *alloca (unsigned int); void ParseError(void* infoPtr, YYSTYPE* base, YYSTYPE* top, YYSTYPE* errTok, const char* s, const YYLTYPE* ); #define yymerge(a, b) SCMerge(a, b) #define yyprocess(a, b, c, d)\ process(a, b, c, d); YYSTYPE process(void* parm, YYSTYPE* stackPtr, int depth, RuleType hook); YYSTYPE SCMerge(YYSTYPE& a, YYSTYPE& b); /* Note 1: we have one shift/reduce conflict here with the following construct (expr) this can be interpreted either as an expression in parentheses or as a select statement consisting of a select list of one item equal to expr. The common practice of Bison to prefer a shift causes such a construct to be parsed as the expression in parentheses which is also the most useful case here. Don't forget that function calls also use such blocks but in another context so that their parameter list is always understood as a select statement. The only three cases where a select statement is used - in assignments, column accesses and casts are the three cases which may be affected by this conflict. The second case is not a problem since to access a column one must name it so that the construct used there must look so: (expr :: name) and doesn't cause a conflict. With casts we can in the future decide on the basis of the type the construct is cast to. If we have a table type then we can understand the construct as a select statement, otherwise this would be an expression whose result is cast to a desired type. In the assignment case the code would look as follows: x = (expr). Here both semantics actually tell us the same - create a table containing one column and assign that table to the given variable. For now we yet distinguish between single variables and tables but in the future we will regard the single variables like one-column tables so the difference will disappear. In all other cases the understanding of the construct as an expression is exactly what we need. So we can resolve this grammar conflict with other means and therefore can tolerate it. */ // NOTE - thes subset operator doesn't represent an operation applied to a list, but rather allows to identify in one step a restricted list - this // is important since subset construct can occur at both the left and the right side of an assignment or insert/remove operator. // but also the semantical sense is different. If we first compute the cumulative list and then apply the subset operator to it then we get the given sublist of // the cumulative list. If we consider subset access as a one-step operator then there is no cumulative list but instead for every parent object the given subset // of the corresponding list is extracted and they are all concatenated to form a list which is quite different from the first one. Since such expressions must // have sense also at the left side of an assignment we think this second meaning is more consistent. Both meanings however coincide if the parent list consists // of only one object. The first meaning can be achieved by using (....)[] construct which is ITEM_LIST_BLOCK containing the desired access path, which is // followed by the SUBSET_OPERATOR construct %} %locations %pure_parser %token FTS_CONCAT %token FTS_ASSIGNMENT %token FTS_COMMA %token FTS_DIFF FTS_XOR FTS_AND FTS_OR %token FTS_SHR FTS_SHL %token FTS_TARGETLIST %token FTS_GREATER FTS_LOWER FTS_EQUAL %token FTS_ANYGREATER FTS_ANYLOWER FTS_ANYEQUAL %token FTS_PLUS FTS_MINUS %token FTS_ASTERISK FTS_SLASH FTS_BACKSLASH %token FTS_EXCLAMATIONMARK %token FTS_QUESTIONMARK %token FTS_PERIOD %token FTS_CAP %token FTS_BACKTICK %token FTS_COLON %token FTS_PUT %token FTS_AT %token FTS_CATCH %token FTS_ID %token FTS_LP FTS_RP FTS_LBK FTS_RBK FTS_LBC FTS_RBC %token FTS_SEMICOLON %token FTS_RETURN FTS_BREAK %token FTS_DOUBLEARROW %token FTS_THIS %token FTS_INTEGER FTS_NUMBER FTS_LITERAL FTS_STRING %token FTS_AMPERSAND %token FTS_PIPE %token FTS_DOLLAR %token FTS_PERCENT %token FTS_AVG FTS_SUM FTS_MAX FTS_MIN FTS_CNT FTS_CNTA FTS_SUB FTS_SIS %token FTS_LABEL %token FTS_DATATYPE %token FTS_DOUBLECOLON %token FTS_STDOUT FTS_STDIN FTS_STDERR %token FTS_GETTER FTS_SETTER FTS_FIELD_VALIDATOR %token FTS_DISK %token FTS_ADDCTX %token FTS_SINGLEARROW // used by scanner/preprocessor and for diagnostics %token FTS_HASH %token FTS_OTHER %token FTS_BOGUS %% MAIN_SYMBOL: DECLARATION // declaration containing a module definitin | QUERY_FACTOR // ad hoc query ; DECLARATION: ROWDEF // a declaration is similar to create table SQL clause ; ROWDEF: TYPED_DITEM // always starts with a typed declaration item | SCRIPT_ITEM // or a named execution unit | ROWDEF FTS_COMMA TYPED_DITEM //%prec LIST // it can be followed by other typed declaration items | ROWDEF FTS_COMMA DITEM //%prec LIST // or by declaration items using current type | ROWDEF FTS_COMMA SCRIPT_ITEM //%prec LIST // or by another script item ; TYPE_HEADER: TYPE_SPEC DITEM // type specification and of a declaration item | SCRIPT_ITEM DITEM // named set of directives by taking return value type | OBJECT_VALUE FTS_PERIOD FTS_PERCENT FTS_DOLLAR DITEM // using an object as type | OBJECT_VALUE FTS_PERIOD FTS_DOLLAR DITEM // using type of an object | NAMED_ITEM ENTITY FTS_PERIOD FTS_DOLLAR DITEM // using type of script item by exact signature | TYPE_SPEC FTS_PERIOD PARAMETER_TYPE DITEM // container typedef ; TYPED_DITEM: TYPE_HEADER // type header is one of the possible type specifiers in "u" | FTS_DISK TYPE_HEADER // data items can be also disk based ; TYPE_SPEC: ENTITY_ITEM // type spec can be given by entity or empty parentheses with optional inheritance factor | PARAMETER_TYPE // or by type further specified with a parameter set - used to define containers so not a real type | QUALIFIED_TYPE_REF // explicit type(also subtype) indication | SEQUENCE_FACTOR // sequence definition is type specification ; QUALIFIED_TYPE_REF: QUALIFIED_TYPE // types can be internal to other types so to refer to them we need an accessor chain ; QUALIFIED_TYPE: FTS_TYPE // this is a usual type token | FTS_TYPE ENTITY // type of edge with containers | FTS_TYPE FTS_DOUBLECOLON QUALIFIED_TYPE // subtype of a type ; DITEM: SPECIFIER INIT_FACTOR FIELD_TRIGGER_FACTOR // a usual identifier definition | QUALIFIED_TYPE_REF // an ordinary typedef but with possibly more potential since it allows definition(and therefore also // redefinition) of externally defined types and subtypes - whether this feature will be useful remains to be seen // but for now we preserve it. ; DITEM_LIST: FTS_PIPE EXPRESSION_FACTOR // start of a specialization argument list using value as argument | FTS_PIPE TYPE_SPEC // start of a specialization argument list using type as argument | DITEM_LIST FTS_COMMA EXPRESSION_FACTOR // continuation of specialization list using value | DITEM_LIST FTS_COMMA TYPE_SPEC // continuation of specialization list using type ; SPECIALIZATION_FACTOR: FTS_LBC DITEM_LIST FTS_PIPE FTS_RBC // specialization of the given object by list of arguments | // missing specialization(normal case) ; ID_ITEM: FTS_ID SPECIALIZATION_FACTOR // accessing a named object or its specialization ; FTS_TYPE: FTS_DATATYPE SPECIALIZATION_FACTOR // accessing named type or its specialization ; // note that it was not possible to define an empty TYPE_REL_LIST and therefore we must duplicate the rules for ENTITY and EMPTY_PARAMETER_BLOCK here ENTITY_FACTOR: ENTITY // an independent entity | TYPE_REL_LIST FTS_COLON ENTITY // an entity depending on others or depended on by others | EMPTY_PARAMETER_BLOCK // an empty entity (can be used to define enumerations) | TYPE_REL_LIST FTS_COLON EMPTY_PARAMETER_BLOCK // an empty entity depending on others ; ENTITY_ITEM: ENTITY_FACTOR // ordinary entity | TEMPLATE_FACTOR ENTITY_FACTOR // entity template ; TEMPLATE_ITEM: FTS_ID // ordinary template parameter | TEMPLATE_FACTOR // template used as template parameter ; ID_LIST_FACTOR: ID_LIST // intermediate leaf for ID_LIST ; ID_LIST: TEMPLATE_ITEM // id list head | ID_LIST FTS_COMMA TEMPLATE_ITEM // id list continuation ; TEMPLATE_FACTOR: FTS_LBC FTS_PIPE ID_LIST_FACTOR FTS_PIPE FTS_RBC // template argument definition construct ; ENTITY: FTS_LP ROWDEF FTS_RP // entity is an encapsulated row definition ; SPECIFIER: ID_FACTOR RELATIONSHIP_FACTOR // specifier is id and optional relationship for it | FTS_PERCENT ID_FACTOR // reference to an existing specifier ; ID_FACTOR: SCALAR_ID_FACTOR // representation of a scalar(0:1 list) | LIST_SIZE_SPECIFIER SCALAR_ID_FACTOR // general definition of the object list ; SCALAR_ID_FACTOR: NAMED_ITEM // construct which can also be used as data accessor | NAMED_ITEM ENTITY // definition of identifier with built-in containers ; NAMED_ITEM: ID_ITEM // a usual named identifier | FTS_DOLLAR FTS_SLASH // file system object(can be used as call) | NAMED_ITEM ITEM_LIST_BLOCK // a parameter function call (as declaration item is used for example to indicate tokenizers for text indexes) ; LIST_SIZE_SPECIFIER: LIST_SIZE_FACTOR // general list size specifier | FTS_COLON // list from nothing to infinity ; LIST_SIZE_FACTOR: LIST_SIZE_ITEM // single list size specifier | LIST_SIZE_FACTOR FTS_PIPE LIST_SIZE_ITEM // sequence of acceptable list sizes ; LIST_SIZE_ITEM: FTS_INTEGER FTS_COLON // an object list specifier limited at lower boundary | FTS_COLON FTS_INTEGER // an object list specifier limited at upper boundary | FTS_INTEGER FTS_COLON FTS_INTEGER // an object list specifier limited at both boundaries | FTS_INTEGER // fixed list size | FTS_LBK QUERY_FACTOR FTS_RBK // list size delivered by a query ; // these items are evident SCRIPT_ITEM: FUNCTION | ROW_VALIDATOR | UPDATE_TRIGGER | CONSTRUCTOR | REMOVE_TRIGGER | INSERT_TRIGGER | DESTRUCTOR ; FUNCTION: NAMED_ITEM ENTITY FUNCTION_BODY // a function taking parameters | TEMPLATE_FACTOR NAMED_ITEM ENTITY FUNCTION_BODY // a function template taking parameters | NAMED_ITEM EMPTY_PARAMETER_BLOCK FUNCTION_BODY // a function not taking parameters | TEMPLATE_FACTOR NAMED_ITEM EMPTY_PARAMETER_BLOCK FUNCTION_BODY // a function template not taking parameters ; FUNCTION_BODY: QUERY // a function works just like a reusable query and can return several rows | FTS_LBC FTS_RBC // empty function | ITEM_LIST_BLOCK // block producing an object(item list) | ITEM_LIST_BLOCK FTS_CATCH FTS_LBK OR_FACTOR FTS_RBK // block producing an object(item list) with exception catching clause ; PARAMETER_TYPE: FTS_TYPE PARAMETER_TYPE_BLOCK // currently the definition of a container on fields of contained objects ; PARAMETER_TYPE_BLOCK: ITEM_LIST_BLOCK // this is the list of container expressions(for example index expressions) ; INIT_FACTOR: // declaration item initialization is missing | FTS_ASSIGNMENT EXPRESSION_UNIT // declaration item initialization is present ; FIELD_TRIGGER_FACTOR: FIELD_TRIGGER_FACTOR_LIST // there can be a list of various trigger factors ; // this definition doesn't prohibit use of several triggers of the same kind which we must catch in translator but for now it's just what we need FIELD_TRIGGER_FACTOR_LIST: // the list can be empty | FIELD_TRIGGER_FACTOR_LIST GETTER // it can contain a getter | FIELD_TRIGGER_FACTOR_LIST SETTER // a setter | FIELD_TRIGGER_FACTOR_LIST FIELD_VALIDATOR // or a validator ; // all field triggers look similarly except for the specific token at the beginning SETTER: FTS_SETTER FTS_LBC STATEMENT_LIST FTS_RBC // doesn't return any value ; GETTER: FTS_GETTER FTS_LBC EXPRESSION FTS_RBC // may return any value ; FIELD_VALIDATOR: FTS_FIELD_VALIDATOR FTS_LBC EXPRESSION FTS_RBC // TODO should it be able to return a value ? ; // type dependencies and dependants TYPE_REL_LIST: TYPE_REL // start of relationship list | TYPE_REL_LIST TYPE_REL // continuation of relationship list ; TYPE_REL: FTS_SHR QUALIFIED_TYPE_REF // base on which a field(in math. sence) is defined // for now we seem not to need this side of base/field definition // {$$ = OnRuleMatch(parm, FTS_BaseOfFieldRel, &$1, &$2, NULL);} | FTS_SHL QUALIFIED_TYPE_REF // field(in math sense) defined on a base | FTS_DOUBLEARROW QUALIFIED_TYPE_REF // TODO check what it can mean | FTS_RETURN QUALIFIED_TYPE_REF // equivalence relationship | FTS_SINGLEARROW QUALIFIED_TYPE_REF // both containing/contained rules are defined on part objects not part types // containing relationship | FTS_LOWER FTS_MINUS QUALIFIED_TYPE_REF // contained relationship | FTS_ADDCTX QUALIFIED_TYPE_REF // derived from relationship | FTS_LOWER FTS_PLUS QUALIFIED_TYPE_REF // base of derived type relationship ; EMPTY_PARAMETER_BLOCK: FTS_LP FTS_RP // block without parameters ; RELATIONSHIP_FACTOR: WEIGHT_FACTOR // weight facility for defining weighted grahps | RELATIONSHIP_TYPE ID_FACTOR WEIGHT_FACTOR // combined relationship/weight facility for defining weighted grahps ; ITEM_LIST_BLOCK: FTS_LP ITEM_LIST FTS_RP // conventional parenthesis construct around value list | FTS_LP EXPRESSION_ITEM FTS_COLON ITEM_LIST FTS_RP // applying a permuttion to container's column list ; ITEM_LIST: ITEM // list head | FTS_COMMA // empty item at start | ITEM_LIST FTS_COMMA // empty item in list continuation | ITEM_LIST FTS_COMMA ITEM // item expression in list continuation | FTS_LOWER STRUCTOR_FACTOR FTS_GREATER // the construct above may be used as a "put" operator if needed anywhere // but maybe we can use it for other purposes ; QUERY_FACTOR: QUERY_LIST QUERY_TARGET_FACTOR // query with target indication ; QUERY_LIST_ITEM: TABLE_LIST LABEL_FACTOR QUERY_BODY // single query item | LABEL_FACTOR QUERY_BODY // query without context | QUERY_BODY // query without address facility ; // this is a UNION facility QUERY_LIST: QUERY_LIST_ITEM // list of queries start | QUERY_LIST FTS_CONCAT QUERY_LIST_ITEM // list of queries continuation ; WRAPPER_LIST: FTS_LBC FTS_ASSIGNMENT OBJECT_VALUE // wrapper list start | WRAPPER_LIST FTS_COLON OBJECT_VALUE // wrapper list continuation ; QUERY_ITEM: FTS_LBC QUERY_FACTOR FTS_RBC // // ordinary query ; LIST_QUERY_ITEM: QUERY_ITEM // ordinary query | WRAPPER_LIST FTS_ASSIGNMENT FTS_RBC QUERY_ITEM // query with wrapper list ; BOOLEAN_QUERY_ITEM: FTS_LP QUERY_LIST_ITEM FTS_RBK FTS_RP // traditional EXISTS query | TABLE_LIST FTS_RBK // a join context object which can be cast to boolean ; QUERY_BLOCK: LIST_QUERY_ITEM // intermediate node ; QUERY: QUERY_BLOCK // ordinary query | QUERY_BLOCK FTS_CATCH FTS_LBK OR_FACTOR FTS_RBK // query with the catch exception clause ; TABLE_LIST: FTS_LBK JOIN // list of tables joined together ; EXPRESSION: EXPRESSION_ITEM FTS_COLON LABEL // identifies expression which gets left by block return | EXPRESSION_ITEM // expression without label ; UPDATE_TRIGGER: FTS_ASSIGNMENT FTS_DOLLAR FTS_LBC EXPRESSION FTS_RBC // modification wrapper ; ROW_VALIDATOR: FTS_EXCLAMATIONMARK FTS_DOLLAR FTS_LBC EXPRESSION FTS_RBC // validation wrapper ; CONSTRUCTOR: FTS_ASTERISK FTS_DOLLAR FTS_LBC STATEMENT_LIST FTS_RBC // construction wrapper ; INSERT_TRIGGER: FTS_GREATER FTS_DOLLAR FTS_LBC STATEMENT_LIST FTS_RBC // insertion wrapper ; REMOVE_TRIGGER: FTS_LOWER FTS_DOLLAR FTS_LBC STATEMENT_LIST FTS_RBC // removal wrapper ; DESTRUCTOR: FTS_PLUS FTS_DOLLAR FTS_LBC STATEMENT_LIST FTS_RBC // destruction wrapper ; WEIGHT_FACTOR: // no weight | FTS_ASTERISK FTS_TYPE // definition of type used to indicate weight or a rel ; RELATIONSHIP_TYPE: FTS_SHR // parent side of an ancestry | FTS_SHR FTS_PLUS // cascading parent side of an ancestry | FTS_SHL // child side of an ancestry | FTS_PLUS FTS_SHL // cascadig child side of an ancestry | FTS_LOWER FTS_GREATER // side of peer relationship ; ITEM_FACTOR: EXPRESSION ITEM_ALIAS_LIST // named select list item(possibly multi-named) | EXPRESSION // unnamed select list item ; ITEM: ITEM_FACTOR // itermediate node ; CTX_FACTOR: FTS_RBK // closing bracket of conventional query context | FTS_RBK FTS_DOLLAR // using specializations based on query context if any, otherwise explicit specializations must be given ; LABEL_FACTOR: CTX_FACTOR FTS_AT // in case label name is not necessary for query | CTX_FACTOR LABEL // in case we need query name as break/skip/jump target ; QUERY_BODY: ITEM_LIST // result object generator | STATEMENT_LIST // code which itself cares about the return value of a query if applicable(by adding to the return value token) ; QUERY_TARGET_FACTOR: // implicit target(usually in context of assignment) | FTS_TARGETLIST QUERY_TARGET // explicit target list construct ; QUERY_TARGET_LIST: QUERY_TARGET_ITEM // start of query target list | QUERY_TARGET_LIST FTS_COMMA QUERY_TARGET_ITEM // continuation of query target list ; QUERY_TARGET: QUERY_TARGET_LIST // multi item target | QUERY_TARGET_BASE // single item target ; QUERY_TARGET_ITEM: QUERY_TARGET_ITEM_BASE // ordinary target item | FTS_AMPERSAND QUERY_TARGET_ITEM_BASE // distinct target item ; QUERY_TARGET_ITEM_BASE: NAMED_QUERY_TARGET_BASE // named target item | NAMED_QUERY_TARGET_BASE QUERY_TARGET_PATH // named target item used as source for subsequent qry ; QUERY_TARGET_PATH: FTS_COLON QUERY // context dependent query ; QUERY_TARGET_BASE: TYPE_SPEC // inline container definition | OR_FACTOR // ordinary list target | FTS_AMPERSAND // unnamed distinct result ; NAMED_QUERY_TARGET_BASE:TYPE_HEADER // inline container definition | OR_FACTOR FTS_ID // ordinary list target ; JOIN: TABLE_CONTEXT // ordinary joined table list ; TABLE_CONTEXT: SINGLE_TABLE_ITEM // single context table | JOIN_ARG // ordinary join context | JOIN_ARG JOIN_TERM // complex join tree context ; JOIN_TERM: JOIN_FACTOR // ordianry join term or first tree on | JOIN_TERM FTS_COMMA JOIN_FACTOR // non-first tree join term ; JOIN_FACTOR: JOINOP JOIN_ARG // join operation on ordinary context | JOINOP JOIN_CONTEXT // join operation on tree context ; JOIN_CONTEXT: JOIN_ARG JOIN_FACTOR // start of join context ; JOIN_ARG: TABLE_ITEM // table item as join argument | FTS_LBK TABLE_CONTEXT FTS_RBK // table context as join argument ; // standard join definitions JOINOP: LEFT_SUB_JOIN | LEFT_OUTER_JOIN | RIGHT_SUB_JOIN | RIGHT_OUTER_JOIN | FULL_OUTER_JOIN | INNER_JOIN | FULL_SUB_JOIN | FTS_ASTERISK // cartesian join ; TABLE_ITEM: TABLE_FACTOR FTS_ID // table factor provided with alias for distinct access ; SINGLE_TABLE_ITEM: TABLE_FACTOR // intermediate node ; TABLE_FACTOR: OBJECT_FACTOR // table as object reference | FTS_CAP TABLE_FACTOR // reverse iteration order on container with defined one | SEQUENCE_FACTOR // sequence as query source ; LEFT_SUB_JOIN: FTS_MINUS FTS_LBK JOIN_EXPRESSION FTS_RBK // sub join definition ; LEFT_OUTER_JOIN: FTS_PLUS FTS_LBK JOIN_EXPRESSION FTS_RBK // left outer join definition ; RIGHT_SUB_JOIN: FTS_LBK JOIN_EXPRESSION FTS_RBK FTS_MINUS // right sub join definition ; RIGHT_OUTER_JOIN: FTS_LBK JOIN_EXPRESSION FTS_RBK FTS_PLUS // right outer join definition ; FULL_OUTER_JOIN: FTS_PLUS FTS_LBK JOIN_EXPRESSION FTS_RBK FTS_PLUS // full outer join definition ; FULL_SUB_JOIN: FTS_MINUS FTS_LBK JOIN_EXPRESSION FTS_RBK FTS_MINUS // full sub join definition(XOR join) ; INNER_JOIN: FTS_LBK JOIN_EXPRESSION FTS_RBK // inner join definition | NATURAL_INNER_JOIN // natural join in U sense definition ; NATURAL_INNER_JOIN: NATURAL_INNER_JOIN_OR // start of natural join definition ; NATURAL_INNER_JOIN_OR: NATURAL_INNER_JOIN_OR_ITEM // natural join as or item ; NATURAL_INNER_JOIN_OR_ITEM:NATURAL_INNER_JOIN_AND // natural join as and clause ; NATURAL_INNER_JOIN_AND:NATURAL_INNER_JOIN_AND_ITEM // natural join as and item ; NATURAL_INNER_JOIN_AND_ITEM:SPECIAL_JOIN_EXPRESSION // NIJ is given in form of a special expression ; JOIN_EXPRESSION: OR_FACTOR // enables using boolean expressions to join tables | FTS_ASTERISK // cartesian join ; SPECIAL_JOIN_EXPRESSION:KEYPATH_JOIN_EXPRESSION // keypath jon ; KEYPATH_JOIN_EXPRESSION:FTS_COLON // relationship based keypath join | FTS_SHR // left source key path join | FTS_SHL // right source key path join | FTS_GREATER OBJECT_FACTOR FTS_GREATER // left source explicit keypath join | FTS_LOWER OBJECT_FACTOR FTS_LOWER // right source explicit keypath join ; SUBGROUP_FACTOR: QUERY // subgroup executed by query | FTS_EQUAL QUERY // unwrapped subgroup query ; GROUP_EXPRESSION: FTS_AVG ITEM_LIST_BLOCK // computing average for a group set | FTS_SUM ITEM_LIST_BLOCK // computing sum for a group set | FTS_MAX SUBGROUP_FACTOR ITEM_LIST_BLOCK // subquery on rows satisfying the max condition | FTS_MAX ITEM_LIST_BLOCK // computing max for a group set | FTS_MIN SUBGROUP_FACTOR ITEM_LIST_BLOCK // subquery on rows satisfying the min condition | FTS_MIN ITEM_LIST_BLOCK // computing min for a group set | FTS_SUB ITEM_LIST_BLOCK // reserved but not used for now | FTS_SUB QUERY // computing sublist on a group set for a qry | FTS_CNT ITEM_LIST_BLOCK // count non empty items in group | FTS_CNTA // computing count of items in a group set | FTS_SIS ITEM_LIST_BLOCK // computing common value for a group set | OBJECT_VALUE FTS_PERIOD FTS_DOLLAR FTS_ASSIGNMENT ITEM_LIST_BLOCK // computing custom group function | OBJECT_VALUE FTS_PERIOD FTS_DOLLAR FTS_ASSIGNMENT SUBGROUP_FACTOR ITEM_LIST_BLOCK // computing custom group function with a subqry ; LABEL: FTS_LABEL // label consists of single label token ; EXPRESSION_ITEM: EXPRESSION_AGENT // as independent expression | STATEMENT_LIST EXPRESSION_AGENT // as list of statements followed by an expression ; STATEMENT_LIST: STATEMENT_LIST STATEMENT // continuation of statement list | STATEMENT // start of statement list ; ID_REF: ID_ITEM // select list item is either ID item | FTS_ID FTS_PERIOD ID_ITEM // or qualified id item to address one of multiple targets ; ITEM_ALIAS_LIST: ITEM_ALIAS // alias list start(redirection of multiple select items) | ITEM_ALIAS_LIST FTS_DOUBLECOLON ITEM_ALIAS // continuation of alias list ; ITEM_ALIAS: ID_REF // item alias start(multiple redirection of select item) | ITEM_ALIAS FTS_COLON ID_REF // continuation of item alias ; OBJECT_FACTOR: OBJECT_VALUE // ordinary object value | OBJECT_VALUE LABEL // this one is an object at a given transaction(TODO) ; OBJECT_VALUE: OBJECT_ROOT // head of qualification path | TYPE_SPEC FTS_PERIOD OBJECT_ACCESSOR_FACTOR // TODO what does it mean exactly ? | OBJECT_VALUE FTS_PERIOD OBJECT_ACCESSOR_FACTOR // value qualified by object accessor | OBJECT_VALUE FTS_PERIOD CAST_TYPE_FACTOR // value qualified by type cast(so cast of value to type) ; // it is what can be applied to object to access a kind of its property // CAST_TYPE_FACTOR cannot be included because of conflicts OBJECT_ACCESSOR_FACTOR: OBJECT_ACCESSOR // plain object accessor | OBJECT_ACCESSOR SUBSET_OPERATOR // object accessor filtered as subset | FTS_PERCENT // list of objects of the given type object ; OBJECT_ACCESSOR: FTS_THIS // applied to type spec it has meaning of FTS_TypeObjOfType // otherwise accessor to the own reference // $$.$i or $$.$t yields id of the object | FTS_DOLLAR FTS_LP FTS_RP // current transaction object. cast to $i yields // the corresponding transaction id | NAMED_ITEM // object accessor is accessor factor too | ITEM_LIST_BLOCK // can also be qualified ; // after comma come respective counts of items to be fetched at the given position RANGE: SHIFT_FACTOR // everything we can build a set of | SHIFT_FACTOR FTS_EQUAL // shortcut for building discrete set // a[4~] contains item at 4, a[4] all items starting with 4 ; RANGE_LIST: RANGE // start of range list | RANGE_LIST FTS_XOR RANGE // continuation of range list by exclusion points | RANGE_LIST FTS_OR RANGE // continuation of range list by inclusion points ; RANGE_FACTOR: RANGE_LIST | FTS_CAP RANGE_LIST // inversion of range list ; SUBSET_OPERATOR: SUBSET_FACTOR // single subset filter applied | SUBSET_OPERATOR SUBSET_FACTOR // list of subset filters applied ; SUBSET_FACTOR: FTS_LBK RANGE_FACTOR FTS_RBK // subset filter is given in brackets | FTS_LBK FTS_RBK // TODO can it be used as left value for appending to end ? ; SUBSETTABLE_ROOT: OBJECT_ACCESSOR // can be qualified | QUERY // query can too | FTS_BACKTICK FACTOR_AGENT FTS_BACKTICK // evaluate - can be cast to a definite type if user knows the return type of it ; OBJECT_ROOT: SUBSETTABLE_ROOT // accessor root as subsettable root but without subset | SUBSETTABLE_ROOT SUBSET_OPERATOR // the same but with subset specified | CONSTANT // constant object | GROUP_EXPRESSION // group expression as object ; CONSTANT: FTS_INTEGER // integer number constant | FTS_NUMBER // floating number constant | FTS_STRING // shell expansion sensitive string constant | FTS_LITERAL // ordinary string constant | FTS_STDIN // STDIN token | FTS_STDOUT // STDOUT token | FTS_STDERR // STDERR token | FTS_DOLLAR FTS_LBC FTS_RBC // special object '1' as known from the group theory // is reserved for now but not yet used - maybe we can // simply interpret 1 according to context | FTS_LBC FTS_RBC // empty list | FTS_PERCENT ADDRESS_FACTOR // target item reference | FTS_DOLLAR FTS_EXCLAMATIONMARK // exception ; EXPRESSION_UNIT: OR_FACTOR // boolean expression | ASSIGNMENT // assignment as expression ; FACTOR_AGENT: AGENT_FACTOR // plain factor agent | LABEL FTS_COLON AGENT_FACTOR // labelled factor agent ; EXPRESSION_AGENT: FACTOR_AGENT // intermediate node ; AGENT_FACTOR: EXPRESSION_UNIT // ordinary expression | FTS_EQUAL EXPRESSION_UNIT // unwrapped expression ; STATEMENT: FACTOR_AGENT FTS_SEMICOLON // standard statement | FTS_BACKTICK FTS_BACKTICK FTS_SEMICOLON // code fragment placeholder in wrappers whose result we cannot know and use since computed in foreign context | DECLARATION FTS_SEMICOLON // declaration is also considered statement in U ; OR_FACTOR: OR_ITEM // single expression | OR_PREFIX_LIST OR_ITEM // list of OR expressions | FTS_EQUAL FTS_DOLLAR // SELECT * ; OR_ITEM: AND_FACTOR // an AND expression is part of an OR expression ; OR_PREFIX: OR_ITEM FTS_PIPE // OR expression is built using | ; OR_PREFIX_LIST: OR_PREFIX // start of prefix list | OR_PREFIX_LIST OR_PREFIX // continuation of prefix list ; AND_FACTOR: AND_ITEM // single expression as AND expression | AND_PREFIX_LIST AND_ITEM // complex AND expression ; AND_PREFIX: AND_ITEM FTS_AMPERSAND // AND expression is built using & ; AND_PREFIX_LIST: AND_PREFIX // start of AND expression | AND_PREFIX_LIST AND_PREFIX // continuation of AND expression ; AND_ITEM: JUMP_FACTOR // this way we can use jumps by condition | SPECIAL_JOIN_EXPRESSION // so it can be used as part of join condition ; JUMP_FACTOR: FTS_RETURN ADDRESS_FACTOR // resultless return from block given by ADDRESS_FACTOR | EXPRESSION_BASE FTS_BREAK ADDRESS_FACTOR // deliver exception outside block given by add factor | FTS_BREAK ADDRESS_FACTOR // break from query given by ADDRESS_FACTOR | FTS_DOUBLEARROW ADDRESS_FACTOR // skip of current row of query given by ADDRESS_FACTOR | EXPRESSION_BASE FTS_BREAK // ordinary exception throw | FTS_BREAK // break from innermost block | FTS_DOUBLEARROW // skip innermost row | LABEL FTS_RETURN // jump // because of this rule we caanot define empty address factor // therefore doubling empty cases for other constructs here | EXPRESSION_BASE FTS_RETURN ADDRESS_FACTOR // result return from block given by ADDRESS_FACTOR | EXPRESSION_BASE FTS_RETURN // result return from innermost block | FTS_RETURN // resultless return from innermost block | EXPRESSION_BASE // plain jump factor is given by an expression ; ADDRESS_FACTOR: FTS_AT // current construct addressed | LABEL // address is given by named label ; EXPRESSION_BASE: EXPRESSION_FACTOR // pass over of expression factor | EXPRESSION_BASE FTS_CAP EXPRESSION_FACTOR // bitwise xor which is here to allow applying it to bools too ; EXPRESSION_FACTOR: CHECK_FACTOR // pass over of check factor | COMPARE_FACTOR // pass over of compare factor | FTS_CAP COMPARE_FACTOR // is not applied to compare factor ; CHECK_FACTOR: FTS_EXCLAMATIONMARK SET_FACTOR // is null ? | FTS_QUESTIONMARK SET_FACTOR // is not null ; // evident COMPARE_FACTOR: SET_FACTOR | BOOLEAN_QUERY_ITEM | COMPARE_FACTOR FTS_GREATER SET_FACTOR | COMPARE_FACTOR FTS_LOWER SET_FACTOR | COMPARE_FACTOR FTS_EQUAL SET_FACTOR | COMPARE_FACTOR FTS_EQUAL FTS_EQUAL SET_FACTOR | COMPARE_FACTOR FTS_ANYGREATER SET_FACTOR // TODO still needed ? | COMPARE_FACTOR FTS_ANYLOWER SET_FACTOR // TODO still needed ? | COMPARE_FACTOR FTS_ANYEQUAL SET_FACTOR // TODO still needed ? ; SET_FACTOR: SHIFT_FACTOR // pass over of shift factor | SET_FACTOR FTS_AND SHIFT_FACTOR // intersection of two sets | SET_FACTOR FTS_OR SHIFT_FACTOR // union of two sets | SET_FACTOR FTS_DIFF SHIFT_FACTOR // order dependent difference of two sets | SET_FACTOR FTS_XOR SHIFT_FACTOR // exclusive union of two sets ; SHIFT_FACTOR: ADD_FACTOR | SHIFT_FACTOR FTS_SHL ADD_FACTOR // shift to right by factor | SHIFT_FACTOR FTS_SHR ADD_FACTOR // now follow the pad/trim constructs | SHIFT_FACTOR FTS_SHL ADD_FACTOR FTS_PERCENT ADD_FACTOR | SHIFT_FACTOR FTS_SHR ADD_FACTOR FTS_PERCENT ADD_FACTOR | SHIFT_FACTOR FTS_PUT ADD_FACTOR // universal put operator ; ADD_FACTOR: MULTIPLY_FACTOR // pass over of multiply factor | ADD_FACTOR FTS_PLUS MULTIPLY_FACTOR // addition | ADD_FACTOR FTS_MINUS MULTIPLY_FACTOR // subtraction ; MULTIPLY_FACTOR: IFNOTNULL_FACTOR | MULTIPLY_FACTOR FTS_ASTERISK IFNOTNULL_FACTOR // multiply | MULTIPLY_FACTOR FTS_SLASH IFNOTNULL_FACTOR // divide | MULTIPLY_FACTOR FTS_BACKSLASH IFNOTNULL_FACTOR // modulo ; IFNOTNULL_FACTOR: SIGN_FACTOR | IFNOTNULL_FACTOR FTS_QUESTIONMARK SIGN_FACTOR // return first non-null in the chain, otherwise the very last item | IFNOTNULL_FACTOR FTS_EXCLAMATIONMARK SIGN_FACTOR // return first null in the chain, otherwise the very last item ; SIGN_FACTOR: QUOTE_FACTOR // pass over of quote factor | FTS_MINUS SIGN_FACTOR // negation ; QUOTE_FACTOR: STRUCTOR_FACTOR // pass over of structor factor | FTS_PERCENT QUOTE_FACTOR // taking reference ; STRUCTOR_FACTOR: OBJECT_FACTOR | OBJECT_FACTOR FTS_AT // autoassign operator - put result into left operand | FTS_ASTERISK OBJECT_FACTOR // construction | FTS_PLUS OBJECT_FACTOR // destruction | FTS_SLASH OBJECT_FACTOR // container removal | FTS_ASTERISK TYPE_SPEC // construction by type ; ASSIGNMENT: QUOTE_FACTOR FTS_ASSIGNMENT EXPRESSION_UNIT // assignment is built of Lvalue, = and expression to right ; SEQUENCE_FACTOR: FTS_DOLLAR FTS_AT // so far integer sequence starting with 0 growing by 1 | FTS_DOLLAR FTS_AT ITEM_LIST_BLOCK // explicitly specified sequence ; CAST_TYPE_FACTOR: FTS_TYPE // needed for translators to distinguish it from other parameter type constructs | FTS_TYPE SUBSET_OPERATOR // TODO what is it ? | PARAMETER_TYPE | PARAMETER_TYPE SUBSET_OPERATOR // TODO what is it ? ; %% const char* const *GTokenNames = yytname - 254; int ScanFunc(void* yy_val_ptr, YYLTYPE* yyloc_param, void* parm) { ParseInfo* infoPtr = (ParseInfo*)parm; return infoPtr->m_scanner->lex(yy_val_ptr, yyloc_param, parm); } void ParseError(void* parm, YYSTYPE* base, YYSTYPE* top, YYSTYPE* errTok, const char* s, const YYLTYPE* yylloc) { printf("parser error: %s at %d:%d-%d\n", s, yylloc->first_line, yylloc->first_column, yylloc->last_column); } YYSTYPE process(void* parm, YYSTYPE* stackPtr, int depth, RuleType hook) { #ifdef DEBUG std::ostringstream stm; #endif ParseInfo* infoPtr = (ParseInfo*)parm; TreeItem* rc = new TreeItem, *former = rc; for(YYSTYPE *aptr = stackPtr - depth + 1; aptr <= stackPtr; aptr ++) { #ifdef DEBUG stm << (former == rc ? "" : " ") << *(*aptr)->m_text; #endif YYSTYPE& ih = former == rc ? former->m_child : former->m_next; former = ih = *aptr; } rc->m_hook = hook; #ifdef DEBUG rc->m_text = new std::string(stm.str()); //printf("generating text %s\n", rc->m_text->c_str()); #endif return rc; } YYSTYPE SCMerge(YYSTYPE& a, YYSTYPE& b) { // TODO implement conditional code generation TreeItem* rc = new TreeItem; *rc = *a; return rc; } }