/**************************************************************************
* parser.y -- scenery file parser
*
- * Written by Curtis Olson, started May 1997.
+ * Written by Curtis Olson, started June 1997.
+ *
+ * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
+ *
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
**************************************************************************/
/* C pass through */
%{
-#include <malloc.h>
+#ifndef __CYGWIN32__
+# include <malloc.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "parsevrml.h"
+#include "geometry.h"
#include "common.h"
#include "mesh.h"
#include "scenery.h"
/* top level reserved words */
-%token IncludeSym MeshSym RowSym ChunkSym BoundsSym PlaceSym
+%token IncludeSym ShapeSym GeometrySym
/* basic tokens */
%token Identifier Number StringLiteral
-/* symbol tokens */
-%token HashSym EqualSym LBraceSym RBraceSym LParenSym RParenSym CommaSym
+/* symbol tokens */
+%token EqualSym LBraceSym RBraceSym LParenSym RParenSym
+%token LSqBracketSym RSqBracketSym CommaSym
/* error tokens */
%token BadStringLiteral ErrorMisc
/* Start Symbol */
-%start start
+%start vrml
/* Rules Section */
%%
-start :
- object_list
+vrml :
+ node_list
;
-object_list :
- object
- | object_list object
+node_list :
+ node
+ | node_list node
;
-object :
+node :
include
- | mesh
- | chunk
+ | shape
;
/* includes */
include :
- HashSym IncludeSym StringLiteral
+ IncludeSym StringLiteral
{
yytext = strip_quotes(yytext);
printf("Need to include %s\n", yytext);
}
;
-/* terrain mesh rules */
-mesh :
- MeshSym
- {
- /* allocate a structure for this terrain mesh */
- mesh_ptr = new_mesh();
- }
- Identifier LBraceSym mesh_body RBraceSym
- {
- /* The following two lines *SHOULD* be here, they are just temporarily
- commented out until the scenery mngmt stuff gets hashed out. */
+/* Shape rules */
- /* free up the mem used by this structure */
- /* free(mesh_ptr->mesh_data); */
- /* free(mesh_ptr); */
- }
+shape :
+ ShapeSym LBraceSym shape_body RBraceSym
;
-mesh_body :
- mesh_header_list
- {
- /* We've read the headers, so allocate a pseudo 2d array */
- mesh_ptr->mesh_data = new_mesh_data(mesh_ptr->rows, mesh_ptr->cols);
- printf("Beginning to read mesh data\n");
- }
- mesh_row_list
+shape_body :
+ /* appearance */ geometry
;
-mesh_header_list :
- mesh_header
- | mesh_header_list mesh_header
-;
+/* appearance : */
+/* Empty OK */
+/* ; */
-mesh_header :
+geometry :
+ GeometrySym
Identifier
{
- mesh_set_option_name(mesh_ptr, yytext);
+ vrmlInitGeometry(yytext);
}
- EqualSym Number
+ LBraceSym geom_item_list RBraceSym
{
- mesh_set_option_value(mesh_ptr, yytext);
+ vrmlHandleGeometry();
+ vrmlFreeGeometry();
}
;
-mesh_row_list :
- mesh_row
- | mesh_row_list mesh_row
+geom_item_list :
+ geom_item
+ | geom_item_list geom_item
;
-mesh_row :
- RowSym
- {
- /* printf("Ready to read a row\n"); */
- mesh_ptr->cur_col = 0;
- }
- EqualSym LParenSym mesh_row_items RParenSym
- {
- mesh_ptr->cur_row++;
- }
+geom_item :
+ Identifier { vrmlGeomOptionName(yytext); }
+ geom_rvalue
;
-mesh_row_items :
- mesh_item
- | mesh_row_items mesh_item
+geom_rvalue :
+ value
+ | LSqBracketSym value_list RSqBracketSym
;
-mesh_item :
- Number
- {
- /* mesh data is a pseudo 2d array */
- mesh_ptr->mesh_data[mesh_ptr->cur_row * mesh_ptr->rows +
- mesh_ptr->cur_col] = atof(yytext);
- mesh_ptr->cur_col++;
- }
+value_list :
+ value
+ | value_list value
;
-/* chunk rules */
-chunk : ChunkSym Identifier LBraceSym chunk_body RBraceSym
- ;
-
-chunk_body : chunk_header_list chunk_bounds place_list
- ;
-
-chunk_header_list : chunk_header
- | chunk_header_list chunk_header
- ;
-
-chunk_header : Identifier EqualSym StringLiteral
- ;
-
-chunk_bounds : BoundsSym EqualSym LBraceSym
- Number CommaSym
- Number CommaSym
- Number CommaSym
- Number CommaSym
- Number CommaSym
- Number CommaSym
- Number CommaSym
- Number
- RBraceSym
- ;
-
-/* place rules */
-place_list : place | place_list place
- ;
-
-place : PlaceSym Identifier LBraceSym place_options_list RBraceSym
- ;
-
-place_options_list : place_option | place_options_list place_option
- ;
-
-place_option : Identifier EqualSym place_value
- ;
-
-place_value : geodetic_coord | Number
- ;
-
-geodetic_coord : LParenSym Number CommaSym Number CommaSym
- Number RParenSym
- ;
+value :
+ Number { vrmlGeomOptionsValue(yytext); }
+;
/* C Function Section */
yydebug = 1;
#endif
- printf("input file = %s\n", argv[1]);
+ printf(" input file = %s\n", argv[1]);
push_input_stream(argv[1]);
yyparse();
*/
-/* parse a scenery file */
-int parse_scenery(char *file) {
+/* parse a VRML scenery file */
+int fgParseVRML(char *file) {
int result;
- printf("input file = %s\n", file);
+ printf(" input file = %s\n", file);
push_input_stream(file);
result = yyparse();
/* return(result) */
- return(mesh_ptr);
+ return(result);
}