/* Automatically generated by Kelbt from "klparse.kh".
 *
 * Parts of this file are copied from Kelbt source covered by the GNU
 * GPL. As a special exception, you may use the parts of this file copied
 * from Kelbt source without restriction. The remainder is derived from
 * "klparse.kh" and inherits the copyright status of that file.
 */

#line 1 "klparse.kh"
/*
 *  Copyright 2006 Adrian Thurston <thurston@complang.org>
 */

/*  This file is part of Kelbt.
 *
 *  Kelbt is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 * 
 *  Kelbt is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with Kelbt; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */

#ifndef KLPARSE_H
#define KLPARSE_H

#include <iostream>
#include "avltree.h"
#include "parsedata.h"

struct LangEl;
struct Token
{
	char *data;
	InputLoc loc;
};

struct Parser
{
	#line 48 "klparse.h"
	struct Parser_Block *block;
	struct Parser_LangEl *freshEl;
	int freshPos;
	struct Parser_LangEl *pool;
	int numRetry;
	int numNodes;
	struct Parser_LangEl *stackTop;
	struct Parser_LangEl *lastFinal;
	int errCount;
	int curs;
#line 49 "klparse.kh"


	Parser( const char *fileName, char *parserName, std::ostream &out ) : 
		pd( fileName, parserName, out ), 
		sawStart(false), sawInterface(false) {}

	void init();
	int parseLangEl( int type, const Token *token );
	int token( int line, int tokid, char *data );

	TypeDef *getTypeDef( char *data );

	ParseData pd;
	bool sawStart;
	bool sawInterface;
	KlangElVect langElVect;
	FactorVect factorVect;
};

#line 79 "klparse.h"
#define KW_Parser 128
#define KW_Include 129
#define KW_Write 130
#define KW_Class 131
#define KW_Commit 132
#define KW_Try 133
#define KW_Undo 134
#define KW_Final 135
#define KW_Translate 136
#define KW_Token 137
#define KW_NonTerm 138
#define KW_Uses 139
#define KW_Type 140
#define KW_Pri 141
#define KW_Shortest 142
#define TK_Word 143
#define TK_String 144
#define TK_Number 145
#define TK_Inline 146
#define TK_Reference 147
#define TK_Literal 148
#define KW_Access 149
#define TK_AccessData 150
#define Parser_tk_eof 151

#line 69 "klparse.kh"

struct ParserDictEl
	: public AvlTreeEl<ParserDictEl>
{
	char *name;
	Parser *parser;

	char *getKey() const { return name; };
};

typedef AvlTree<ParserDictEl, char*, CmpStr> ParserDict;

#endif
