1 /**************************************************************************
2 * parser.y -- scenery file parser
4 * Written by Curtis Olson, started May 1997.
6 * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 **************************************************************************/
38 /*#DEFINE YYDEBUG 1 */
40 /* interfacing with scanner.l (lex) */
43 int push_input_stream ( char *input );
45 /* we must define this ourselves */
48 /* handle for a mesh structure */
49 struct mesh *mesh_ptr;
53 /* top level reserved words */
54 %token IncludeSym MeshSym RowSym ChunkSym BoundsSym PlaceSym
57 %token Identifier Number StringLiteral
60 %token HashSym EqualSym LBraceSym RBraceSym LParenSym RParenSym CommaSym
63 %token BadStringLiteral ErrorMisc
90 HashSym IncludeSym StringLiteral
92 yytext = strip_quotes(yytext);
93 printf("Need to include %s\n", yytext);
94 push_input_stream(yytext);
98 /* terrain mesh rules */
102 /* allocate a structure for this terrain mesh */
103 mesh_ptr = new_mesh();
105 Identifier LBraceSym mesh_body RBraceSym
107 /* The following two lines *SHOULD* be here, they are just temporarily
108 commented out until the scenery mngmt stuff gets hashed out. */
110 /* free up the mem used by this structure */
111 /* free(mesh_ptr->mesh_data); */
112 /* free(mesh_ptr); */
119 /* We've read the headers, so allocate a pseudo 2d array */
120 mesh_ptr->mesh_data = new_mesh_data(mesh_ptr->rows, mesh_ptr->cols);
121 printf("Beginning to read mesh data\n");
128 | mesh_header_list mesh_header
134 mesh_set_option_name(mesh_ptr, yytext);
138 mesh_set_option_value(mesh_ptr, yytext);
144 | mesh_row_list mesh_row
150 /* printf("Ready to read a row\n"); */
151 mesh_ptr->cur_col = 0;
153 EqualSym LParenSym mesh_row_items RParenSym
161 | mesh_row_items mesh_item
167 /* mesh data is a pseudo 2d array */
168 mesh_ptr->mesh_data[mesh_ptr->cur_row * mesh_ptr->rows +
169 mesh_ptr->cur_col] = atof(yytext);
175 chunk : ChunkSym Identifier LBraceSym chunk_body RBraceSym
178 chunk_body : chunk_header_list chunk_bounds place_list
181 chunk_header_list : chunk_header
182 | chunk_header_list chunk_header
185 chunk_header : Identifier EqualSym StringLiteral
188 chunk_bounds : BoundsSym EqualSym LBraceSym
201 place_list : place | place_list place
204 place : PlaceSym Identifier LBraceSym place_options_list RBraceSym
207 place_options_list : place_option | place_options_list place_option
210 place_option : Identifier EqualSym place_value
213 place_value : geodetic_coord | Number
216 geodetic_coord : LParenSym Number CommaSym Number CommaSym
221 /* C Function Section */
225 int yyerror(char *s) {
226 printf("Error: %s at line %d.\n", s, line_num);
231 /* this is a simple main for testing the parser */
234 int main(int argc, char **argv) {
239 printf("input file = %s\n", argv[1]);
240 push_input_stream(argv[1]);
248 /* parse a scenery file */
249 int parse_scenery(char *file) {
252 printf("input file = %s\n", file);
253 push_input_stream(file);