summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/ETCL/ETCL.ll
blob: c27536a8d123aed6d3627aca2f1b85c3b3b805e3 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
%option noyywrap

%{
// ETCL.ll,v 1.1.2.1 2000/02/27 23:12:27 coryan Exp
// ========================================================================
//
// = LIBRARY
//   orbsvcs/ECTL
// 
// = FILENAME
//   ETCL.ll
//
// = AUTHOR
//   Carlos O'Ryan <coryan@uci.edu> based on previous work by
//   Seth Widoff <sbw1@cs.wustl.edu>
//
// ========================================================================

#include "ace/OS.h"

#include "ETCL_Constraint.h"
#include "ETCL_y.h"

static const char * extract_string(char*);

#define TAO_YY_LEX_DEBUG

#ifdef TAO_CONSTRAINT_DEBUG
#define TAO_YY_LEX_DEBUG TAO_OS::fprintf(stderr, "%s\n", yytext)
#endif /* TAO_CONSTRAINT_DEBUG */

#define YY_DECL int TAO_ETCL_yylex (TAO_ETCL_YYSTYPE *lvalp, void* state)

#define YY_BREAK
#define YY_NO_UNPUT

%}

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

%%

min             { TAO_YY_LEX_DEBUG; return TAO_ETCL_MIN; }
max             { TAO_YY_LEX_DEBUG; return TAO_ETCL_MAX; }
first           { TAO_YY_LEX_DEBUG; return TAO_ETCL_FIRST; }
random          { TAO_YY_LEX_DEBUG; return TAO_ETCL_RANDOM; }
with            { TAO_YY_LEX_DEBUG; return TAO_ETCL_WITH; }
exist		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_EXIST; }
not		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_NOT; }
and		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_AND; }
or		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_OR; }
in		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_IN; }
"~"             { TAO_YY_LEX_DEBUG; return TAO_ETCL_TWIDDLE; }
"+"		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_PLUS; }
"-"		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_MINUS; }
"*"		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_MULT; }
"/"		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_DIV; }
"<"		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_LT; }
"<="		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_LE; }
">"		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_GT; }
">="		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_GE; }
"=="		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_EQ; }
"!="		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_NE; }
"("             { TAO_YY_LEX_DEBUG; return TAO_ETCL_LPAREN; }
")"             { TAO_YY_LEX_DEBUG; return TAO_ETCL_RPAREN; }
"$"		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_DOLLAR; }
"."		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_DOT; }
"default"	{ TAO_YY_LEX_DEBUG; return TAO_ETCL_DEFAULT; }
"_d"		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_DISCRIMINANT; }
"_type_id"	{ TAO_YY_LEX_DEBUG; return TAO_ETCL_TYPE_ID; }
"_repos_id"	{ TAO_YY_LEX_DEBUG; return TAO_ETCL_REPOS_ID; }
"_length"	{ TAO_YY_LEX_DEBUG; return TAO_ETCL_LENGTH; }
"["		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_LBRA; }
"]"		{ TAO_YY_LEX_DEBUG; return TAO_ETCL_RBRA; }
TRUE		{ 
		  lvalp->constraint = 
		    new TAO_ETCL_Boolean_Literal (1);
		  TAO_YY_LEX_DEBUG; return TAO_ETCL_BOOLEAN;
		}
FALSE		{ 
		  lvalp->constraint = 
		    new TAO_ETCL_Boolean_Literal (0);
		  TAO_YY_LEX_DEBUG; return TAO_ETCL_BOOLEAN;
		}
{integer}	{ 
		  lvalp->constraint = 
		    new TAO_ETCL_Integer_Literal (ACE_OS::atoi (yytext));
		  TAO_YY_LEX_DEBUG; return TAO_ETCL_INTEGER; 
		}
{float}		{
		  double v;
		  sscanf (yytext, "%lf", &v); 
		  lvalp->constraint = 
		    new TAO_ETCL_Float_Literal (v);
		  TAO_YY_LEX_DEBUG; return TAO_ETCL_FLOAT; 
		}
{string}	{ 
		  lvalp->constraint =
		    new TAO_ETCL_String_Literal (extract_string(yytext));
		  TAO_YY_LEX_DEBUG; return TAO_ETCL_STRING; 
		}
{ident}		{ 
		  lvalp->constraint = 
		    new TAO_ETCL_Identifier (yytext);
		  TAO_YY_LEX_DEBUG; return TAO_ETCL_IDENT; 
		}
{white_space}   { 
                  TAO_YY_LEX_DEBUG; break; // Ignore
                }
.               { 
                  TAO_YY_LEX_DEBUG; break; // @@ TODO
                }
%%

const char*
extract_string(char* str)
{
  char *t = str;
  for (char * i = str + 1; *i != 0; ++i, ++t)
    {
      if (*i == '\\')
        {
	  ++i;
	  if (*i == 0)
	    return 0;
	  else if (*i == 't')
	    *t = '\t';
	  else if (*i == 'n')
	    *t = '\n';
	  else if (*i == '\\')
	    *t = '\\';
          else
            *t = *i;
          continue;
        }
      *t = *i;
     
    }

  return str;
}