/* **============================================================================== ** ** Includes ** **============================================================================== */ %{ #include #include #ifdef PEGASUS_OS_TYPE_WINDOWS # include #endif #if defined(PEGASUS_COMPILER_ACC) && defined(PEGASUS_OS_HPUX) # include #endif extern int WQL_lex(); extern int WQL_error(char*); %} /* **============================================================================== ** ** Union used to pass tokens from Lexer to this Parser. ** **============================================================================== */ %union { int intValue; double doubleValue; char* strValue; void* nodeValue; } /* **============================================================================== ** ** Tokens, types, and associative rules. ** **============================================================================== */ %token TOK_INTEGER %token TOK_DOUBLE %token STRING_LITERAL %token EQ %token NE %token LT %token LE %token GT %token GE %token TOK_SELECT %token WHERE %token FROM %token TOK_IDENTIFIER %token NOT %token OR %token AND %token ISA %token WQL_TRUE %token WQL_FALSE %type constant %type property %type propertyListOrStar %type propertyList %type expressionTerm %type expression %type whereClause %type fromClass %type selectStatement %type className %type function %type functionParameterList %type functionParameter %left OR %left AND %nonassoc NOT /* **============================================================================== ** ** The grammar itself. ** **============================================================================== */ %% /* **------------------------------------------------------------------------------ ** ** start rule: ** **------------------------------------------------------------------------------ */ start : selectStatement { } /* BOOKMARK */ /* **------------------------------------------------------------------------------ ** ** Select Statement ** **------------------------------------------------------------------------------ */ selectStatement : TOK_SELECT propertyListOrStar fromClass { } | TOK_SELECT propertyListOrStar fromClass whereClause { } fromClass : FROM className { $$ = $2; } className : TOK_IDENTIFIER { $$ = $1 } whereClause : WHERE expression { } propertyListOrStar : propertyList { } | '*' { } propertyList : property { } | propertyList ',' property { } property : TOK_IDENTIFIER { } | TOK_IDENTIFIER '.' TOK_IDENTIFIER { } expression : expression OR expression { } | expression AND expression { } | NOT expression { } | '(' expression ')' { } | expressionTerm { } expressionTerm : property LT constant { } | property GT constant { } | property LE constant { } | property GE constant { } | property EQ constant { } | property NE constant { } | constant LT property { } | constant GT property { } | constant LE property { } | constant GE property { } | constant EQ property { } | constant NE property { } | function LT constant { } | function GT constant { } | function LE constant { } | function GE constant { } | function EQ constant { } | function NE constant { } | constant LT function { } | constant GT function { } | constant LE function { } | constant GE function { } | constant EQ function { } | constant NE function { } | className ISA className { } function : TOK_IDENTIFIER '(' ')' { } | TOK_IDENTIFIER '(' functionParameterList ')' { } functionParameterList : functionParameter { } | functionParameterList ',' functionParameter { } functionParameter : property | constant | function ; constant : TOK_INTEGER { } | TOK_DOUBLE { } | STRING_LITERAL { } %% int WQL_error(char* errorMessage) { fprintf(stderr, "WQL_error: %s\n", errorMessage); return -1; }