File: predicate_parser.y

package info (click to toggle)
kde4libs 4:4.14.2-5+deb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 82,428 kB
  • ctags: 99,415
  • sloc: cpp: 761,864; xml: 12,344; ansic: 6,295; java: 4,060; perl: 2,938; yacc: 2,507; python: 1,207; sh: 1,179; ruby: 337; lex: 278; makefile: 29
file content (99 lines) | stat: -rw-r--r-- 2,923 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
%{
#include <stdlib.h>
#include <stdio.h>
#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 <valb> VAL_BOOL
%token <name> VAL_STRING
%token <name> VAL_ID
%token <vali> VAL_NUM
%token <vald> VAL_FLOAT

%type <ptr> predicate
%type <ptr> predicate_atom
%type <ptr> predicate_or
%type <ptr> predicate_and
%type <ptr> string_list
%type <ptr> string_list_rec
%type <ptr> 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( $<ptr>1 ); $$ = $<ptr>1; }
         | '[' predicate_or ']' { PredicateParse_setResult( $<ptr>2 ); $$ = $<ptr>2; }
         | '[' predicate_and ']' { PredicateParse_setResult( $<ptr>2 ); $$ = $<ptr>2; }

predicate_atom: VAL_ID '.' VAL_ID EQ value { $$ = PredicateParse_newAtom( $<name>1, $<name>3, $<ptr>5 ); }
              | VAL_ID '.' VAL_ID MASK value { $$ = PredicateParse_newMaskAtom( $<name>1, $<name>3, $<ptr>5 ); }
              | IS VAL_ID { $$ = PredicateParse_newIsAtom( $<name>2 ); }

predicate_or: predicate OR predicate { $$ = PredicateParse_newOr( $<ptr>1, $<ptr>3 ); }

predicate_and: predicate AND predicate { $$ = PredicateParse_newAnd( $<ptr>1, $<ptr>3 ); }

value: VAL_STRING { $$ = PredicateParse_newStringValue( $<name>1 ); }
     | VAL_BOOL { $$ = PredicateParse_newBoolValue( $<valb>1 ); }
     | VAL_NUM { $$ = PredicateParse_newNumValue( $<vali>1 ); }
     | VAL_FLOAT { $$ = PredicateParse_newDoubleValue( $<vald>1 ); }
     | string_list { $$ = $<ptr>1; }

string_list: '{' string_list_rec '}' { $$ = $<ptr>1; }

string_list_rec: /* empty */ { $$ = PredicateParse_newEmptyStringListValue(); }
               | VAL_STRING { $$ = PredicateParse_newStringListValue( $<ptr>1 ); }
               | VAL_STRING ',' string_list_rec { $$ = PredicateParse_appendStringListValue( $<name>1, $<ptr>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 );
}