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