| 896 |
push_int(&(env->head), env->err); |
push_int(&(env->head), env->err); |
| 897 |
} |
} |
| 898 |
|
|
| 899 |
|
extern void read(environment*); |
| 900 |
|
|
| 901 |
int main() |
int main() |
| 902 |
{ |
{ |
| 903 |
environment myenv; |
environment myenv; |
|
char in_string[100]; |
|
| 904 |
|
|
| 905 |
init_env(&myenv); |
init_env(&myenv); |
| 906 |
|
|
| 907 |
printf("okidok\n "); |
while(1) { |
| 908 |
|
fprintf(stderr, "okidok\n "); |
| 909 |
while(fgets(in_string, 100, stdin) != NULL) { |
read(&myenv); |
|
stack_read(&myenv, in_string); |
|
| 910 |
if(myenv.err) { |
if(myenv.err) { |
| 911 |
printf("(error %d) ", myenv.err); |
printf("(error %d) ", myenv.err); |
| 912 |
myenv.err=0; |
myenv.err=0; |
| 913 |
|
} else if(myenv.head->item->type==symb |
| 914 |
|
&& ((symbol*)(myenv.head->item->content.ptr))->id[0]==';') { |
| 915 |
|
toss(&myenv); /* No error check in main */ |
| 916 |
|
eval(&myenv); |
| 917 |
} |
} |
|
printf("okidok\n "); |
|
| 918 |
} |
} |
| 919 |
quit(&myenv); |
quit(&myenv); |
| 920 |
return EXIT_FAILURE; |
return EXIT_FAILURE; |
| 1259 |
|
|
| 1260 |
push_sym(env, "["); |
push_sym(env, "["); |
| 1261 |
|
|
| 1262 |
for(i= start; i<= ending; i++) |
if(ending>=start) { |
| 1263 |
push_int(&(env->head), i); |
for(i= start; i<=ending; i++) |
| 1264 |
|
push_int(&(env->head), i); |
| 1265 |
|
} else { |
| 1266 |
|
for(i= start; i>=ending; i--) |
| 1267 |
|
push_int(&(env->head), i); |
| 1268 |
|
} |
| 1269 |
|
|
| 1270 |
push_sym(env, "["); |
push_sym(env, "["); |
| 1271 |
pack(env); if(env->err) return; |
pack(env); if(env->err) return; |
| 1272 |
} |
} |
| 1273 |
|
|
| 1274 |
|
/* Read a string */ |
| 1275 |
|
extern void readline(environment *env) { |
| 1276 |
|
char in_string[101]; |
| 1277 |
|
|
| 1278 |
|
fgets(in_string, 100, stdin); |
| 1279 |
|
push_cstring(&(env->head), in_string); |
| 1280 |
|
} |
| 1281 |
|
|
| 1282 |
|
/* Read a value and place on stack */ |
| 1283 |
|
extern void read(environment *env) { |
| 1284 |
|
const char symbform[]= "%[a-zA-Z0-9!$%*+./:<=>?@^_~-]%100c"; |
| 1285 |
|
const char strform[]= "\"%[^\"]\"%100c"; |
| 1286 |
|
const char intform[]= "%i%100c"; |
| 1287 |
|
const char blankform[]= "%*[ \t]%100c"; |
| 1288 |
|
const char ebrackform[]= "%*1[]]%100c"; |
| 1289 |
|
const char semicform[]= "%*1[;]%100c"; |
| 1290 |
|
const char bbrackform[]= "%*1[[]%100c"; |
| 1291 |
|
|
| 1292 |
|
int itemp, rerun= 0; |
| 1293 |
|
static int depth= 0; |
| 1294 |
|
char *rest, *match; |
| 1295 |
|
static char *in_string= NULL; |
| 1296 |
|
size_t inlength; |
| 1297 |
|
|
| 1298 |
|
if(in_string==NULL) { |
| 1299 |
|
readline(env); if(env->err) return; |
| 1300 |
|
|
| 1301 |
|
in_string= malloc(strlen(env->head->item->content.ptr)+1); |
| 1302 |
|
strcpy(in_string, env->head->item->content.ptr); |
| 1303 |
|
toss(env); if(env->err) return; |
| 1304 |
|
} |
| 1305 |
|
|
| 1306 |
|
inlength= strlen(in_string)+1; |
| 1307 |
|
match= malloc(inlength); |
| 1308 |
|
rest= malloc(inlength); |
| 1309 |
|
|
| 1310 |
|
if(sscanf(in_string, blankform, rest)) { |
| 1311 |
|
rerun= 1; |
| 1312 |
|
} else if(sscanf(in_string, intform, &itemp, rest) > 0) { |
| 1313 |
|
push_int(&(env->head), itemp); |
| 1314 |
|
} else if(sscanf(in_string, strform, match, rest) > 0) { |
| 1315 |
|
push_cstring(&(env->head), match); |
| 1316 |
|
} else if(sscanf(in_string, symbform, match, rest) > 0) { |
| 1317 |
|
push_sym(env, match); |
| 1318 |
|
} else if(sscanf(in_string, ebrackform, rest) > 0) { |
| 1319 |
|
push_sym(env, "["); |
| 1320 |
|
pack(env); if(env->err) return; |
| 1321 |
|
if(depth!=0) depth--; |
| 1322 |
|
} else if(sscanf(in_string, semicform, rest) > 0) { |
| 1323 |
|
push_sym(env, ";"); |
| 1324 |
|
} else if(sscanf(in_string, bbrackform, rest) > 0) { |
| 1325 |
|
push_sym(env, "["); |
| 1326 |
|
depth++; |
| 1327 |
|
} else { |
| 1328 |
|
free(rest); |
| 1329 |
|
rest= NULL; |
| 1330 |
|
rerun= 1; |
| 1331 |
|
} |
| 1332 |
|
|
| 1333 |
|
free(in_string); |
| 1334 |
|
free(match); |
| 1335 |
|
|
| 1336 |
|
in_string= rest; |
| 1337 |
|
|
| 1338 |
|
if(rerun || depth) |
| 1339 |
|
return read(env); |
| 1340 |
|
} |