init
This commit is contained in:
commit
1f0a783560
9 changed files with 1045 additions and 0 deletions
42
grammar/parser.c
Normal file
42
grammar/parser.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue