%{ #include #include #include "predicate_parser.h" #include "predicateparse.h" #define YYLTYPE_IS_TRIVIAL 0 #define YYENABLE_NLS 0 #define YYLEX_PARAM scanner #define YYPARSE_PARAM scanner typedef void* yyscan_t; void Soliderror(const char *s); int Solidlex( YYSTYPE *yylval, yyscan_t scanner ); int Solidlex_init( yyscan_t *scanner ); int Solidlex_destroy( yyscan_t *scanner ); void PredicateParse_initLexer( const char *s, yyscan_t scanner ); void PredicateParse_mainParse( const char *_code ); %} %union { char valb; int vali; double vald; char *name; void *ptr; } %token EQ %token MASK %token AND %token OR %token IS %token VAL_BOOL %token VAL_STRING %token VAL_ID %token VAL_NUM %token VAL_FLOAT %type predicate %type predicate_atom %type predicate_or %type predicate_and %type string_list %type string_list_rec %type value %destructor { PredicateParse_destroy( $$ ); } predicate %destructor { PredicateParse_destroy( $$ ); } predicate_atom %destructor { PredicateParse_destroy( $$ ); } predicate_or %destructor { PredicateParse_destroy( $$ ); } predicate_and %pure-parser %% predicate: predicate_atom { PredicateParse_setResult( $1 ); $$ = $1; } | '[' predicate_or ']' { PredicateParse_setResult( $2 ); $$ = $2; } | '[' predicate_and ']' { PredicateParse_setResult( $2 ); $$ = $2; } predicate_atom: VAL_ID '.' VAL_ID EQ value { $$ = PredicateParse_newAtom( $1, $3, $5 ); } | VAL_ID '.' VAL_ID MASK value { $$ = PredicateParse_newMaskAtom( $1, $3, $5 ); } | IS VAL_ID { $$ = PredicateParse_newIsAtom( $2 ); } predicate_or: predicate OR predicate { $$ = PredicateParse_newOr( $1, $3 ); } predicate_and: predicate AND predicate { $$ = PredicateParse_newAnd( $1, $3 ); } value: VAL_STRING { $$ = PredicateParse_newStringValue( $1 ); } | VAL_BOOL { $$ = PredicateParse_newBoolValue( $1 ); } | VAL_NUM { $$ = PredicateParse_newNumValue( $1 ); } | VAL_FLOAT { $$ = PredicateParse_newDoubleValue( $1 ); } | string_list { $$ = $1; } string_list: '{' string_list_rec '}' { $$ = $1; } string_list_rec: /* empty */ { $$ = PredicateParse_newEmptyStringListValue(); } | VAL_STRING { $$ = PredicateParse_newStringListValue( $1 ); } | VAL_STRING ',' string_list_rec { $$ = PredicateParse_appendStringListValue( $1, $3 ); } %% void Soliderror ( const char *s ) /* Called by Solidparse on error */ { PredicateParse_errorDetected(s); } void PredicateParse_mainParse( const char *_code ) { yyscan_t scanner; Solidlex_init( &scanner ); PredicateParse_initLexer( _code, scanner ); Solidparse( scanner ); Solidlex_destroy( scanner ); }