parser.c 454 Bytes
Newer Older
lyz's avatar
lyz committed
1
#include "syntax_tree.h"
lxq's avatar
lxq committed
2
extern syntax_tree *parse(const char *);
lyz's avatar
lyz committed
3

lxq's avatar
lxq committed
4
int main(int argc, char *argv[]) {
lyz's avatar
lyz committed
5 6 7 8 9
    syntax_tree *tree = NULL;
    const char *input = NULL;

    if (argc == 2) {
        input = argv[1];
lxq's avatar
lxq committed
10
    } else if (argc >= 3) {
lyz's avatar
lyz committed
11 12 13 14 15 16 17 18 19 20
        printf("usage: %s <cminus_file>\n", argv[0]);
        return 1;
    }

    // Call the syntax analyzer.
    tree = parse(input);
    print_syntax_tree(stdout, tree);
    del_syntax_tree(tree);
    return 0;
}