/*
 * The contents of this file are subject to the Netscape Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/NPL/

 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.

 * The Original Code is Rhino code, released
 * May 6, 1999.

 * The Initial Developer of the Original Code is Netscape
 * Communications Corporation.  Portions created by Netscape are
 * Copyright (C) 1997-1999 Netscape Communications Corporation. All
 * Rights Reserved.

 * Contributor(s): 

 * Alternatively, the contents of this file may be used under the
 * terms of the GNU Public License (the "GPL"), in which case the
 * provisions of the GPL are applicable instead of those above.
 * If you wish to allow use of your version of this file only
 * under the terms of the GPL and not to allow others to use your
 * version of this file under the NPL, indicate your decision by
 * deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL.  If you do not delete
 * the provisions above, a recipient may use your version of this
 * file under either the NPL or the GPL.
 */

#ifndef _JS_PARSER_H_
#define _JS_PARSER_H_

#include "js-zonenew.h"
#include "js-context.h"
#include "js-tokenstream.h"
#include "js-source.h"
#include "js-irfactory.h"
#include "js-node.h"

/* Classes */
class JSParser: public JSZoneNew {
    protected:
	int		lastExprEndLine; // Hack to handle function expr
					//termination.
	JSIRFactory	*nf;
	JSErrorReporter	*er;
	jsBool_t	ok; // Did the parse encounter an error?

    protected:
	void	mustMatchToken(JSContext *cx, JSTokenStream *ts, int toMatch,
			jsString_t messageId);
	void	reportError(JSContext *cx, JSTokenStream *ts,
			jsString_t messageId);
	JSNode	*parseFunctionBody(JSContext *cx, JSTokenStream *ts,
			JSSource *source);
	JSNode	*function(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t isExpr);
	JSNode	*statements(JSContext *cx, JSTokenStream *ts,
			JSSource *source);
   	JSNode	*condition(JSContext *cx, JSTokenStream *ts, JSSource *source);
	jsBool_t 
		wellTerminated(JSContext *cx, JSTokenStream *ts,
			int lastExprType);
	jsString_t
		matchLabel(JSContext *cx, JSTokenStream *ts);
	JSNode	*statement(JSContext *cx, JSTokenStream *ts, JSSource *source);
	JSNode	*statementHelper(JSContext *cx, JSTokenStream *ts,
			JSSource *source);
	JSNode *variables(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t inForInit);
	JSNode	*expr(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t inForInit);
	JSNode	*assignExpr(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t inForInit);
	JSNode	*condExpr(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t inForInit);
	JSNode	*orExpr(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t inForInit);
	JSNode	*andExpr(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t inForInit);
	JSNode	*bitOrExpr(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t inForInit);
	JSNode	*bitXorExpr(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t inForInit);
	JSNode	*bitAndExpr(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t inForInit);
	JSNode	*eqExpr(JSContext *cx, JSTokenStream *ts,
			JSSource *source, jsBool_t inForInit);
	JSNode	*relExpr(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t inForInit);
	JSNode	*shiftExpr(JSContext *cx, JSTokenStream *ts, JSSource *source);
	JSNode	*addExpr(JSContext *cx, JSTokenStream *ts, JSSource *source);
	JSNode	*mulExpr(JSContext *cx, JSTokenStream *ts, JSSource *source);
	JSNode	*unaryExpr(JSContext *cx, JSTokenStream *ts, JSSource *source);
	JSNode	*argumentList(JSContext *cx, JSTokenStream *ts,
			JSSource *source, JSNode *listNode);
	JSNode	*memberExpr(JSContext *cx, JSTokenStream *ts, JSSource *source,
			jsBool_t allowCallSyntax);
	JSNode	*primaryExpr(JSContext *cx, JSTokenStream *ts,
			JSSource *source);

    public:
	JSParser(JSIRFactory *nf);

	JSNode	*parse(JSContext *cx, JSTokenStream *ts);
} ;

#endif /* _JS_PARSER_H_ */

