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