*** empty log message ***
[dyninst.git] / dyner / src / cmdline.l
1 %{
2 #if defined(i386_unknown_nt4_0)
3 #define YY_SKIP_YYWRAP
4 #define YY_NEVER_INTERACTIVE 1
5
6 int yywrap()
7 {
8     return 1;
9 }
10 #endif
11
12 #include <string.h>
13 #include "BPatch_snippet.h"
14 #include "dyner.tab.h"
15
16 extern "C" {
17 void set_lex_input(char *);
18 }
19
20 static char *input_str = NULL;
21
22 #ifdef FLEX_SCANNER
23 #undef YY_INPUT
24
25 #define YY_INPUT(b,r,ms) (r = my_yyinput(b, ms))
26
27 int my_yyinput(char *buf, int max_size);
28 #else
29 #undef input
30 #undef unput
31
32 #define input()  (*input_str++)
33 #define unput(c) (*--input_str = c)
34
35 #endif
36
37
38 static int yyinput(void);
39
40 static int doubleQuote()
41 {
42     int count;
43     char ch;
44     bool backSlash = false;
45
46     count = 0;
47     while (1) {
48         ch = yyinput();
49         yyleng++;
50         switch (ch) {
51             case '"':
52                 if (backSlash) {
53                     /* \" */
54                     yytext[count++] = '"';
55                 } else {
56                     yyleng--;
57                     yytext[count] = '\0';
58                     dynerlval.sval = strdup(yytext);
59                     return(STRING);
60                 }
61                 break;
62
63             case '\n':
64                 /* New line before end of string */
65                 return(ERROR);
66                 break;
67
68             case '\\':
69                 yytext[count++] = ch;
70                 backSlash = true;
71                 break;
72
73             case 'n':
74                 if (backSlash) {
75                     yytext[count-1] = '\n';
76                 } else {
77                     yytext[count++] = ch;
78                 }
79                 backSlash = false;
80                 break;
81
82             default:
83                 yytext[count++] = ch;
84                 backSlash = false;
85                 break;
86         }
87     }
88 }
89
90 %}
91
92 %%
93
94 if                      { return IF; }
95
96 else                    { return ELSE; }
97
98 [0-9]+                  { dynerlval.ival = atoi(yytext); return NUMBER; }
99
100 [A-za-z][A-Za-z0-9_]*   { dynerlval.sval = strdup(yytext); return IDENTIFIER; }
101
102 \<=                     { return LESS_EQ; }
103
104 \>=                     { return GREATER_EQ; }
105
106 ==                      { return EQ; }
107
108 ,                       { return COMMA; }
109
110 =                       { return ASSIGN; }
111
112 !=                      { return NOT_EQ; }
113  
114 \{                      { return START_BLOCK; }
115
116 \}                      { return END_BLOCK; }
117
118 \.                      { return DOT; }
119
120 ;                       { return SEMI; }
121
122 [()<>+*/-]              { return yytext[0]; }
123
124 &&                      { return AND; }
125
126 \|\|                    { return OR; }
127
128 [ \t\n]+                { /* Nothing */; }
129
130 \"                      { int ret;
131                           ret = doubleQuote();
132                           return(ret);
133                         }
134
135 "++"                    { return PLUSPLUS; }
136
137 "--"                    { return MINUSMINUS; }
138
139 .                       { return ERROR; }
140
141 %%
142
143 void set_lex_input(char *str)
144 {
145     static int firstCall = 1;
146
147     input_str = str;
148
149     if (!firstCall) yy_flush_buffer(YY_CURRENT_BUFFER);
150     firstCall = 0;
151 }
152
153 #ifdef FLEX_SCANNER
154 int my_yyinput(char *buf, int max_size)
155 {
156     int sz = 0;
157
158     while (*input_str != '\0' && sz < max_size) {
159         *buf++ = *input_str++;
160         sz++;
161     }
162
163     return sz;
164 }
165 #endif
166
167 #if !defined(i386_unknown_nt4_0)
168 int yywrap()
169 {
170     return 1;
171 }
172 #endif