2020-04-24 12:45:14 -07:00
|
|
|
/** @file
|
|
|
|
|
*
|
|
|
|
|
* @par History
|
|
|
|
|
* - 2020/04/24 Syzygy: Moved here from parser.h
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef H_EXPRESSION_H
|
|
|
|
|
#define H_EXPRESSION_H
|
|
|
|
|
|
|
|
|
|
#include <queue>
|
|
|
|
|
#include <stack>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace Pol
|
|
|
|
|
{
|
|
|
|
|
namespace Bscript
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class Token;
|
|
|
|
|
|
|
|
|
|
class Expression
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
~Expression();
|
|
|
|
|
|
2020-04-28 14:02:16 -07:00
|
|
|
void consume_tokens( Expression& expr );
|
2020-04-24 12:45:14 -07:00
|
|
|
void optimize();
|
2020-04-23 19:12:04 -07:00
|
|
|
void replace_elvis();
|
2020-04-24 12:45:14 -07:00
|
|
|
int get_num_tokens( int idx ) const;
|
2020-04-23 19:12:04 -07:00
|
|
|
void dump_tokens() const;
|
2020-04-24 12:45:14 -07:00
|
|
|
|
|
|
|
|
typedef std::vector<Token*> Tokens;
|
|
|
|
|
Tokens tokens;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
std::stack<Token*> TX;
|
|
|
|
|
std::queue<Token*> CA;
|
2020-04-29 02:38:52 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void optimize_binary_operations();
|
|
|
|
|
void optimize_unary_operations();
|
|
|
|
|
void optimize_assignments();
|
|
|
|
|
bool optimize_token( int i );
|
|
|
|
|
void remove_non_emitting_tokens();
|
2020-04-24 12:45:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Bscript
|
|
|
|
|
} // namespace Pol
|
|
|
|
|
|
|
|
|
|
#endif // H_EXPRESSION_H
|