1 /**************************************************************************
2 * scenery.l -- Lexical Analyzer for scenery files
4 * Written by Curtis Olson, started May 1997.
6 * NOTE: Compiles with flex and gcc.
9 **************************************************************************/
20 /* custom print routine */
21 static int scanner_debug = 0;
23 /* Routines to manage a stack of nested input buffers (for
24 processing the #include directive */
25 #define MAX_INCLUDE_DEPTH 10
26 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
27 static int include_stack_ptr = 0;
29 int push_input_stream ( char *input ) {
31 if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
32 fprintf( stderr, "Scanner says: Includes nested too deeply\n" );
36 /* save yyin in case the following fails */
39 yyin = fopen( input, "r" );
41 fprintf( stderr, "Scanner says: cannot open '%s'\n", input );
43 /* The failed attempt destroyed yyin, so restore it */
49 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
50 yy_switch_to_buffer( yy_create_buffer(yyin, YY_BUF_SIZE) );
55 int pop_input_stream () {
56 if ( --include_stack_ptr < 1 ) {
57 /* end of last input stream */
60 /* end of current input stream, restore previous and continue */
61 yy_delete_buffer( YY_CURRENT_BUFFER );
62 yy_switch_to_buffer( include_stack[include_stack_ptr] );
73 ident {letter}({letter}|{digit}|{connecter})*
77 plain_real {integer}"."{integer}
78 short_exp_real {integer}[Ee][+-]?{integer}
79 exp_real {plain_real}[Ee][+-]?{integer}
80 real [+-]?{plain_real}|{short_exp_real}|{exp_real}
82 number {real}|{integer}
86 bad_string \"([^"\n]|\n)+\"
95 include { if ( scanner_debug ) {
96 printf("return IncludeSym\n");
101 mesh { if ( scanner_debug ) {
102 printf("return MeshSym\n");
107 row { if ( scanner_debug ) {
108 printf("return RowSym\n");
113 chunk { if ( scanner_debug ) {
114 printf("return ChunkSym\n");
119 bounds { if ( scanner_debug ) {
120 printf("return BoundsSym\n");
125 place { if ( scanner_debug ) {
126 printf("return PlaceSym\n");
131 {ident} { if ( scanner_debug ) {
132 printf("return Identifier = %s\n", yytext);
137 {number} { if ( scanner_debug ) {
138 printf("return Number\n");
143 {string} { if ( scanner_debug ) {
144 printf("return StringLiteral = %s\n", yytext);
146 return StringLiteral;
149 {bad_string} { if ( scanner_debug ) {
150 printf("return BadStringLiteral = %s\n", yytext);
152 return BadStringLiteral;
156 if ( scanner_debug ) {
157 printf("Line number = %d\n", line_num);
161 "#" { if ( scanner_debug ) {
162 printf("return HashSym\n");
167 "=" { if ( scanner_debug ) {
168 printf("return EqualSym\n");
173 "," { if ( scanner_debug ) {
174 printf("return CommaSym\n");
179 "{" { if ( scanner_debug ) {
180 printf("return LBraceSym\n");
185 "}" { if ( scanner_debug ) {
186 printf("return RBraceSym\n");
191 "(" { if ( scanner_debug ) {
192 printf("return LParenSym\n");
197 ")" { if ( scanner_debug ) {
198 printf("return RParenSym\n");
203 "//" { /* burn through "#" comment */
205 while ( (c != '\n') ) {
207 /* scanner_print("%c", c); */
215 {other} { if ( scanner_debug ) {
216 printf("Scanned some unexpected text = `%s'\n", yytext);
221 <<EOF>> { if ( pop_input_stream() == 0 ) {
222 /* End of last input stream */