%{ #include extern "C" { #include "parse.h" #ifdef _WIN32 #include #endif void yyerror(char *s); void initFlex( const char *s ); } int yylex(); %} %union { char valb; int vali; double vald; char *name; void *ptr; } %token DOCROOT %token PORT %token CGI %token ALIAS %token MIME %token PIXDIR %token NOT %token EQ %token NEQ %token LEQ %token GEQ %token LE %token GR %token OR %token AND %token IN %token EXIST %token FIRST %token RANDOM %token MAX %token MIN %token WITH %token BOOL %token STRING %token ID %token NUM %token FLOAT %type bool %type bool_or %type bool_and %type bool_compare %type expr_in %type expr_twiddle %type expr %type term %type factor_non %type factor /* Grammar follows */ %% constraint: /* empty */ { setConstraintsParseTree( 0L ); } | bool { setConstraintsParseTree( $1 ); } | preferences { } ; preferences: WITH bool { setPreferencesParseTree( newWITH( $2 ) ); } | MAX bool { setPreferencesParseTree( newMAX( $2 ) ); } | MIN bool { setPreferencesParseTree( newMIN( $2 ) ); } | FIRST { setPreferencesParseTree( newFIRST() ); } | RANDOM { setPreferencesParseTree( newRANDOM() ); } ; bool: bool_or { $$ = $1; } ; bool_or: bool_and OR bool_and { $$ = newOR( $1, $3 ); } | bool_and { $$ = $1; } ; bool_and: bool_compare AND bool_compare { $$ = newAND( $1, $3 ); } | bool_compare { $$ = $1; } ; bool_compare: expr_in EQ expr_in { $$ = newCMP( $1, $3, 1 ); } | expr_in NEQ expr_in { $$ = newCMP( $1, $3, 2 ); } | expr_in GEQ expr_in { $$ = newCMP( $1, $3, 3 ); } | expr_in LEQ expr_in { $$ = newCMP( $1, $3, 4 ); } | expr_in LE expr_in { $$ = newCMP( $1, $3, 5 ); } | expr_in GR expr_in { $$ = newCMP( $1, $3, 6 ); } | expr_in { $$ = $1; } ; expr_in: expr_twiddle IN ID { $$ = newIN( $1, newID( $3 ) ); } | expr_twiddle { $$ = $1; } ; expr_twiddle: expr '~' expr { $$ = newMATCH( $1, $3 ); } | expr { $$ = $1; } ; expr: expr '+' term { $$ = newCALC( $1, $3, 1 ); } | expr '-' term { $$ = newCALC( $1, $3, 2 ); } | term { $$ = $1; } ; term: term '*' factor_non { $$ = newCALC( $1, $3, 3 ); } | term '/' factor_non { $$ = newCALC( $1, $3, 4 ); } | factor_non { $$ = $1; } ; factor_non: NOT factor { $$ = newNOT( $2 ); } | factor { $$ = $1; } ; factor: '(' bool_or ')' { $$ = newBRACKETS( $2 ); } | EXIST ID { $$ = newEXIST( $2 ); } | ID { $$ = newID( $1 ); } | NUM { $$ = newNUM( $1 ); } | FLOAT { $$ = newFLOAT( $1 ); } | STRING { $$ = newSTRING( $1 ); } | BOOL { $$ = newBOOL( $1 ); } ; /* End of grammar */ %% void yyerror ( char *s ) /* Called by yyparse on error */ { printf ("ERROR: %s\n", s); } void mainParse( const char *_code ) { initFlex( _code ); yyparse(); }