Manual bugfixes.
[dyninst.git] / dyner / src / cmdline.l
1 %option noyywrap
2
3 %{
4
5 #include <string.h>
6 #include "BPatch_snippet.h"
7 #include "dyner.tab.h"
8
9 extern "C" {
10 void set_lex_input(char *);
11 }
12
13 static char *input_str = NULL;
14
15 #ifdef FLEX_SCANNER
16 #undef YY_INPUT
17
18 #define YY_INPUT(b,r,ms) (r = my_yyinput(b, ms))
19
20 int my_yyinput(char *buf, int max_size);
21
22 #else
23 #undef input
24 #undef unput
25
26 #define input()  (*input_str++)
27 #define unput(c) (*--input_str = c)
28
29 #endif
30
31 static int yyinput(void);
32 static void yyunput(int, char *);
33
34 void yyunput_wrapper(int i, char *s)
35 {
36   yyunput(i, s);
37 }
38
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_T);
60                 }
61                 break;
62
63             case '\n':
64                 /* New line before end of string */
65
66                 return(_ERROR_T);
67                 break;
68
69             case '\\':
70                 yytext[count++] = ch;
71                 backSlash = true;
72                 break;
73
74             case 'n':
75                 if (backSlash) {
76                     yytext[count-1] = '\n';
77                 } else {
78                     yytext[count++] = ch;
79                 }
80                 backSlash = false;
81                 break;
82
83             default:
84                 yytext[count++] = ch;
85                 backSlash = false;
86                 break;
87         }
88     }
89 }
90
91 %}
92
93 %%
94
95 if                      { return IF_T; }
96
97 else                    { return ELSE_T; }
98
99 [0-9]+                  { dynerlval.ival = atoi(yytext); return NUMBER_T; }
100
101 [A-za-z][A-Za-z0-9_]*   { dynerlval.sval = strdup(yytext); return IDENTIFIER_T; }
102
103 \<=                     { return LESS_EQ_T; }
104
105 \>=                     { return GREATER_EQ_T; }
106
107 ==                      { return EQ_T; }
108
109 ,                       { return COMMA_T; }
110
111 =                       { return ASSIGN_T; }
112
113 !=                      { return NOT_EQ_T; }
114  
115 \{                      { return START_BLOCK_T; }
116
117 \}                      { return END_BLOCK_T; }
118
119 \$                      { return DOLLAR_T; }
120
121 \.                      { return DOT_T; }
122
123 ;                       { return SEMI_T; }
124
125 [()<>+*/-]              { return yytext[0]; }
126
127 &&                      { return AND_T; }
128
129 \|\|                    { return OR_T; }
130
131 [ \t\n]+                { /* Nothing */; }
132
133 \"                      { int ret;
134                           ret = doubleQuote();
135                           return(ret);
136                         }
137
138 "++"                    { return PLUSPLUS_T; }
139
140 "--"                    { return MINUSMINUS_T; }
141
142 .                       { return _ERROR_T; }
143
144 %%
145
146 void set_lex_input(char *str)
147 {
148     static int firstCall = 1;
149
150     input_str = str;
151
152     if (!firstCall) yy_flush_buffer(YY_CURRENT_BUFFER);
153     firstCall = 0;
154 }
155
156 #ifdef FLEX_SCANNER
157 int my_yyinput(char *buf, int max_size)
158 {
159     int sz = 0;
160
161     while (*input_str != '\0' && sz < max_size) {
162        *buf++ = *input_str++;
163        sz++;
164     }
165
166     return sz;
167 }
168 #endif