diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-10-29 23:36:52 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-10-29 23:36:52 -0400 |
commit | f5f8d18d86e15e0bd14f955768edb616e1357a66 (patch) | |
tree | bf8398673c364bb2475baf8946631779ef443d8b | |
parent | 29963e449e8e4c8a3b4eeda9ef9a57083184697d (diff) | |
download | dimension-f5f8d18d86e15e0bd14f955768edb616e1357a66.tar.xz |
Skeleton of parser and realizer.
-rw-r--r-- | dimension/Makefile.am | 4 | ||||
-rw-r--r-- | dimension/main.c | 56 | ||||
-rw-r--r-- | dimension/parse.c | 39 | ||||
-rw-r--r-- | dimension/parse.h | 29 | ||||
-rw-r--r-- | dimension/realize.c | 28 | ||||
-rw-r--r-- | dimension/realize.h | 22 |
6 files changed, 169 insertions, 9 deletions
diff --git a/dimension/Makefile.am b/dimension/Makefile.am index da8d86d..5445c80 100644 --- a/dimension/Makefile.am +++ b/dimension/Makefile.am @@ -22,6 +22,10 @@ INCLUDES = -I$(top_srcdir)/libdimension bin_PROGRAMS = dimension dimension_SOURCES = main.c \ + parse.c \ + parse.h \ + realize.c \ + realize.h \ tokenize.c \ tokenize.h \ utility.c \ diff --git a/dimension/main.c b/dimension/main.c index 76c5ff6..990ee14 100644 --- a/dimension/main.c +++ b/dimension/main.c @@ -18,16 +18,17 @@ *************************************************************************/ #include "tokenize.h" +#include "parse.h" +#include "realize.h" #include "../libdimension/dimension.h" #include <stdlib.h> #include <getopt.h> static const char *output = NULL, *input = NULL; -static int tokenize = 0; +static int tokenize = 0, parse = 0; int main(int argc, char **argv) { - dmnsn_array *tokens; FILE *input_file, *output_file; /* @@ -38,6 +39,7 @@ main(int argc, char **argv) { { "output", required_argument, NULL, 'o' }, { "input", required_argument, NULL, 'i' }, { "tokenize", no_argument, &tokenize, 1 }, + { "parse", no_argument, &parse, 1 }, { 0, 0, 0, 0 } }; int opt, opt_index; @@ -81,10 +83,11 @@ main(int argc, char **argv) { input = argv[optind]; } } else if (optind < argc) { - dmnsn_error(DMNSN_SEVERITY_HIGH, "Invalid extranious command line options."); + dmnsn_error(DMNSN_SEVERITY_HIGH, + "Invalid extranious command line options."); } - if (!output && !tokenize) { + if (!output && !(tokenize || parse)) { dmnsn_error(DMNSN_SEVERITY_HIGH, "No output file specified."); } if (!input) { @@ -98,33 +101,68 @@ main(int argc, char **argv) { } /* Tokenize the input file */ - tokens = dmnsn_tokenize(input, input_file); + dmnsn_array *tokens = dmnsn_tokenize(input, input_file); if (!tokens) { fclose(input_file); dmnsn_error(DMNSN_SEVERITY_HIGH, "Error tokenizing input file."); } + fclose(input_file); /* Debugging option - output the list of tokens as an S-expression */ if (tokenize) { dmnsn_print_token_sexpr(stdout, tokens); + + if (!parse) { + dmnsn_delete_tokens(tokens); + return EXIT_SUCCESS; + } + } + + /* Parse the input */ + dmnsn_array *astree = dmnsn_parse(tokens); + if (!astree) { dmnsn_delete_tokens(tokens); - fclose(input_file); + dmnsn_error(DMNSN_SEVERITY_HIGH, "Error parsing input file."); + } + dmnsn_delete_tokens(tokens); + + /* Debugging option - output the abstract syntax tree as an S-expression */ + if (parse) { + dmnsn_print_astree_sexpr(stdout, astree); + dmnsn_delete_astree(astree); return EXIT_SUCCESS; } + /* Realize the input */ + dmnsn_scene *scene = dmnsn_realize(astree); + if (!scene) { + dmnsn_delete_astree(astree); + dmnsn_error(DMNSN_SEVERITY_HIGH, "Error realizing input file."); + } + dmnsn_delete_astree(astree); + /* * Now we render the scene */ + if (dmnsn_raytrace_scene(scene) != 0) { + dmnsn_delete_scene(scene); + dmnsn_error(DMNSN_SEVERITY_HIGH, "Error rendering scene."); + } + dmnsn_delete_scene(scene); + /* Open the output file */ output_file = fopen(output, "wb"); if (!output_file) { dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't open output file."); } - /* Clean up and exit! */ - dmnsn_delete_tokens(tokens); + if (dmnsn_png_write_canvas(scene->canvas, output_file) != 0) { + fclose(output_file); + dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't write output."); + } fclose(output_file); - fclose(input_file); + + /* Clean up and exit! */ return EXIT_SUCCESS; } diff --git a/dimension/parse.c b/dimension/parse.c new file mode 100644 index 0000000..2c1b67c --- /dev/null +++ b/dimension/parse.c @@ -0,0 +1,39 @@ +/************************************************************************* + * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of Dimension. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 3 of the License, or (at * + * your option) any later version. * + * * + * Dimension is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#include "parse.h" +#include "tokenize.h" +#include "utility.h" + +dmnsn_array * +dmnsn_parse(dmnsn_array *tokens) +{ + return NULL; +} + +void +dmnsn_delete_astree(dmnsn_array *astree) +{ + dmnsn_delete_array(astree); +} + +void +dmnsn_print_astree_sexpr(FILE *file, const dmnsn_array *tokens) +{ +} diff --git a/dimension/parse.h b/dimension/parse.h new file mode 100644 index 0000000..d51144a --- /dev/null +++ b/dimension/parse.h @@ -0,0 +1,29 @@ +/************************************************************************* + * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of Dimension. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 3 of the License, or (at * + * your option) any later version. * + * * + * Dimension is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#include "../libdimension/dimension.h" + +/* The workhorse */ +dmnsn_array *dmnsn_parse(dmnsn_array *tokens); + +/* Free an abstract syntax tree */ +void dmnsn_delete_astree(dmnsn_array *astree); + +/* Print an S-expression of the abstract syntax tree to `file' */ +void dmnsn_print_astree_sexpr(FILE *file, const dmnsn_array *tokens); diff --git a/dimension/realize.c b/dimension/realize.c new file mode 100644 index 0000000..7f5e385 --- /dev/null +++ b/dimension/realize.c @@ -0,0 +1,28 @@ +/************************************************************************* + * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of Dimension. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 3 of the License, or (at * + * your option) any later version. * + * * + * Dimension is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#include "realize.h" +#include "parse.h" +#include "utility.h" + +dmnsn_scene * +dmnsn_realize(dmnsn_array *astree) +{ + return dmnsn_new_scene(); +} diff --git a/dimension/realize.h b/dimension/realize.h new file mode 100644 index 0000000..fa2b6eb --- /dev/null +++ b/dimension/realize.h @@ -0,0 +1,22 @@ +/************************************************************************* + * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of Dimension. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 3 of the License, or (at * + * your option) any later version. * + * * + * Dimension is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#include "../libdimension/dimension.h" + +dmnsn_scene *dmnsn_realize(dmnsn_array *astree); |