/****************************************************************************
	Kalkulon - A programmable calculator for programmers

	This file is part of the Kalkulon core.
	
	If you find this source code useful, your are encouraged to use it in your own projects.
	Please give me credit!

	COPYRIGHT by Juergen Holetzeck 2003 - 2008
	e-mail:		contact@kalkulon.de
	homepage:	www.kalkulon.de
****************************************************************************/


// ArithParser.h: Schnittstelle für die Klasse CArithParser.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_ArithParser_H__F57A2224_BB78_11D6_BEF2_E23F3DCEFF7E__INCLUDED_)
#define AFX_ArithParser_H__F57A2224_BB78_11D6_BEF2_E23F3DCEFF7E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>
#include <queue>
#include <istream>


namespace Kalkulon{
/////////////////////////////////////////////////////////////////////
// ArithParser interface
class CArithParser  
{

public:
	CArithParser();
	virtual ~CArithParser();
	
	int parse(std::istream* in, RPNStack_t* prpn_stack_); 

private:
	// attributes 
	std::istream* instream;
	Token tok;	// current token
	RPNStack_t* prpn_stack;

	unsigned int uid;

	// methods

	// lexer
	Token	get_token();
	void next_token();
	
	// Parser

	void prim_expr ();
	void postfix_expr();
	void unary_expr();
	void pow_expr  ();
	void mult_expr ();
	void add_expr  ();
	void shift_expr();
	void rel_expr();
	void eq_expr();
	void and_expr();
	void xor_expr();
	void or_expr();
	void logical_and_expr();
	void logical_or_expr();
	void expression();

	int  expr_list ();
	int  arg_list (bool function=false);

	// help function
	bool iscast(Token &tok);
	bool isstatement(Token &tok);


};

}

#endif // !defined(AFX_ArithParser_H__F57A2224_BB78_11D6_BEF2_E23F3DCEFF7E__INCLUDED_)
