42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
#include <stdio.h>
|
|
|
|
#define false 0
|
|
#define true 1
|
|
_Bool reached_EOF = false;
|
|
#define YY_INPUT(buf, result, max_size) \
|
|
{ \
|
|
int yyc = getchar(); \
|
|
if (yyc == EOF) { \
|
|
reached_EOF = true; \
|
|
fprintf(stdout, "EOF"); \
|
|
} else { \
|
|
fprintf(stdout, "%c", yyc); \
|
|
} \
|
|
result = (EOF == yyc) ? 0 : (*(buf) = yyc, 1); \
|
|
}
|
|
|
|
#include "peg.c"
|
|
|
|
int main(int argc, char** argv) {
|
|
if (argc < 2) {
|
|
fprintf(stderr, "usage: %s filen.fang [output/file]\n", *argv);
|
|
return -1;
|
|
}
|
|
freopen(argv[1], "r", stdin);
|
|
if (!stdin) {
|
|
fprintf(stderr, "file %s not found\n", argv[1]);
|
|
return -2;
|
|
}
|
|
_Bool newline = true;
|
|
if (argc >= 3) {
|
|
freopen(argv[2], "w", stdout);
|
|
if (!stdout) {
|
|
fprintf(stderr, "file %s not found\n", argv[2]);
|
|
return -2;
|
|
}
|
|
newline = false;
|
|
}
|
|
while (yyparse());
|
|
if (newline) printf("\n");
|
|
return !reached_EOF;
|
|
}
|