-
Notifications
You must be signed in to change notification settings - Fork 1
/
bfconf_lexical.lex
108 lines (90 loc) · 1.86 KB
/
bfconf_lexical.lex
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
/*
* (c) Copyright 2001 -- Anders Torger
*
* This program is open source. For license terms, see the LICENSE file.
*
*/
%{
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "defs.h"
#include "bfconf_grammar.h"
int lexlineno = 0;
%}
%option nounput
%option noyywrap
%option noyylineno
%option noreject
%option fast
%option 8bit
DIGIT [0-9]
ANUM [A-Za-z_0-9]
%%
"\n" {
lexlineno++;
}
"{" { return LBRACE; }
"}" { return RBRACE; }
"," { return COMMA; }
"/" { return SLASH; }
";" { return EOS; }
"#"[^\n]* /* remove one-line comments */
[ \t\r]+ /* remove whitespace */
"coeff" { return COEFF; }
"input" { return INPUT; }
"output" { return OUTPUT; }
"filter" { return FILTER; }
"route" { return FILTER; } /* backwards compability */
"true" {
yylval.boolean = true;
return BOOLEAN;
}
"false" {
yylval.boolean = false;
return BOOLEAN;
}
"\""("\\\""|[^\"])*"\"" {
int n, slen;
slen = strlen(yytext) - 1;
yytext[slen] = '\0';
for (n = 0; n < slen - 1; n++) {
switch ((int)yytext[n]) {
case '\\':
memmove(&yytext[n], &yytext[n+1], slen - n);
slen--;
switch ((int)yytext[n]) {
case 'n':
yytext[n] = '\n';
break;
case 't':
yytext[n] = '\t';
break;
default:
break;
}
break;
case '\n':
lexlineno++;
break;
}
}
yylval.string = &yytext[1];
return STRING;
}
{ANUM}+":" {
yylval.field = yytext;
yylval.field[strlen(yylval.field)-1] = '\0';
return FIELD;
}
("+"|"-")?{DIGIT}*"."?{DIGIT}+("e"("+"|"-"){DIGIT}{2})? {
yylval.real = atof(yytext);
return REAL;
}
<<EOF>> {
return EOF;
}
. {
parse_error("unrecognised token.\n");
}
%%