Line 126... |
Line 126... |
$$ = new DLINE($1->eval());
|
$$ = new DLINE($1->eval());
|
else {
|
else {
|
$$ = new VLINE();
|
$$ = new VLINE();
|
yyerror("ERROR: word list undefined");
|
yyerror("ERROR: word list undefined");
|
}}
|
}}
|
| expr COMMA wordlist {
|
| wordlist COMMA expr {
|
if ($1->isdefined())
|
if ($3->isdefined()) {
|
$$ = new DLINE($1->eval());
|
LLINE *ln;
|
else {
|
if ($1->m_state == 'L') {
|
|
ln = ((LLINE *)$1);
|
|
} else {
|
|
ln = new LLINE();
|
|
ln->addline($1);
|
|
} ln->addline(new DLINE($3->eval()));
|
|
$$ = ln;
|
|
} else {
|
$$ = new VLINE();
|
$$ = new VLINE();
|
yyerror("ERROR: word list undefined\n");
|
yyerror("ERROR: word list undefined\n");
|
}}
|
}}
|
;
|
;
|
|
|
Line 404... |
Line 411... |
void yyerror(const char *str) {
|
void yyerror(const char *str) {
|
fprintf(stderr, "%s:%d: ERROR: %s\n", master_input_filename, yylineno, str);
|
fprintf(stderr, "%s:%d: ERROR: %s\n", master_input_filename, yylineno, str);
|
if (linecp) fprintf(stderr, "Offending line was: %s\n", linecp);
|
if (linecp) fprintf(stderr, "Offending line was: %s\n", linecp);
|
}
|
}
|
|
|
FILE *run_preprocessor(const char *zname = NULL) {
|
FILE *run_preprocessor(const char *path = NULL, const char *zname = NULL) {
|
int pipefd[2];
|
int pipefd[2];
|
int pid;
|
int pid;
|
|
|
if (pipe(pipefd)!=0) {
|
if (pipe(pipefd)!=0) {
|
fprintf(stderr, "PIPE FAILED!\n");
|
fprintf(stderr, "PIPE FAILED!\n");
|
Line 423... |
Line 430... |
|
|
if (0 == (pid = fork())) {
|
if (0 == (pid = fork())) {
|
int fdin, fdout;
|
int fdin, fdout;
|
|
|
// Child process -- run the preprocessor
|
// Child process -- run the preprocessor
|
if (zname) {
|
|
fdin = open(zname, O_RDONLY);
|
|
close(STDIN_FILENO);
|
|
dup2(fdin, STDIN_FILENO);
|
|
} // else use stdin, already set up
|
|
|
|
|
// Close the reader: we write only
|
close(pipefd[0]);
|
close(pipefd[0]);
|
|
|
|
// Adjust stdout to write to our pipe instead of anywhere else
|
fdout = pipefd[1];
|
fdout = pipefd[1];
|
close(STDOUT_FILENO);
|
close(STDOUT_FILENO);
|
dup2(fdout, STDOUT_FILENO);
|
dup2(fdout, STDOUT_FILENO);
|
|
|
|
char *zpp_path;
|
|
if (path != NULL) {
|
|
zpp_path = new char[strlen(path+1+strlen("/zpp"))];
|
|
strcpy(zpp_path, path);
|
|
strcat(zpp_path, "/zpp");
|
|
} else zpp_path = strdup("zpp");
|
|
|
// This call should never return
|
// This call should never return
|
execlp("./zpp", "zpp", NULL);
|
// We have to pass the name here, rather than an open file,
|
|
// since zpp needs to mark for us what file it is in at all
|
|
// times.
|
|
if (zname)
|
|
execlp(zpp_path, "zpp", zname, NULL);
|
|
else
|
|
execlp(zpp_path, "zpp", NULL);
|
|
|
fprintf(stderr, "Could not start pre-processor!\n");
|
fprintf(stderr, "Could not start pre-processor!\n");
|
perror("O/S Err:");
|
perror("O/S Err:");
|
|
|
exit(-5);
|
exit(-5);
|
Line 451... |
Line 468... |
}
|
}
|
|
|
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
int skp = 0;
|
int skp = 0;
|
const char *zout_fname = NULL;
|
const char *zout_fname = NULL;
|
|
char *path_to_zasm = NULL;
|
|
bool preprocess_only = false;
|
master_input_filename = NULL;
|
master_input_filename = NULL;
|
|
|
|
// Find what directory zasm is in, so that we can find zpp when
|
|
// necessary.
|
|
path_to_zasm = NULL;
|
|
if (strchr(argv[0], '/')) {
|
|
path_to_zasm = strdup(argv[0]);
|
|
char *ptr = strrchr(path_to_zasm,'/');
|
|
*ptr = '\0';
|
|
}
|
|
|
skp=1;
|
skp=1;
|
for(int argn=0; argn+skp
|
for(int argn=0; argn+skp
|
if (argv[argn+skp][0] == '-') {
|
if (argv[argn+skp][0] == '-') {
|
if (argv[argn+skp][1] == 'o') {
|
if (argv[argn+skp][1] == 'o') {
|
if (zout_fname)
|
if (zout_fname)
|
free((void *)zout_fname);
|
free((void *)zout_fname);
|
zout_fname = strdup(argv[argn+skp+1]);
|
zout_fname = strdup(argv[argn+skp+1]);
|
skp++;
|
skp++;
|
}
|
} else if (argv[argn+skp][1] == 'E')
|
|
preprocess_only = true;
|
|
|
skp++;
|
skp++;
|
} argv[argn] = argv[argn+skp];
|
} argv[argn] = argv[argn+skp];
|
} argc -= skp;
|
} argc -= skp;
|
|
|
|
if (preprocess_only) {
|
|
objcode.open("/dev/null");
|
|
} else {
|
if (!zout_fname)
|
if (!zout_fname)
|
zout_fname = "z.out";
|
zout_fname = "z.out";
|
|
|
objcode.open(zout_fname);
|
objcode.open(zout_fname);
|
|
}
|
|
|
master_input_filename = NULL;
|
master_input_filename = NULL;
|
|
|
if (argc > 0) {
|
if (argc > 0) {
|
for(int argn=0; argn
|
for(int argn=0; argn
|
Line 484... |
Line 517... |
|
|
create_new_context();
|
create_new_context();
|
if (master_input_filename)
|
if (master_input_filename)
|
free(master_input_filename);
|
free(master_input_filename);
|
master_input_filename = strdup(argv[argn]);
|
master_input_filename = strdup(argv[argn]);
|
yyrestart(run_preprocessor(master_input_filename));
|
if (preprocess_only) {
|
|
FILE *fp = run_preprocessor(path_to_zasm, master_input_filename);
|
|
int ch;
|
|
while(EOF != (ch = fgetc(fp)))
|
|
fputc(ch, stdout);
|
|
} else {
|
|
yyrestart(run_preprocessor(path_to_zasm, master_input_filename));
|
yylineno = 1;
|
yylineno = 1;
|
yyparse();
|
yyparse();
|
}
|
}
|
|
}
|
} else { // Run from Stdin
|
} else { // Run from Stdin
|
extern FILE *yyin;
|
extern FILE *yyin;
|
extern void yyrestart(FILE *);
|
extern void yyrestart(FILE *);
|
|
|
create_new_context();
|
create_new_context();
|
master_input_filename = strdup("(stdin)");
|
master_input_filename = strdup("(stdin)");
|
|
if (preprocess_only) {
|
|
int ch;
|
|
FILE *fp = run_preprocessor(path_to_zasm, master_input_filename);
|
|
while(EOF != (ch = fgetc(fp)))
|
|
fputc(ch, stdout);
|
|
} else {
|
yyin = run_preprocessor(NULL);
|
yyin = run_preprocessor(NULL);
|
yyrestart(yyin);
|
yyrestart(yyin);
|
yyparse();
|
yyparse();
|
}
|
}
|
|
}
|
|
|
if (!objcode.reduce())
|
if (!objcode.reduce())
|
fprintf(stderr, "Not all symbols defined!\n");
|
fprintf(stderr, "Not all symbols defined!\n");
|
}
|
}
|
|
|