/* %Z%%M% %I% %E% */

/*
 * Copyright (c) 1990, 1991, 1992, 1995 by Wayne C. Gramlich.
 * All rights reserved.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * for any purpose is hereby granted without fee provided that the above
 * copyright notice and this permission are retained.  The author makes
 * no representations about the suitability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 */

/* This file declares the parser data structures: */

#ifndef PARSER_DEFS_H
#define PARSER_DEFS_H

#ifndef EXP_DEFS_H
#include "exp_defs.h"
#endif

#ifndef FILE_TYPES_H
#include "file_types.h"
#endif

#ifndef MSG_TYPES_H
#include "msg_types.h"
#endif

#ifndef OBJECT_TYPES_H
#include "object_types.h"
#endif

#ifndef PARSER_EXPORTS_H
#include "parser_exports.h"
#endif

#ifndef ROUTINE_TYPES_H
#include "routine_types.h"
#endif

#ifndef TABLE_TYPES_H
#include "table_types.h"
#endif

#ifndef TYPE_TYPES_H
#include "type_types.h"
#endif

#define PARSER_NONE ((Parser)0)
#define PARSER_LOOP(parser) \
	for (parser_loop_init(parser); parser_loop_next(parser); )

#define	PARSER_NOOP		0377	/* This token is not an operator */
#define PARSER_RIGHT_ASSOC	0100	/* Operator is right associative */
#define PARSER_BINARY		040	/* Operator is binary */
#define PARSER_PREC_MASK	037	/* Precedence mask */


#define PARSER_PREC_END		(1)
#define PARSER_PREC_COMMA	(2 | PARSER_BINARY)
#define PARSER_PREC_ASSIGN	(3 | PARSER_BINARY | PARSER_RIGHT_ASSOC)
#define PARSER_PREC_OR_IF	(4 | PARSER_BINARY)
#define PARSER_PREC_AND_IF	(5 | PARSER_BINARY)
#define PARSER_PREC_EQUAL	(6 | PARSER_BINARY)
#define PARSER_PREC_COMPARE	PARSER_PREC_EQUAL
#define PARSER_PREC_IDENTICAL	PARSER_PREC_EQUAL
#define PARSER_PREC_IF		(7 | PARSER_BINARY)
#define PARSER_PREC_COLON	(8 | PARSER_BINARY)
#define PARSER_PREC_ADD		(9 | PARSER_BINARY)
#define PARSER_PREC_MULTIPLY	(10 | PARSER_BINARY)
#define PARSER_PREC_POWER	(11 | PARSER_BINARY | PARSER_RIGHT_ASSOC)
#define	PARSER_PREC_XOR		(12 | PARSER_BINARY)
#define PARSER_PREC_OR		(13 | PARSER_BINARY)
#define PARSER_PREC_AND		(14 | PARSER_BINARY)
#define PARSER_PREC_SHIFT	(15 | PARSER_BINARY)
#define PARSER_PREC_CALL	(16 | PARSER_BINARY)
#define	PARSER_PREC_DOT		(17 | PARSER_BINARY)
#define PARSER_PREC_UNARY	(18)
#define PARSER_PREC_AT		(19 | PARSER_BINARY)
#define PARSER_PREC_DEFINE	PARSER_PREC_AT
#define PARSER_PREC_LEAF	(20)

struct Parser_struct {
	Vec(char)		buffer;		/* String buffer */
	int			column;		/* Previous column */
	File			file;
	Flags			flags;
	Stdio			gen_file;	/* Generate file */
	Heap			heap;
	Table(Str, Keyword)	keywords;	/* Keyword table */
	int			level;
	Vec(int)		levels;		/* List of previous levels */
	int			loop_number;	/* Loop number counter */
	Msg			msg;
	Object_table		object_table;
	Str			operators;
	Stdio			out_file;	/* For generated routines */
	Table(Str, Type_ref)	parameter_table;
	Token			peek_token;
	Token			previous;	/* Prev token or 0 */
	Routine_table		routine_table;
	Type_def_table		type_def_table;
	Type_tables		type_tables;	/* Type tables */
};

#endif  /* PARSER_DEFS_H */
