]> git.mxchange.org Git - flightgear.git/blob - Scenery/parser.y
More twiddling with the Scenery Management system.
[flightgear.git] / Scenery / parser.y
1 /**************************************************************************
2  * parser.y -- scenery file parser
3  *
4  * Written by Curtis Olson, started June 1997.
5  *
6  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7  *
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.
12  *
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.
17  *
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.
21  *
22  * $Id$
23  **************************************************************************/
24
25
26 /* C pass through */
27 %{
28 #include <malloc.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "parsevrml.h"
34 #include "geometry.h"
35 #include "common.h"
36 #include "mesh.h"
37 #include "scenery.h"
38
39
40     /*#DEFINE YYDEBUG 1 */
41
42     /* interfacing with scanner.l (lex) */
43     extern int line_num;
44     extern char *yytext;
45     int push_input_stream ( char *input );
46
47     /* we must define this ourselves */
48     int yyerror(char *s);
49
50     /* handle for a mesh structure */
51     struct mesh *mesh_ptr;
52 %}
53
54
55 /* top level reserved words */
56 %token IncludeSym ShapeSym GeometrySym ElevationGridSym
57
58 /* basic tokens */
59 %token Identifier Number StringLiteral 
60
61 /* symbol tokens */
62 %token EqualSym LBraceSym RBraceSym LParenSym RParenSym 
63 %token LSqBracketSym RSqBracketSym CommaSym
64
65 /* error tokens */
66 %token BadStringLiteral ErrorMisc
67
68
69 /* Start Symbol */
70 %start vrml
71
72
73 /* Rules Section */
74 %%
75
76 vrml : 
77     node_list
78 ;
79
80 node_list : 
81     node 
82     | node_list node
83 ;
84
85 node : 
86     include 
87     | shape 
88 ;
89
90 /* includes */
91 include : 
92     IncludeSym StringLiteral 
93     { 
94         yytext = strip_quotes(yytext);
95         printf("Need to include %s\n", yytext);
96         push_input_stream(yytext);
97     }
98 ;
99
100 /* Shape rules */
101
102 shape :
103     ShapeSym LBraceSym shape_body RBraceSym
104 ;
105
106 shape_body :
107     /* appearance */ geometry
108 ;
109
110 /* appearance : */
111 /* Empty OK */
112 /* ; */
113
114 geometry :
115     GeometrySym 
116     Identifier 
117     {
118         vrmlInitGeometry(yytext);
119     }
120     LBraceSym geom_item_list RBraceSym
121     {
122         vrmlHandleGeometry();
123         vrmlFreeGeometry();
124     }
125 ;
126
127 geom_item_list :
128     geom_item
129     | geom_item_list geom_item
130 ;
131
132 geom_item :
133     Identifier { vrmlGeomOptionName(yytext); }
134     geom_rvalue
135 ;
136
137 geom_rvalue :
138     value
139     | LSqBracketSym value_list RSqBracketSym
140 ;
141
142 value_list :
143     value
144     | value_list value
145 ;
146
147 value :
148     Number { vrmlGeomOptionsValue(yytext); }
149 ;
150
151
152 /* C Function Section */
153 %%
154
155
156 int yyerror(char *s) {
157     printf("Error: %s at line %d.\n", s, line_num);
158     return 0;
159 }
160
161
162 /* this is a simple main for testing the parser */
163
164 /*
165 int main(int argc, char **argv) {
166 #ifdef YYDEBUG
167     yydebug = 1;
168 #endif
169
170     printf("input file = %s\n", argv[1]);
171     push_input_stream(argv[1]);
172     yyparse();
173
174     return 0;
175 }
176 */
177
178
179 /* parse a VRML scenery file */
180 int fgParseVRML(char *file) {
181     int result;
182
183     printf("input file = %s\n", file);
184     push_input_stream(file);
185     result = yyparse();
186
187     /* return(result) */
188     return(result);
189 }