]>
Commit | Line | Data |
---|---|---|
ffc11f03 CP |
1 | %option noyywrap |
2 | ||
3 | %{ | |
946729bd | 4 | |
9b276ca6 CP |
5 | #include <stdlib.h> |
6 | #include <string.h> | |
7 | ||
e828314e | 8 | #include "../lib/sstring.h" |
ffc11f03 | 9 | |
e828314e | 10 | #define YYSTYPE sstring * |
ffc11f03 CP |
11 | extern YYSTYPE yylval; |
12 | ||
e828314e | 13 | #include "y.tab.h" |
ffc11f03 CP |
14 | #include "../lib/stringbuf.h" |
15 | ||
16 | #define MAX_STR_CONST 512 | |
e828314e | 17 | |
9b276ca6 CP |
18 | int lexpos, lexerror; |
19 | ||
20 | #define addpos(x) lexpos+=x; | |
21 | #define incpos() addpos(1); | |
22 | ||
23 | void lexreset(void) { | |
24 | lexerror = 0; | |
25 | lexpos = -1; | |
26 | } | |
27 | ||
ffc11f03 CP |
28 | %} |
29 | ||
30 | digit [0-9] | |
31 | letter [a-zA-Z] | |
32 | ||
4324be96 | 33 | %x str pascalstr |
ffc11f03 CP |
34 | %% |
35 | ||
36 | char bufdata[MAX_STR_CONST]; | |
37 | StringBuf buf; | |
38 | ||
9b276ca6 | 39 | \" { incpos(); |
ffc11f03 CP |
40 | sbinit(&buf, bufdata, sizeof(bufdata)); |
41 | BEGIN(str); | |
42 | } | |
43 | ||
44 | <str>{ | |
9b276ca6 | 45 | \" { incpos(); |
ffc11f03 CP |
46 | BEGIN(INITIAL); |
47 | sbterminate(&buf); | |
e828314e | 48 | yylval = getsstring(bufdata, 512); |
ffc11f03 CP |
49 | return STRING; |
50 | } | |
9b276ca6 CP |
51 | \\\\ { addpos(2); |
52 | sbaddchar(&buf, '\\'); | |
53 | } | |
54 | \\\" { addpos(2); | |
55 | sbaddchar(&buf, '"'); | |
56 | } | |
57 | [^\\] { incpos(); | |
58 | sbaddchar(&buf, *yytext); | |
59 | } | |
ffc11f03 CP |
60 | } |
61 | ||
9b276ca6 | 62 | \' { incpos(); |
4324be96 CP |
63 | sbinit(&buf, bufdata, sizeof(bufdata)); |
64 | BEGIN(pascalstr); | |
65 | } | |
66 | ||
67 | <pascalstr>{ | |
9b276ca6 CP |
68 | \'\' { addpos(2); |
69 | sbaddchar(&buf, '\''); | |
70 | } | |
71 | \' { incpos(); | |
4324be96 CP |
72 | BEGIN(INITIAL); |
73 | sbterminate(&buf); | |
74 | yylval = getsstring(bufdata, 512); | |
75 | return STRING; | |
76 | } | |
9b276ca6 CP |
77 | . { incpos(); |
78 | sbaddchar(&buf, *yytext); | |
79 | } | |
4324be96 CP |
80 | } |
81 | ||
9b276ca6 CP |
82 | "(" { incpos(); |
83 | return LPAREN; | |
84 | } | |
85 | ")" { incpos(); | |
86 | return RPAREN; | |
87 | } | |
88 | [ \t]+ { addpos(strlen(yytext)); | |
89 | return WHITESPACE; | |
90 | } | |
dd7fb4db | 91 | ({letter}|{digit}|[#\-\+\.\*])+ { addpos(strlen(yytext)); |
e828314e | 92 | yylval = getsstring(yytext, 512); |
ffc11f03 CP |
93 | return IDENTIFIER; |
94 | } | |
95 | ||
9b276ca6 CP |
96 | [\n\r] { incpos(); |
97 | /* ignore */; | |
98 | } | |
99 | ||
100 | . { | |
101 | incpos(); | |
102 | lexerror = 1; | |
103 | yyterminate(); | |
104 | } | |
ffc11f03 CP |
105 | |
106 | <<EOF>> { | |
107 | BEGIN(INITIAL); | |
108 | yyterminate(); | |
109 | } | |
110 | %% | |
946729bd CP |
111 | |
112 | void ydummyfn(void) { | |
113 | yyunput(0, NULL); | |
114 | } |