File: modula.re

package info (click to toggle)
yasm 1.3.0-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,880 kB
  • sloc: asm: 74,423; ansic: 53,055; python: 9,927; sh: 5,276; xml: 1,617; makefile: 214; pascal: 95; sed: 16
file content (202 lines) | stat: -rw-r--r-- 4,840 bytes parent folder | download | duplicates (22)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef unsigned int uint;
typedef unsigned char uchar;

#define	BSIZE	8192

#define	YYCTYPE		uchar
#define	YYCURSOR	cursor
#define	YYLIMIT		s->lim
#define	YYMARKER	s->ptr
#define	YYFILL		{cursor = fill(s, cursor);}

#define	RETURN(i)	{s->cur = cursor; return i;}

typedef struct Scanner {
    int			fd;
    uchar		*bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof;
    uint		line;
} Scanner;

uchar *fill(Scanner *s, uchar *cursor){
    if(!s->eof){
	uint cnt = s->tok - s->bot;
	if(cnt){
	    memcpy(s->bot, s->tok, s->lim - s->tok);
	    s->tok = s->bot;
	    s->ptr -= cnt;
	    cursor -= cnt;
	    s->pos -= cnt;
	    s->lim -= cnt;
	}
	if((s->top - s->lim) < BSIZE){
	    uchar *buf = (uchar*) malloc(((s->lim - s->bot) + BSIZE)*sizeof(uchar));
	    memcpy(buf, s->tok, s->lim - s->tok);
	    s->tok = buf;
	    s->ptr = &buf[s->ptr - s->bot];
	    cursor = &buf[cursor - s->bot];
	    s->pos = &buf[s->pos - s->bot];
	    s->lim = &buf[s->lim - s->bot];
	    s->top = &s->lim[BSIZE];
	    free(s->bot);
	    s->bot = buf;
	}
	if((cnt = read(s->fd, (char*) s->lim, BSIZE)) != BSIZE){
	    s->eof = &s->lim[cnt]; *(s->eof)++ = '\n';
	}
	s->lim += cnt;
    }
    return cursor;
}

int scan(Scanner *s){
	uchar *cursor = s->cur;
	uint depth;
std:
	s->tok = cursor;
/*!re2c
any	= [\000-\377];
digit	= [0-9];
letter	= [a-zA-Z];
*/

/*!re2c
	"(*"			{ depth = 1; goto comment; }

	digit +			{RETURN(1);}
	digit + / ".."   	{RETURN(1);}
	[0-7] + "B"        	{RETURN(2);}
	[0-7] + "C"        	{RETURN(3);}
	digit [0-9A-F] * "H"	{RETURN(4);}
	digit + "." digit * ("E" ([+-]) ? digit +) ?	{RETURN(5);}
	['] (any\[\n']) * [']	| ["] (any\[\n"]) * ["]	{RETURN(6);}

	"#"              	{RETURN(7);}
	"&"              	{RETURN(8);}
	"("              	{RETURN(9);}
	")"              	{RETURN(10);}
	"*"              	{RETURN(11);}
	"+"              	{RETURN(12);}
	","              	{RETURN(13);}
	"-"              	{RETURN(14);}
	"."              	{RETURN(15);}
	".."             	{RETURN(16);}
	"/"              	{RETURN(17);}
	":"              	{RETURN(18);}
	":="             	{RETURN(19);}
	";"              	{RETURN(20);}
	"<"              	{RETURN(21);}
	"<="             	{RETURN(22);}
	"<>"             	{RETURN(23);}
	"="              	{RETURN(24);}
	">"              	{RETURN(25);}
	">="             	{RETURN(26);}
	"["              	{RETURN(27);}
	"]"              	{RETURN(28);}
	"^"              	{RETURN(29);}
	"{"              	{RETURN(30);}
	"|"              	{RETURN(31);}
	"}"              	{RETURN(32);}
	"~"              	{RETURN(33);}

	"AND"              	{RETURN(34);}
	"ARRAY"            	{RETURN(35);}
	"BEGIN"           	{RETURN(36);}
	"BY"               	{RETURN(37);}
	"CASE"             	{RETURN(38);}
	"CONST"            	{RETURN(39);}
	"DEFINITION"       	{RETURN(40);}
	"DIV"              	{RETURN(41);}
	"DO"               	{RETURN(42);}
	"ELSE"             	{RETURN(43);}
	"ELSIF"            	{RETURN(44);}
	"END"              	{RETURN(45);}
	"EXIT"             	{RETURN(46);}
	"EXPORT"          	{RETURN(47);}
	"FOR"              	{RETURN(48);}
	"FROM"             	{RETURN(49);}
	"IF"               	{RETURN(50);}
	"IMPLEMENTATION"   	{RETURN(51);}
	"IMPORT"           	{RETURN(52);}
	"IN"               	{RETURN(53);}
	"LOOP"             	{RETURN(54);}
	"MOD"              	{RETURN(55);}
	"MODULE"           	{RETURN(56);}
	"NOT"              	{RETURN(57);}
	"OF"               	{RETURN(58);}
	"OR"               	{RETURN(59);}
	"POINTER"          	{RETURN(60);}
	"PROCEDURE"        	{RETURN(61);}
	"QUALIFIED"        	{RETURN(62);}
	"RECORD"           	{RETURN(63);}
	"REPEAT"           	{RETURN(64);}
	"RETURN"           	{RETURN(65);}
	"SET"              	{RETURN(66);}
	"THEN"             	{RETURN(67);}
	"TO"               	{RETURN(68);}
	"TYPE"             	{RETURN(69);}
	"UNTIL"            	{RETURN(70);}
	"VAR"              	{RETURN(71);}
	"WHILE"            	{RETURN(72);}
	"WITH"             	{RETURN(73);}

	letter (letter | digit) *	{RETURN(74);}

	[ \t]+			{ goto std; }

	"\n"
	    {
		if(cursor == s->eof) RETURN(0);
		s->pos = cursor; s->line++;
		goto std;
	    }

	any
	    {
		printf("unexpected character: %c\n", *s->tok);
		goto std;
	    }
*/
comment:
/*!re2c
	"*)"
	    {
		if(--depth == 0)
		    goto std;
		else
		    goto comment;
	    }
	"(*"			{ ++depth; goto comment; }
	"\n"
	    {
		if(cursor == s->eof) RETURN(0);
		s->tok = s->pos = cursor; s->line++;
		goto comment;
	    }
        any			{ goto comment; }
*/
}

/*
void putStr(FILE *o, char *s, uint l){
    while(l-- > 0)
	putc(*s++, o);
}
*/

main(){
    Scanner in;
    memset((char*) &in, 0, sizeof(in));
    in.fd = 0;
    while(scan(&in)){
/*
	putc('<', stdout);
	putStr(stdout, (char*) in.tok, in.cur - in.tok);
	putc('>', stdout);
	putc('\n', stdout);
*/
    }
}