1 /**************************************************************************
2 * parser.y -- scenery file parser
4 * Written by Curtis Olson, started May 1997.
7 **************************************************************************/
22 /*#DEFINE YYDEBUG 1 */
24 /* interfacing with scanner.l (lex) */
27 int push_input_stream ( char *input );
29 /* we must define this ourselves */
32 /* handle for a mesh structure */
33 struct mesh *mesh_ptr;
37 /* top level reserved words */
38 %token IncludeSym MeshSym RowSym ChunkSym BoundsSym PlaceSym
41 %token Identifier Number StringLiteral
44 %token HashSym EqualSym LBraceSym RBraceSym LParenSym RParenSym CommaSym
47 %token BadStringLiteral ErrorMisc
74 HashSym IncludeSym StringLiteral
76 yytext = strip_quotes(yytext);
77 printf("Need to include %s\n", yytext);
78 push_input_stream(yytext);
82 /* terrain mesh rules */
86 /* allocate a structure for this terrain mesh */
87 mesh_ptr = new_mesh();
89 Identifier LBraceSym mesh_body RBraceSym
91 /* The following two lines *SHOULD* be here, they are just temporarily
92 commented out until the scenery mngmt stuff gets hashed out. */
94 /* free up the mem used by this structure */
95 /* free(mesh_ptr->mesh_data); */
103 /* We've read the headers, so allocate a pseudo 2d array */
104 mesh_ptr->mesh_data = new_mesh_data(mesh_ptr->rows, mesh_ptr->cols);
105 printf("Beginning to read mesh data\n");
112 | mesh_header_list mesh_header
118 mesh_set_option_name(mesh_ptr, yytext);
122 mesh_set_option_value(mesh_ptr, yytext);
128 | mesh_row_list mesh_row
134 /* printf("Ready to read a row\n"); */
135 mesh_ptr->cur_col = 0;
137 EqualSym LParenSym mesh_row_items RParenSym
145 | mesh_row_items mesh_item
151 /* mesh data is a pseudo 2d array */
152 mesh_ptr->mesh_data[mesh_ptr->cur_row * mesh_ptr->rows +
153 mesh_ptr->cur_col] = atof(yytext);
159 chunk : ChunkSym Identifier LBraceSym chunk_body RBraceSym
162 chunk_body : chunk_header_list chunk_bounds place_list
165 chunk_header_list : chunk_header
166 | chunk_header_list chunk_header
169 chunk_header : Identifier EqualSym StringLiteral
172 chunk_bounds : BoundsSym EqualSym LBraceSym
185 place_list : place | place_list place
188 place : PlaceSym Identifier LBraceSym place_options_list RBraceSym
191 place_options_list : place_option | place_options_list place_option
194 place_option : Identifier EqualSym place_value
197 place_value : geodetic_coord | Number
200 geodetic_coord : LParenSym Number CommaSym Number CommaSym
205 /* C Function Section */
209 int yyerror(char *s) {
210 printf("Error: %s at line %d.\n", s, line_num);
215 /* this is a simple main for testing the parser */
218 int main(int argc, char **argv) {
223 printf("input file = %s\n", argv[1]);
224 push_input_stream(argv[1]);
232 /* parse a scenery file */
233 int parse_scenery(char *file) {
236 printf("input file = %s\n", file);
237 push_input_stream(file);