1 /**************************************************************************
2 * parser.y -- scenery file parser
4 * Written by Curtis Olson, started May 1997.
7 * (Log is kept at end of this file)
8 **************************************************************************/
23 /*#DEFINE YYDEBUG 1 */
25 /* interfacing with scanner.l (lex) */
28 int push_input_stream ( char *input );
30 /* we must define this ourselves */
33 /* handle for a mesh structure */
34 struct mesh *mesh_ptr;
38 /* top level reserved words */
39 %token IncludeSym MeshSym RowSym ChunkSym BoundsSym PlaceSym
42 %token Identifier Number StringLiteral
45 %token HashSym EqualSym LBraceSym RBraceSym LParenSym RParenSym CommaSym
48 %token BadStringLiteral ErrorMisc
75 HashSym IncludeSym StringLiteral
77 yytext = strip_quotes(yytext);
78 printf("Need to include %s\n", yytext);
79 push_input_stream(yytext);
83 /* terrain mesh rules */
87 /* allocate a structure for this terrain mesh */
88 mesh_ptr = new_mesh();
90 Identifier LBraceSym mesh_body RBraceSym
92 /* The following two lines *SHOULD* be here, they are just temporarily
93 commented out until the scenery mngmt stuff gets hashed out. */
95 /* free up the mem used by this structure */
96 /* free(mesh_ptr->mesh_data); */
104 /* We've read the headers, so allocate a pseudo 2d array */
105 mesh_ptr->mesh_data = new_mesh_data(mesh_ptr->rows, mesh_ptr->cols);
106 printf("Beginning to read mesh data\n");
113 | mesh_header_list mesh_header
119 mesh_set_option_name(mesh_ptr, yytext);
123 mesh_set_option_value(mesh_ptr, yytext);
129 | mesh_row_list mesh_row
135 /* printf("Ready to read a row\n"); */
136 mesh_ptr->cur_col = 0;
138 EqualSym LParenSym mesh_row_items RParenSym
146 | mesh_row_items mesh_item
152 /* mesh data is a pseudo 2d array */
153 mesh_ptr->mesh_data[mesh_ptr->cur_row * mesh_ptr->rows +
154 mesh_ptr->cur_col] = atof(yytext);
160 chunk : ChunkSym Identifier LBraceSym chunk_body RBraceSym
163 chunk_body : chunk_header_list chunk_bounds place_list
166 chunk_header_list : chunk_header
167 | chunk_header_list chunk_header
170 chunk_header : Identifier EqualSym StringLiteral
173 chunk_bounds : BoundsSym EqualSym LBraceSym
186 place_list : place | place_list place
189 place : PlaceSym Identifier LBraceSym place_options_list RBraceSym
192 place_options_list : place_option | place_options_list place_option
195 place_option : Identifier EqualSym place_value
198 place_value : geodetic_coord | Number
201 geodetic_coord : LParenSym Number CommaSym Number CommaSym
206 /* C Function Section */
210 int yyerror(char *s) {
211 printf("Error: %s at line %d.\n", s, line_num);
216 /* this is a simple main for testing the parser */
219 int main(int argc, char **argv) {
224 printf("input file = %s\n", argv[1]);
225 push_input_stream(argv[1]);
233 /* parse a scenery file */
234 int parse_scenery(char *file) {
237 printf("input file = %s\n", file);
238 push_input_stream(file);