mirror of
https://github.com/pnx/m16vm
synced 2026-06-18 04:00:02 +02:00
asm: adding the parser
This commit is contained in:
parent
16501e40be
commit
3528c467ac
4 changed files with 254 additions and 17 deletions
38
src/as/as.c
38
src/as/as.c
|
|
@ -19,36 +19,42 @@
|
|||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
|
||||
int usage(char *program) {
|
||||
|
||||
fprintf(stderr, "Usage: %s <string>\n", program);
|
||||
fprintf(stderr, "Usage: %s <inputfile> [ <outputfile ]\n", program);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
FILE *fd;
|
||||
struct lexer lex;
|
||||
FILE *fd_in;
|
||||
FILE *fd_out = stdout;
|
||||
|
||||
if (argc < 2)
|
||||
return usage(argv[0]);
|
||||
|
||||
fd = fopen(argv[1], "r");
|
||||
if (fd == NULL)
|
||||
fd_in = fopen(argv[1], "r");
|
||||
if (fd_in == NULL) {
|
||||
perror("Could not open input file");
|
||||
return -1;
|
||||
|
||||
lexer_init(&lex, fd);
|
||||
|
||||
do {
|
||||
if (lexer_get_next(&lex) < 0)
|
||||
break;
|
||||
|
||||
lexer_print_token(&lex.token);
|
||||
} while(lex.token.type != TOKEN_EOI);
|
||||
}
|
||||
|
||||
|
||||
fclose(fd);
|
||||
// If we have a output file.
|
||||
if (argc > 2) {
|
||||
fd_out = fopen(argv[2], "w");
|
||||
if (fd_out == NULL) {
|
||||
perror("Could not open output file");
|
||||
fclose(fd_in);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
parse(fd_in, fd_out);
|
||||
|
||||
fclose(fd_in);
|
||||
fclose(fd_out);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue