1 %{
2 /*	SCCS Id: @(#)dgn_lex.c	3.3	96/03/02	*/
3 /*	Copyright (c) 1989 by Jean-Christophe Collet */
4 /*	Copyright (c) 1990 by M. Stephenson	     */
5 /* NetHack may be freely redistributed.  See license for details. */
6 
7 #define DGN_COMP
8 
9 #include "config.h"
10 #include "dgn_comp.h"
11 #include "dgn_file.h"
12 
13 /*
14  * Most of these don't exist in flex, yywrap is macro and
15  * yyunput is properly declared in flex.skel.
16  */
17 #if !defined(FLEX_SCANNER) && !defined(FLEXHACK_SCANNER)
18 int FDECL(yyback, (int *,int));
19 int NDECL(yylook);
20 int NDECL(yyinput);
21 int NDECL(yywrap);
22 int NDECL(yylex);
23 	/* Traditional lexes let yyunput() and yyoutput() default to int;
24 	 * newer ones may declare them as void since they don't return
25 	 * values.  For even more fun, the lex supplied as part of the
26 	 * newer unbundled compiler for SunOS 4.x adds the void declarations
27 	 * (under __STDC__ or _cplusplus ifdefs -- otherwise they remain
28 	 * int) while the bundled lex and the one with the older unbundled
29 	 * compiler do not.  To detect this, we need help from outside --
30 	 * sys/unix/Makefile.utl.
31 	 *
32 	 * Digital UNIX is difficult and still has int in spite of all
33 	 * other signs.
34 	 */
35 # if defined(NeXT) || defined(SVR4) || defined(_AIX32)
36 #  define VOIDYYPUT
37 # endif
38 # if !defined(VOIDYYPUT) && defined(POSIX_TYPES)
39 #  if !defined(BOS) && !defined(HISX) && !defined(_M_UNIX) && !defined(VMS)
40 #   define VOIDYYPUT
41 #  endif
42 # endif
43 # if !defined(VOIDYYPUT) && defined(WEIRD_LEX)
44 #  if defined(SUNOS4) && defined(__STDC__) && (WEIRD_LEX > 1)
45 #   define VOIDYYPUT
46 #  endif
47 # endif
48 # if defined(VOIDYYPUT) && defined(__osf__)
49 #  undef VOIDYYPUT
50 # endif
51 # ifdef VOIDYYPUT
52 void FDECL(yyunput, (int));
53 void FDECL(yyoutput, (int));
54 # else
55 int FDECL(yyunput, (int));
56 int FDECL(yyoutput, (int));
57 # endif
58 #endif	/* !FLEX_SCANNER && !FLEXHACK_SCANNER */
59 
60 #ifdef FLEX_SCANNER
61 #define YY_MALLOC_DECL \
62 	       genericptr_t FDECL(malloc, (size_t)); \
63 	       genericptr_t FDECL(realloc, (genericptr_t,size_t));
64 #endif
65 
66 
67 void FDECL(init_yyin, (FILE *));
68 void FDECL(init_yyout, (FILE *));
69 
70 /* this doesn't always get put in dgn_comp.h
71  * (esp. when using older versions of bison)
72  */
73 
74 extern YYSTYPE yylval;
75 
76 int line_number = 1;
77 /*
78  *	This is a hack required by Michael Hamel to get things
79  *	working on the Mac.
80  */
81 #if defined(applec) && !defined(FLEX_SCANNER) && !defined(FLEXHACK_SCANNER)
82 #undef input
83 #undef unput
84 #define unput(c) { yytchar = (c); if (yytchar == 10) yylineno--; *yysptr++ = yytchar; }
85 # ifndef YYNEWLINE
86 # define YYNEWLINE 10
87 # endif
88 
89 char
input()90 input()		/* Under MPW \n is chr(13)! Compensate for this. */
91 {
92 	if (yysptr > yysbuf) return(*--yysptr);
93 	else {
94 		yytchar = getc(yyin);
95 		if (yytchar == '\n') {
96 		    yylineno++;
97 		    return(YYNEWLINE);
98 		}
99 		if (yytchar == EOF) return(0);
100 		else		    return(yytchar);
101 	}
102 }
103 #endif	/* applec && !FLEX_SCANNER && !FLEXHACK_SCANNER */
104 
105 %}
106 %%
107 DUNGEON		return(A_DUNGEON);
108 up		{ yylval.i=1; return(UP_OR_DOWN); }
109 down		{ yylval.i=0; return(UP_OR_DOWN); }
110 ENTRY		return(ENTRY);
111 stair		return(STAIR);
112 no_up		return(NO_UP);
113 no_down		return(NO_DOWN);
114 portal		return(PORTAL);
115 PROTOFILE	return(PROTOFILE);
116 DESCRIPTION	return(DESCRIPTION);
117 LEVELDESC	return(LEVELDESC);
118 ALIGNMENT       return(ALIGNMENT);
119 LEVALIGN        return(LEVALIGN);
120 town		{ yylval.i=TOWN ; return(DESCRIPTOR); }
121 hellish		{ yylval.i=HELLISH ; return(DESCRIPTOR); }
122 mazelike	{ yylval.i=MAZELIKE ; return(DESCRIPTOR); }
123 roguelike	{ yylval.i=ROGUELIKE ; return(DESCRIPTOR); }
124 unaligned       { yylval.i=D_ALIGN_NONE ; return(DESCRIPTOR); }
125 noalign         { yylval.i=D_ALIGN_NONE ; return(DESCRIPTOR); }
126 lawful          { yylval.i=D_ALIGN_LAWFUL ; return(DESCRIPTOR); }
127 neutral         { yylval.i=D_ALIGN_NEUTRAL ; return(DESCRIPTOR); }
128 chaotic         { yylval.i=D_ALIGN_CHAOTIC ; return(DESCRIPTOR); }
129 BRANCH		return(BRANCH);
130 CHAINBRANCH	return(CHBRANCH);
131 LEVEL		return(LEVEL);
132 RNDLEVEL	return(RNDLEVEL);
133 CHAINLEVEL	return(CHLEVEL);
134 RNDCHLEVEL	return(RNDCHLEVEL);
135 [-0-9]+		{ yylval.i=atoi(yytext); return(INTEGER); }
136 \"[^"]*\"	{ yytext[yyleng-1] = 0; /* Discard the trailing \" */
137 		  yylval.str = (char *) alloc(strlen(yytext+1)+1);
138 		  Strcpy(yylval.str, yytext+1); /* Discard the first \" */
139 		  return(STRING); }
140 ^#.*\n		{ line_number++; }
141 \n		{ line_number++; }
142 [ \t]+		;	/* skip trailing tabs & spaces */
143 .		{ return yytext[0]; }
144 %%
145 
146 /* routine to switch to another input file; needed for flex */
147 void init_yyin( input_f )
148 FILE *input_f;
149 {
150 #if defined(FLEX_SCANNER) || defined(FLEXHACK_SCANNER)
151 	if (yyin)
152 	    yyrestart(input_f);
153 	else
154 #endif
155 	    yyin = input_f;
156 }
157 /* analogous routine (for completeness) */
158 void init_yyout( output_f )
159 FILE *output_f;
160 {
161 	yyout = output_f;
162 }
163 
164 /*dgn_comp.l*/
165