1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 02:53:53 +00:00
openmw/components/compiler/controlparser.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
2.1 KiB
C++
Raw Normal View History

2010-06-30 17:58:25 +00:00
#ifndef COMPILER_CONTROLPARSER_H_INCLUDED
#define COMPILER_CONTROLPARSER_H_INCLUDED
#include <vector>
#include <components/interpreter/types.hpp>
#include "exprparser.hpp"
#include "lineparser.hpp"
#include "parser.hpp"
namespace Compiler
{
class Locals;
class Literals;
2010-06-30 17:58:25 +00:00
// Control structure parser
2010-06-30 17:58:25 +00:00
class ControlParser : public Parser
{
enum State
{
StartState,
2010-07-01 08:42:49 +00:00
IfEndState,
IfBodyState,
2010-06-30 17:58:25 +00:00
IfElseifEndState,
IfElseifBodyState,
IfElseEndState,
IfElseBodyState,
2010-07-01 08:42:49 +00:00
IfEndifState,
WhileEndState,
WhileBodyState,
WhileEndwhileState,
IfElseJunkState
2010-06-30 17:58:25 +00:00
};
2022-09-22 18:26:05 +00:00
2010-06-30 17:58:25 +00:00
typedef std::vector<Interpreter::Type_Code> Codes;
typedef std::vector<std::pair<Codes, Codes>> IfCodes;
2022-09-22 18:26:05 +00:00
Locals& mLocals;
Literals& mLiterals;
2010-06-30 17:58:25 +00:00
Codes mCode;
Codes mCodeBlock;
IfCodes mIfCode; // condition, body
LineParser mLineParser;
ExprParser mExprParser;
State mState;
2022-09-22 18:26:05 +00:00
2010-07-01 08:47:29 +00:00
bool parseIfBody(int keyword, const TokenLoc& loc, Scanner& scanner);
2022-09-22 18:26:05 +00:00
2010-07-01 08:47:29 +00:00
bool parseWhileBody(int keyword, const TokenLoc& loc, Scanner& scanner);
2022-09-22 18:26:05 +00:00
2010-06-30 17:58:25 +00:00
public:
2014-02-14 11:23:00 +00:00
ControlParser(ErrorHandler& errorHandler, const Context& context, Locals& locals, Literals& literals);
2022-09-22 18:26:05 +00:00
2010-06-30 17:58:25 +00:00
void appendCode(std::vector<Interpreter::Type_Code>& code) const;
2014-06-15 13:58:01 +00:00
///< store generated code in \a code.
2022-09-22 18:26:05 +00:00
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
2022-09-22 18:26:05 +00:00
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
2010-06-30 17:58:25 +00:00
///< Handle a keyword token.
/// \return fetch another token?
2022-09-22 18:26:05 +00:00
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
2010-06-30 17:58:25 +00:00
///< Handle a special character token.
/// \return fetch another token?
2022-09-22 18:26:05 +00:00
void reset() override;
2010-06-30 17:58:25 +00:00
///< Reset parser to clean state.
};
}
#endif