/* **============================================================================== ** ** Includes ** **============================================================================== */ %{ #include #include #ifdef PEGASUS_OS_TYPE_WINDOWS # include #endif #if defined(PEGASUS_COMPILER_ACC) && defined(PEGASUS_OS_HPUX) # include #endif #if 0 # define WQL_TRACE(X) printf(X) #else # define WQL_TRACE(X) #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 TOK_STRING %token TOK_TRUE %token TOK_FALSE %token TOK_NULL %token TOK_EQ %token TOK_NE %token TOK_LT %token TOK_LE %token TOK_GT %token TOK_GE %token TOK_NOT %token TOK_OR %token TOK_AND %token TOK_IS %token TOK_IDENTIFIER %token TOK_SELECT %token TOK_WHERE %token TOK_FROM %token TOK_UNEXPECTED_CHAR %type propertyName %type propertyList %type predicate %type comparisonPredicate %type comparisonTerm %type nullPredicate %type searchCondition %type fromClause %type whereClause %type selectStatement %type selectList %type selectExpression %type className %left TOK_OR %left TOK_AND %nonassoc TOK_NOT %% /* **============================================================================== ** ** The grammar itself. ** **============================================================================== */ start : selectStatement { printf("YACC: start\n"); } selectStatement : TOK_SELECT selectList selectExpression { } selectList : '*' { } | propertyList { } propertyList : propertyName { } | propertyList ',' propertyName { } selectExpression : fromClause whereClause { } | fromClause { } fromClause : TOK_FROM className { } whereClause : TOK_WHERE searchCondition { } searchCondition : searchCondition TOK_OR searchCondition { } | searchCondition TOK_AND searchCondition { } | TOK_NOT searchCondition { } | '(' searchCondition ')' { } | predicate { } | predicate TOK_IS truthValue { } | predicate TOK_IS TOK_NOT truthValue { } predicate : comparisonPredicate { } | nullPredicate { } comparisonPredicate : comparisonTerm TOK_LT comparisonTerm { } | comparisonTerm TOK_GT comparisonTerm { } | comparisonTerm TOK_LE comparisonTerm { } | comparisonTerm TOK_GE comparisonTerm { } | comparisonTerm TOK_EQ comparisonTerm { } | comparisonTerm TOK_NE comparisonTerm { } nullPredicate : comparisonTerm TOK_IS TOK_NULL { } | comparisonTerm TOK_IS TOK_NOT TOK_NULL { } truthValue : TOK_TRUE { } | TOK_FALSE { } propertyName : TOK_IDENTIFIER { } className : TOK_IDENTIFIER { } comparisonTerm : propertyName { } | TOK_INTEGER { } | TOK_DOUBLE { } | TOK_STRING { } | truthValue { } %% int WQL_error(char* errorMessage) { fprintf(stderr, "WQL_error: %s\n", errorMessage); return -1; }