Changeset 4145
- Timestamp:
- 09/06/06 04:18:54 (7 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/branches/scanner-opt-branch/lib/conf-lex.l
r4123 r4145 55 55 %option nounput 56 56 57 /* 58 * States. 'Normal' states STRING and MIDDLE share some rules; 59 * other states have only their own rules 60 */ 61 62 %s MIDDLE 57 /* All states are exclusive */ 58 59 %x MIDDLE 63 60 %x STRING 64 61 %x ERR … … 85 82 %% 86 83 87 88 <MIDDLE>\n { /* newline here sends EOL token to parser */ 89 BEGIN(INITIAL); 90 sensors_yylineno++; 91 return EOL; 92 } 93 94 <MIDDLE><<EOF>> { /* EOF here sends EOL token to parser also */ 95 BEGIN(INITIAL); 96 return EOL; 97 } 98 99 {BLANK}+ ; /* eat as many blanks as possible at once */ 84 /* 85 * STATE: INITIAL 86 */ 87 88 <INITIAL>{ 89 90 <<EOF>> { /* EOF from this state terminates */ 91 return 0; 92 } 93 94 {BLANK}+ ; /* eat as many blanks as possible at once */ 100 95 101 96 {BLANK}*\n { /* eat a bare newline (possibly preceded by blanks) */ … … 103 98 } 104 99 105 <MIDDLE>\\{BLANK}*\n { /* eat an escaped newline with no state change */ 106 sensors_yylineno++; 107 } 108 109 <MIDDLE>#.* ; /* eat the rest of the line after comment char */ 110 111 <MIDDLE>#.*\n { /* eat the rest of the line after comment char */ 112 BEGIN(INITIAL); 113 sensors_yylineno++; 114 return EOL; 115 } 100 /* comments */ 116 101 117 102 #.* ; /* eat the rest of the line after comment char */ … … 123 108 /* Some keywords at the beginning of lines */ 124 109 125 <INITIAL>"label"{110 "label" { 126 111 sensors_yylval.line = sensors_yylineno; 127 112 BEGIN(MIDDLE); … … 129 114 } 130 115 131 <INITIAL>"set"{116 "set" { 132 117 sensors_yylval.line = sensors_yylineno; 133 118 BEGIN(MIDDLE); … … 135 120 } 136 121 137 <INITIAL>"compute"{122 "compute" { 138 123 sensors_yylval.line = sensors_yylineno; 139 124 BEGIN(MIDDLE); … … 141 126 } 142 127 143 <INITIAL>"bus"{128 "bus" { 144 129 sensors_yylval.line = sensors_yylineno; 145 130 BEGIN(MIDDLE); … … 147 132 } 148 133 149 <INITIAL>"chip"{134 "chip" { 150 135 sensors_yylval.line = sensors_yylineno; 151 136 BEGIN(MIDDLE); 152 137 return CHIP; 153 138 } 154 <INITIAL>"ignore" { 139 140 "ignore" { 155 141 sensors_yylval.line = sensors_yylineno; 156 142 BEGIN(MIDDLE); … … 160 146 /* Anything else at the beginning of a line is an error */ 161 147 162 <INITIAL>.{148 . { 163 149 yymore(); 164 150 BEGIN(ERR); 165 151 } 166 167 <ERR>[^\n]*\n { 152 } 153 154 /* 155 * STATE: ERROR 156 */ 157 158 <ERR>{ 159 160 .*(\n)? { 168 161 BEGIN(INITIAL); 169 162 strcpy(sensors_lex_error,"Invalid keyword"); 170 163 return ERROR; 171 164 } 165 } 166 167 /* 168 * STATE: MIDDLE 169 */ 170 171 <MIDDLE>{ 172 173 {BLANK}+ ; /* eat as many blanks as possible at once */ 174 175 \n { /* newline here sends EOL token to parser */ 176 BEGIN(INITIAL); 177 sensors_yylineno++; 178 return EOL; 179 } 180 181 <<EOF>> { /* EOF here sends EOL token to parser also */ 182 BEGIN(INITIAL); 183 return EOL; 184 } 185 186 \\{BLANK}*\n { /* eat an escaped newline with no state change */ 187 sensors_yylineno++; 188 } 189 190 #.* ; /* eat the rest of the line after comment char */ 191 192 #.*\n { /* eat the rest of the line after comment char */ 193 BEGIN(INITIAL); 194 sensors_yylineno++; 195 return EOL; 196 } 172 197 173 198 /* A number */ 174 199 175 <MIDDLE>{FLOAT}{200 {FLOAT} { 176 201 sensors_yylval.value = atof(sensors_yytext); 177 202 return FLOAT; … … 180 205 /* Some operators */ 181 206 182 <MIDDLE>"+"return '+';183 <MIDDLE>"-"return '-';184 <MIDDLE>"*"return '*';185 <MIDDLE>"/"return '/';186 <MIDDLE>"("return '(';187 <MIDDLE>")"return ')';188 <MIDDLE>","return ',';189 <MIDDLE>"@"return '@';190 <MIDDLE>"^"return '^';191 <MIDDLE>"`"return '`';207 "+" return '+'; 208 "-" return '-'; 209 "*" return '*'; 210 "/" return '/'; 211 "(" return '('; 212 ")" return ')'; 213 "," return ','; 214 "@" return '@'; 215 "^" return '^'; 216 "`" return '`'; 192 217 193 218 /* Quoted string */ 194 219 195 <MIDDLE>\"{220 \" { 196 221 buffer_malloc(); 197 222 BEGIN(STRING); 198 223 } 199 224 225 /* A normal, unquoted identifier */ 226 227 {IDCHAR}+ { 228 sensors_yylval.name = strdup(sensors_yytext); 229 if (! sensors_yylval.name) 230 sensors_fatal_error("conf-lex.l", 231 "Allocating a new string"); 232 233 return NAME; 234 } 235 236 /* anything else is bogus */ 237 238 . { 239 yymore(); 240 BEGIN(ERR); 241 } 242 } 243 244 /* 245 * STATE: STRING 246 */ 247 248 <STRING>{ 249 200 250 /* Oops, newline while in a string is not good */ 201 251 202 <STRING>\n|203 <STRING>\\\n{252 \n | 253 \\\n { 204 254 buffer_add_char("\0"); 205 255 strcpy(sensors_lex_error,"No matching double quote"); … … 211 261 /* At the end */ 212 262 213 <STRING>\"{263 \" { 214 264 buffer_add_char("\0"); 215 265 sensors_yylval.name = strdup(buffer); … … 222 272 } 223 273 224 <STRING>\\a{274 \\a { 225 275 buffer_add_char("\a"); 226 276 } 227 277 228 <STRING>\\b{278 \\b { 229 279 buffer_add_char("\b"); 230 280 } 231 281 232 <STRING>\\f{282 \\f { 233 283 buffer_add_char("\f"); 234 284 } 235 285 236 <STRING>\\n{286 \\n { 237 287 buffer_add_char("\n"); 238 288 } 239 289 240 <STRING>\\r{290 \\r { 241 291 buffer_add_char("\r"); 242 292 } 243 293 244 <STRING>\\t{294 \\t { 245 295 buffer_add_char("\t"); 246 296 } 247 297 248 <STRING>\\v{298 \\v { 249 299 buffer_add_char("\v"); 250 300 } … … 252 302 /* We can't support \0, this would cause havoc! */ 253 303 254 <STRING>\\{OCTESC}{304 \\{OCTESC} { 255 305 int res; 256 306 sscanf(sensors_yytext+1,"%o",&res); … … 260 310 /* Other escapes: just copy the character behind the slash */ 261 311 262 <STRING>\\.{312 \\. { 263 313 buffer_add_char(&sensors_yytext[1]); 264 314 } … … 266 316 /* Anything else */ 267 317 268 <STRING>[^\\\n\"]+{318 [^\\\n\"]+ { 269 319 buffer_add_string(sensors_yytext); 270 320 } 271 272 /* A normal, unquoted identifier */ 273 274 <MIDDLE>{IDCHAR}+ { 275 sensors_yylval.name = strdup(sensors_yytext); 276 if (! sensors_yylval.name) 277 sensors_fatal_error("conf-lex.l", 278 "Allocating a new string"); 279 280 return NAME; 281 } 321 } 282 322 283 323 %%
