summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Trader/constraint.l
blob: 321fe33724ee39ae99e6806285bbe663688cddb5 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
%{
// $Id$
// ========================================================================
//
// = LIBRARY
//    orbsvcs
// 
// = FILENAME
//    constraint.l
//
// = AUTHOR
//    Seth Widoff <sbw1@cs.wustl.edu>
//
// ========================================================================

#include "Constraint.h"
#include "Constraint_Nodes.h"
#include "Constraint_Tokens.h"

static ACE_Literal_Constraint* extract_string(const char*);

#define ACE_YY_LEX_DEBUG

#ifdef ACE_CONSTRAINT_DEBUG
#define ACE_YY_LEX_DEBUG ACE_OS::fprintf(stderr, "%s\n", yytext)
#endif /* ACE_CONSTRAINT_DEBUG */


%}

white_space     [ \t]
letter		[a-zA-Z]
digit		[0-9]
alpha_num	({letter}|{digit})
integer		{digit}+ 
float		({digit}*\.{digit}+)([eE][-+]?{digit}+)? 
string		'(([^'\\]*)|([^'\\]*\\')|([^'\\]*\\\\))*'
ident		{letter}({alpha_num}|[_])*
newline		\n
unknown         [^ \t]

%%

min             { ACE_YY_LEX_DEBUG; return MIN; }
max             { ACE_YY_LEX_DEBUG; return MAX; }
first           { ACE_YY_LEX_DEBUG; return FIRST; }
random          { ACE_YY_LEX_DEBUG; return RANDOM; }
with            { ACE_YY_LEX_DEBUG; return WITH; }
exist		{ ACE_YY_LEX_DEBUG; return EXIST; }
not		{ ACE_YY_LEX_DEBUG; return NOT; }
and		{ ACE_YY_LEX_DEBUG; return AND; }
or		{ ACE_YY_LEX_DEBUG; return OR; }
in		{ ACE_YY_LEX_DEBUG; return IN; }
"~"             { ACE_YY_LEX_DEBUG; return TWIDDLE; }
"+"		{ ACE_YY_LEX_DEBUG; return PLUS; }
"-"		{ ACE_YY_LEX_DEBUG; return MINUS; }
"*"		{ ACE_YY_LEX_DEBUG; return MULT; }
"/"		{ ACE_YY_LEX_DEBUG; return DIV; }
"<"		{ ACE_YY_LEX_DEBUG; return LT; }
"<="		{ ACE_YY_LEX_DEBUG; return LE; }
">"		{ ACE_YY_LEX_DEBUG; return GT; }
">="		{ ACE_YY_LEX_DEBUG; return GE; }
"=="		{ ACE_YY_LEX_DEBUG; return EQ; }
"!="		{ ACE_YY_LEX_DEBUG; return NE; }
"("             { ACE_YY_LEX_DEBUG; return LPAREN; }
")"             { ACE_YY_LEX_DEBUG; return RPAREN; }
TRUE		{ 
		  yylval.constraint_ = 
		    new ACE_Literal_Constraint((CORBA::Boolean)TRUE_CON);
		  ACE_YY_LEX_DEBUG; return BOOLEAN;
		}
FALSE		{ 
		  yylval.constraint_ = 
		    new ACE_Literal_Constraint((CORBA::Boolean)FALSE_CON);
		  ACE_YY_LEX_DEBUG; return BOOLEAN;
		}
{integer}	{ 
		  yylval.constraint_ = 
		    new ACE_Literal_Constraint((CORBA::Long)atoi(yytext));
		  ACE_YY_LEX_DEBUG; return NUMBER; 
		}
{float}		{ 
		  yylval.constraint_ = 
		    new ACE_Literal_Constraint((CORBA::Double)atof(yytext));
		  ACE_YY_LEX_DEBUG; return NUMBER; 
		}
{string}	{ 
		  yylval.constraint_ = extract_string(yytext);
		  ACE_YY_LEX_DEBUG; return STRING; 
		}
{ident}		{ 
		  yylval.constraint_ = 
		    new ACE_Property_Constraint(yytext);
		  ACE_YY_LEX_DEBUG; return IDENT; 
		}
{unknown}       { 
                  ACE_YY_LEX_DEBUG; return UNKNOWN;
                }
%%

ACE_Literal_Constraint*
extract_string(const char* total)
{
  int prev_slash = 0, 
    ctr = 0;
  char str[BUFSIZ],
   *tmp = total + 1;

  while (*tmp != '\0')
    {
      if (*tmp == '\\')
        {
          if (prev_slash)
            prev_slash = 0;
          else
            {
              prev_slash = 1;
              continue;
            }
        }
      else if (*tmp == '\'')
        prev_slash = 0;

      str[ctr++] = *tmp;
      tmp++;
    }

  str[ctr - 1] = '\0';
  return new ACE_Literal_Constraint(str);
}