cyacc.h 9.28 KB
Newer Older
moh_lo's avatar
moh_lo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
#ifndef CYACC_H
#define CYACC_H

/************************************************************
cyacc.h
This file can be freely modified for the generation of
custom code.

Copyright (c) 1997-99 P. D. Stearns
************************************************************/

#define YY_AYACC

#include <stdio.h>
#include <stddef.h>
#include <assert.h>

// defines
#include <yytdefs.h>

// user defines
#if defined(YYTUDEFS) || defined(YYUDEFS)
#include <yytudefs.h>
#endif

// modifiers
#ifndef YYCDECL
#define YYCDECL
#endif
#ifndef YYDCDECL
#define YYDCDECL
#endif
#ifndef YYNEAR
#define YYNEAR
#endif
#ifndef YYFAR
#define YYFAR
#endif
#ifndef YYNEARFAR
#define YYNEARFAR
#endif
#ifndef YYBASED_CODE
#define YYBASED_CODE
#endif

// forward references
class YYFAR yylexer;

typedef short yystack_t;

// yyparse return values
#define YYEXIT_SUCCESS	0
#define YYEXIT_FAILURE	1

// common tokens
#define YYTK_ALL		(-1)		// match all tokens
#define YYTK_END		0			// $end token
#define YYTK_ERROR		256			// error token

#ifndef YYCNONTERMGOTO_T
#define YYCNONTERMGOTO_T
typedef short yycnontermgoto_t;
#endif

#ifndef YYCSTATEGOTO_T
#define YYCSTATEGOTO_T
typedef struct yycstategoto {
	short current;					// current state
	short next;						// next state
} yycstategoto_t;
#endif

#ifndef YYNONTERMGOTO_T
#define YYNONTERMGOTO_T
typedef struct yynontermgoto {
	short base;						// base
	short def;						// default state
} yynontermgoto_t;
#endif

#ifndef YYSTATEGOTO_T
#define YYSTATEGOTO_T
typedef struct yystategoto {
	short check;					// check
	short next;						// next state
} yystategoto_t;
#endif

// action types
#define YYAT_SHIFT		0		// shift action
#define YYAT_REDUCE		1		// reduce action
#define YYAT_ERROR		2		// error
#define YYAT_ACCEPT		3		// accept
#define YYAT_DEFAULT	4		// default state

#ifndef YYCSTATEACTION_T
#define YYCSTATEACTION_T
typedef short yycstateaction_t;
#endif

#ifndef YYCTOKENACTION_T
#define YYCTOKENACTION_T
typedef struct yyctokenaction {
	int token;					// lookahead token
	unsigned char type;			// action to perform
	short sr;					// state to shift/production to reduce
} yyctokenaction_t;
#endif

#ifndef YYSTATEACTION_T
#define YYSTATEACTION_T
typedef struct yystateaction {
	short base;					// base
	unsigned char lookahead;	// lookahead needed
	unsigned char type;			// action to perform
	short sr;					// shift/reduce
} yystateaction_t;
#endif

#ifndef YYTOKENACTION_T
#define YYTOKENACTION_T
typedef struct yytokenaction {
	short check;				// check
	unsigned char type;			// action type
	short sr;					// shift/reduce
} yytokenaction_t;
#endif

// states
#define YYST_ALL		(-1)	// match all states
#define YYST_ERROR		(-1)	// goto error

#ifndef YYREDUCTION_T
#define YYREDUCTION_T
typedef struct yyreduction {
	short rule;						// the rhs symbol
	short length;					// number of symbols on lhs
	short action;					// the user action
} yyreduction_t;
#endif

typedef short yydestructor_t;

typedef short yytokendest_t;

#ifndef YYCTOKENDEST_T
#define YYCTOKENDEST_T
typedef struct yyctokendest {
	int token;						/* token */
	short action;					/* the user action */
} yyctokendest_t;
#endif

// debugging
#ifdef YYDEBUG
#ifndef YYSYMBOL_T
#define YYSYMBOL_T
typedef struct yysymbol {
	const char* name;				// symbol name
	int token;						// symbol token
} yysymbol_t;
#endif
#endif

class YYFAR yyparser {
public:
	yyparser();
	virtual ~yyparser();

// Attributes
protected:
	// stack
	yystack_t YYFAR* yystackptr;		// (state) stack
	yystack_t YYFAR* yysstackptr;		// static (state) stack
	void YYFAR* yyattributestackptr;	// attribute stack
	void YYFAR* yysattributestackptr;	// static attribute stack
	int yystack_size;					// number of elements in stack
	int yysstack_size;					// initial number of elements in stack

	int yytop;							// the current top of the stack
	size_t yyattribute_size;			// size of attribute

	void YYFAR* yyvalptr;				// attribute for $$

	// lookahead token
	unsigned char yylookahead;			// whether current lookahead token is valid
	int yychar;							// current lookahead token

	// error recovery
	unsigned char yywipeflg;			// whether to "wipe" stack on abort
	unsigned char yypopflg;				// popping symbols during error recovery
	int yyskip;							// error recovery token shift counter

	// actions
	unsigned char yyexitflg;			// whether yymexit called
	unsigned char yyretireflg;			// whether yymretire called
	unsigned char yyerrorflg;			// whether yymforceerror called
	int yyexitcode;						// yymexit exit code
	int yyretirecode;					// yymretire exit code
	int yyerrorpop;						// how many error transitions to pop
public:
	yylexer YYFAR* yylexerptr;			// pointer to the attached lexical analyser

	unsigned char yystackgrow;			// whether stack can grow
	void YYFAR* yylvalptr;				// current token attribute
	FILE YYFAR* yyerr;					// error output file
	int yyerrorcount;					// how many syntax errors have occurred

// Operations
protected:
	virtual void yyaction(int action) = 0;

// utility functions
#ifdef YYDEBUG
	void yypop(int num);
	void yysetskip(int skip);
#else
	void yypop(int num) { yytop -= num; }
	void yysetskip(int skip) { yyskip = skip; }
#endif
	int yypush(yystack_t state);
	yystack_t yypeek() const { return yystackptr[yytop]; }

public:
	// instance functions
	int yycreate(yylexer YYFAR* lexerptr = NULL);
	void yydestroy();

	// general functions
	void yydestructpop(int num);
	int yyparse();
	void yycleanup();
	int yysetstacksize(int size);
	int yysetup();
	void yywipe();
	virtual int yywork() = 0;
	virtual void yydestructclearin() = 0;

	// service functions
	virtual void yystackoverflow();
	virtual void yyerror(const char YYFAR* text);
	virtual void yysyntaxerror();
	virtual void yydiscard(int token);
	virtual int yygettoken();

	// action functions
	void yysetin(int token);
	int yyunclearin();
	void yyabort() { yyexit(1); }
	void yyaccept() { yyexit(0); }
#ifndef YY_COMPATIBLE
	void yyclearin() { yylookahead = 0; }
	void yyerrok() { yysetskip(0); }
#else
	void _yyclearin() { yylookahead = 0; }
	void _yyerrok() { yysetskip(0); }
#endif
	void yyexit(int exitcode) { yyexitflg = 1; yyexitcode = exitcode; }
	void yyforceerror() { yythrowerror(0); }
	int yypopping() const { return yypopflg; }
	int yyrecovering() const { return yyskip > 0; }
	void yyretire(int retirecode) { yyretireflg = 1; yyretirecode = retirecode; }
	void yythrowerror(int pop) { yyerrorflg = 1; yyerrorpop = pop; }

	// compatibility
	int yycparse() { return yyparse(); }
	int yycwork() { return yywork(); }
	void yyparsecleanup() { yycleanup(); }
	void yyparseinit() { /* do nothing */ }
#ifdef YY_COMPATIBLE
#define yyclearin _yyclearin()
#define yyerrok _yyerrok()
#endif
#define YYABORT yyexit(1)
#define YYACCEPT yyexit(0)
#define YYERROR yyforceerror()
#define YYRECOVERING yyrecovering()

// Tables
protected:
	const yyreduction_t YYNEARFAR* yyreduction;
	const yydestructor_t YYNEARFAR* yydestructorptr;

// Debugging
#ifdef YYDEBUG
public:
	int yydebug;				// whether debug information should be output
	int yydebugstack;			// whether stack debug information should be output
	int yydebugflush;			// whether debug output should be flushed
	FILE YYFAR* yydebugout;		// debug output file
protected:
	const yysymbol_t YYNEARFAR* yysymbol;
	const char* const YYNEARFAR* yyrule;

	// debugging functions
protected:
	const char* yytokenstring(int token) const;
	void yydgettoken(int token) const;
	void yydshift(int token) const;
	void yydreduce(int rule) const;
	void yydsyntaxerror() const;
	void yydaccept() const;
	void yydabort() const;
	void yyddiscard(int token) const;
	void yydexit(int exitcode) const;
	void yydthrowerror(int errorpop) const;
	void yydretire(int retirecode) const;
	void yydattemptrecovery() const;
	void yydebugoutput(const char *string) const;
#endif
};

class YYFAR yyfparser : public yyparser {
public:
	yyfparser() { /* do nothing */ }

// Operations
public:
	virtual int yywork();
	virtual void yydestructclearin();

// Tables
protected:
	const yystateaction_t YYNEARFAR* yystateaction;
	const yytokenaction_t YYNEARFAR* yytokenaction;
	int yytokenaction_size;
	const yynontermgoto_t YYNEARFAR* yynontermgoto;
	const yystategoto_t YYNEARFAR* yystategoto;
	int yystategoto_size;
	const yytokendest_t YYNEARFAR* yytokendestptr;
	int yytokendest_size;
	int yytokendestbase;
};

class YYFAR yycparser : public yyparser {
public:
	yycparser() { /* do nothing */ }

// Operations
public:
	virtual int yywork();
	virtual void yydestructclearin();

// Tables
protected:
	const yycstateaction_t YYNEARFAR* yycstateaction;
	const yyctokenaction_t YYNEARFAR* yyctokenaction;
	const yycnontermgoto_t YYNEARFAR* yycnontermgoto;
	const yycstategoto_t YYNEARFAR* yycstategoto;
	const yyctokendest_t YYNEARFAR* yyctokendestptr;
};

// utility functions
#ifndef yyassert
#define yyassert(expr) assert(expr)
#endif

// debugging variables
#ifdef YYDEBUG
extern "C" int YYNEAR YYDCDECL yydebug;
extern "C" int YYNEAR YYDCDECL yydebugstack;
extern "C" int YYNEAR YYDCDECL yydebugflush;
#endif

// user defines
#if defined(YYBUDEFS) || defined(YYUDEFS)
#include <yybudefs.h>
#endif

// defines
#include <yybdefs.h>

#endif