~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/sd/bv/adsedgelabelevaluation.y

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%{
 
2
#include "adsedgelabelevaluationparse.h"
 
3
#include <math.h>
 
4
#include <string.h>
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
 
7
 
 
8
#define YYERROR_VERBOSE 
 
9
 
 
10
  int proptype[200];  /* should be initialised by caller */
 
11
  char *propname[200];/* should be initialised by caller */
 
12
  int boollist[200];/* should be initialised by caller */
 
13
  int count;/* should be initialised by caller */
 
14
  int isin; /* true if IN predicate is part of label */
 
15
 
 
16
  int outcome; /* result */
 
17
 
 
18
 
 
19
int isintexp,isstrexp;
 
20
 
 
21
char temp[100];
 
22
 
 
23
int GetBool(char *s, int t){
 
24
  int i=0;
 
25
  while (i<count){
 
26
    if ((!strcmp(propname[i],s))&& (proptype[i]==t)) return boollist[i];
 
27
    i++;
 
28
  }
 
29
  return -1;
 
30
}
 
31
 
 
32
 
 
33
%}
 
34
%union{
 
35
  int i;
 
36
  char *str;
 
37
}
 
38
 
 
39
 
 
40
/* BISON Declarations */
 
41
%token  <str> QUOTE OPEN CLOSE OPENB CLOSEB NL INTEGER IDENTIFIER TRUE LEQ GEQ EQ NEQ GT LT
 
42
%left <i> MINUS PLUS OR
 
43
%left <i> TIMES DIV AND
 
44
%left <i>  NEG NOT  IN   /* negation--unary minus */
 
45
%right <i> '^'         /* exponentiation        */
 
46
 
 
47
/* Grammar follows */
 
48
%%
 
49
input:  line 
 
50
;
 
51
 
 
52
line:  event guard action {if ($<i>1>=0 && $<i>2>=0) outcome= ($<i>1) && ($<i>2); else outcome=0;  }
 
53
;
 
54
 
 
55
 
 
56
 
 
57
 
 
58
event: {$<i>$=1;}
 
59
| IDENTIFIER   {     
 
60
                       int b;
 
61
                       b=GetBool($<str>1,EVENT);
 
62
                       if (b>=0) $<i>$=b; 
 
63
                       else {
 
64
                         b=GetBool($<str>1,SENDEVENT);
 
65
                         if (b>=0) $<i>$=b; else $<i>$=-1;                    
 
66
                       }
 
67
                }
 
68
;
 
69
 
 
70
 
 
71
guard: {$<i>$=1;}
 
72
| OPENB pexp CLOSEB {if ($<i>2 >=0) $<i>$=$<i>2;else $<i>$=1;}
 
73
;
 
74
 
 
75
                 
 
76
pexp:     orexp {$<i>$=$<i>1;}  
 
77
/*
 
78
        | IN OPEN IDENTIFIER CLOSE {$<i>$=1;isin=1; / IN clause checked elsewhere /}
 
79
        | pexp OR pexp     {if ($<i>1>=0 && $<i>3>=0) $<i>$=($<i>1 || $<i>3); else $<i>$=-1;}
 
80
        | pexp AND pexp    {if ($<i>1>=0 && $<i>3>=0) $<i>$=($<i>1 && $<i>3); else $<i>$=-1;} 
 
81
        | NOT pexp         {if ($<i>2>=0) $<i>$=(!$<i>2);else $<i>$=-1;if (isin) $<i>$=1;}
 
82
        | OPEN pexp CLOSE  {$<i>$=$<i>2;}
 
83
*/
 
84
;
 
85
 
 
86
 
 
87
orexp  :   andexp {$<i>$=$<i>1;} 
 
88
         | orexp OR andexp
 
89
                         { if (($<i>3 >= 0) && ($<i>1>=0)) $<i>$=($<i>3 || $<i>1);
 
90
                           if (($<i>3 < 0)  && ($<i>1>=0)) $<i>$=($<i>1);
 
91
                           if (($<i>3 >= 0) && ($<i>1 < 0)) $<i>$=($<i>3);
 
92
                           if (($<i>3 < 0)   && ($<i>1 < 0)) $<i>$=-1;
 
93
                         }
 
94
;
 
95
 
 
96
andexp :   literal {$<i>$=$<i>1;}
 
97
         | andexp AND literal 
 
98
                         { if (($<i>3 >= 0) && ($<i>1>=0)) $<i>$=($<i>3 && $<i>1);
 
99
                           if (($<i>3 < 0)  && ($<i>1>=0)) $<i>$=($<i>1);
 
100
                           if (($<i>3 >= 0) && ($<i>1 < 0)) $<i>$=($<i>3);
 
101
                           if (($<i>3 < 0)   && ($<i>1 < 0)) $<i>$=-1;
 
102
                         }
 
103
;
 
104
 
 
105
literal:  atomic {if ($<i>1>=0) $<i>$=$<i>1;else $<i>$=-1;}
 
106
        | NOT literal {if ($<i>2>=0) $<i>$=(!$<i>2);else $<i>$=-1;if (isin) $<i>$=1;}
 
107
        | OPEN pexp CLOSE {$<i>$=$<i>2;}
 
108
        | IN OPEN IDENTIFIER CLOSE {$<i>$=1;isin=1; /* IN clause checked elsewhere */}
 
109
;
 
110
 
 
111
atomic:   TRUE          {$<i>$=1;}
 
112
| IDENTIFIER           {  
 
113
                          strcpy(temp,$<str>1);
 
114
                        } 
 
115
  isexp   
 
116
                        { 
 
117
                           if (isintexp) {
 
118
                             int b;
 
119
                             strcpy(temp,$<str>1);
 
120
                             b=GetBool(temp,INT);
 
121
                             if (b==-1) b=GetBool(temp,INTERNAL_INT);
 
122
                             if (b>=0) $<i>$=b; else $<i>$=-1;
 
123
                           }
 
124
                           else if (isstrexp){
 
125
                                int b;
 
126
                                strcpy(temp,$<str>1);
 
127
                                b=GetBool(temp,STRING);
 
128
                                if (b==-1) b=GetBool(temp,INTERNAL_STRING);
 
129
                                if (b>=0) $<i>$=b; else $<i>$=-1;                
 
130
                           }
 
131
                           else{
 
132
                             int b;
 
133
                             b = GetBool(temp,PROP);
 
134
                             if (b==-1) b=GetBool(temp,INTERNAL_PROP);
 
135
                             if (b>=0) $<i>$=b; else {$<i>$=-1;}
 
136
                           }
 
137
 
 
138
}
 
139
;
 
140
 
 
141
     
 
142
isexp:    /* empty */ {isintexp=0;isstrexp=0;}
 
143
        | irel INTEGER        {strcpy($<str>$,$<str>1);
 
144
                               isintexp =1;isstrexp=0;}   
 
145
        | srel QUOTE         { strcpy($<str>$,$<str>1);
 
146
                              isintexp=0;isstrexp=1;} 
 
147
;
 
148
 
 
149
irel:      EQ               {strcpy($<str>$,$<str>1);}
 
150
         | NEQ              {strcpy($<str>$,$<str>1);}
 
151
         | GT               {strcpy($<str>$,$<str>1);}
 
152
         | LT               {strcpy($<str>$,$<str>1);}
 
153
         | GEQ              {strcpy($<str>$,$<str>1);}
 
154
         | LEQ              {strcpy($<str>$,$<str>1);}
 
155
;
 
156
 
 
157
         
 
158
 
 
159
srel:      EQ               {strcpy($<str>$,$<str>1);}
 
160
         | NEQ              {strcpy($<str>$,$<str>1);}
 
161
;
 
162
 
 
163
 
 
164
 
 
165
 
 
166
action:   /* empty */ {$<i>$=1;}
 
167
          | DIV IDENTIFIER {$<i>$=1;}
 
168
;
 
169
%%
 
170
 
 
171
 
 
172
 
 
173
 
 
174