mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
a ?: b Evaluates to a if a is true (not: false, 0, undefined, etc) Otherwise evaluates to b Short-circuit evaluation
50 lines
807 B
C++
50 lines
807 B
C++
/** @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();
|
|
|
|
void consume_tokens( Expression& expr );
|
|
void optimize();
|
|
void replace_elvis();
|
|
int get_num_tokens( int idx ) const;
|
|
void dump_tokens() const;
|
|
|
|
typedef std::vector<Token*> Tokens;
|
|
Tokens tokens;
|
|
|
|
public:
|
|
std::stack<Token*> TX;
|
|
std::queue<Token*> CA;
|
|
|
|
private:
|
|
void optimize_binary_operations();
|
|
void optimize_unary_operations();
|
|
void optimize_assignments();
|
|
bool optimize_token( int i );
|
|
void remove_non_emitting_tokens();
|
|
};
|
|
|
|
} // namespace Bscript
|
|
} // namespace Pol
|
|
|
|
#endif // H_EXPRESSION_H
|