%{ #include #include #include "ktraderparse.h" void yyerror(const char *s); int yylex(); void TDETraderParse_initFlex( const char *s ); %} %union { char valb; int vali; double vald; char *name; void *ptr; } %token NOT %token EQ %token NEQ %token LEQ %token GEQ %token LE %token GR %token OR %token AND %token TOKEN_IN %token EXIST %token MAX %token MIN %token VAL_BOOL %token VAL_STRING %token VAL_ID %token VAL_NUM %token VAL_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 */ { TDETraderParse_setParseTree( 0L ); } | bool { TDETraderParse_setParseTree( $1 ); } ; bool: bool_or { $$ = $1; } ; bool_or: bool_and OR bool_or { $$ = TDETraderParse_newOR( $1, $3 ); } | bool_and { $$ = $1; } ; bool_and: bool_compare AND bool_and { $$ = TDETraderParse_newAND( $1, $3 ); } | bool_compare { $$ = $1; } ; bool_compare: expr_in EQ expr_in { $$ = TDETraderParse_newCMP( $1, $3, 1 ); } | expr_in NEQ expr_in { $$ = TDETraderParse_newCMP( $1, $3, 2 ); } | expr_in GEQ expr_in { $$ = TDETraderParse_newCMP( $1, $3, 3 ); } | expr_in LEQ expr_in { $$ = TDETraderParse_newCMP( $1, $3, 4 ); } | expr_in LE expr_in { $$ = TDETraderParse_newCMP( $1, $3, 5 ); } | expr_in GR expr_in { $$ = TDETraderParse_newCMP( $1, $3, 6 ); } | expr_in { $$ = $1; } ; expr_in: expr_twiddle TOKEN_IN VAL_ID { $$ = TDETraderParse_newIN( $1, TDETraderParse_newID( $3 ) ); } | expr_twiddle { $$ = $1; } ; expr_twiddle: expr '~' expr { $$ = TDETraderParse_newMATCH( $1, $3 ); } | expr { $$ = $1; } ; expr: expr '+' term { $$ = TDETraderParse_newCALC( $1, $3, 1 ); } | expr '-' term { $$ = TDETraderParse_newCALC( $1, $3, 2 ); } | term { $$ = $1; } ; term: term '*' factor_non { $$ = TDETraderParse_newCALC( $1, $3, 3 ); } | term '/' factor_non { $$ = TDETraderParse_newCALC( $1, $3, 4 ); } | factor_non { $$ = $1; } ; factor_non: NOT factor { $$ = TDETraderParse_newNOT( $2 ); } | factor { $$ = $1; } ; factor: '(' bool_or ')' { $$ = TDETraderParse_newBRACKETS( $2 ); } | EXIST VAL_ID { $$ = TDETraderParse_newEXIST( $2 ); } | VAL_ID { $$ = TDETraderParse_newID( $1 ); } | VAL_NUM { $$ = TDETraderParse_newNUM( $1 ); } | VAL_FLOAT { $$ = TDETraderParse_newFLOAT( $1 ); } | VAL_STRING { $$ = TDETraderParse_newSTRING( $1 ); } | VAL_BOOL { $$ = TDETraderParse_newBOOL( $1 ); } | MAX VAL_ID { $$ = TDETraderParse_newMAX2( $2 ); } | MIN VAL_ID { $$ = TDETraderParse_newMIN2( $2 ); } ; /* End of grammar */ %% void yyerror ( const char *s ) /* Called by yyparse on error */ { TDETraderParse_error( s ); } void TDETraderParse_mainParse( const char *_code ) { TDETraderParse_initFlex( _code ); yyparse(); }