From 62ba30ec8c042da8d9762150bd15d1bd8fa70309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind?= Date: Sun, 13 Feb 2022 17:42:50 +0100 Subject: [PATCH] Added yylex_destroy --- exercises/02/vslc/src/vslc.c | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 exercises/02/vslc/src/vslc.c diff --git a/exercises/02/vslc/src/vslc.c b/exercises/02/vslc/src/vslc.c new file mode 100644 index 0000000..4a4ed91 --- /dev/null +++ b/exercises/02/vslc/src/vslc.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + + +/* Global state */ + +node_t *root; // Syntax tree + + +/* Command line option parsing for the main function */ +static void options ( int argc, char **argv ); +bool + print_full_tree = false; + + +/* Entry point */ +int +main ( int argc, char **argv ) +{ + options ( argc, argv ); + + yyparse(); // Generated from grammar/bison, constructs syntax tree + + yylex_destroy(); // Free heap used by flex + + if ( print_full_tree ) + print_syntax_tree(); + + destroy_syntax_tree(); // In tree.c +} + + +static const char *usage = +"Command line options\n" +"\t-h\tOutput this text and halt\n" +"\t-t\tOutput the full syntax tree\n"; + + +static void +options ( int argc, char **argv ) +{ + int o; + while ( (o=getopt(argc,argv,"ht")) != -1 ) + { + switch ( o ) + { + case 'h': + printf ( "%s:\n%s", argv[0], usage ); + exit ( EXIT_FAILURE ); + break; + case 't': print_full_tree = true; break; + } + } +} +