blob: 6dd8408306f640bae3f80f2fd8df450402375f93 (
plain)
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
|
namespace string
lex
literal `"
token data /[^"\\]+/
token escape /'\\' any/
end
def string_data
[data]
| [escape]
def string
[`" string_data* `"]
str unquote( S: string )
{
match S [`" DL: string_data* `"]
for E: escape in DL
E.data = 'x'
return $DL
}
end # string
namespace hash
lex
literal `define `include
literal `#
token NL /'\n'/ -ni
token id /[a-zA-Z_][a-zA-Z_0-9]*/
token number /[0-9]+/
ignore /[ \t]/
end
def hash
[`# `define Id: id number NL]
| [`# `include Inc: string::string NL]
end # hash
token rest_of_line /[^\n]* '\n'/
namespace lang
lex
ignore /space/
literal `* `( `) `;
token id /[a-zA-Z_][a-zA-Z_0-9]*/
token number /[0-9]+/
token hash /'#'/ {
parse_stop H: hash::hash[ input ]
if ( H ) {
if ( H.Inc ) {
FN: str = string::unquote( H.Inc )
print[ 'opening ' FN '\n' ]
IS: stream = open( FN, 'r' )
if ( ! IS ) {
print[ 'ERROR: failed to open ' FN '\n' ]
exit(1)
}
input->push_stream( IS )
}
}
else {
parse_stop L: rest_of_line[ input ]
if ! L {
print[ "ERROR: stuck: " error ]
exit(1)
}
print[ "ERROR: failed to parse # directive: " L ]
}
}
end
def item
[id]
| [`( item* `)]
def statement
[item* `;]
def start
[statement*]
end # lang
parse Input: lang::start[ stdin ]
if ! Input
print[ error '\n' ]
else {
print[ @Input ]
}
##### IN #####
hello;
#include "inpush1a.in"
there;
#include "inpush1b.in"
dude;
#include "inpush1c.in"
and dudettes;
##### EXP #####
opening inpush1a.in
opening inpush1b.in
opening inpush1c.in
hello;
a;
b;
there;
c;
d;
dude;
e;
f;
and dudettes;
|