1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-29 18:32:36 +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 19:58:25 +02: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 19:58:25 +02:00
// Control structure parser
2010-06-30 19:58:25 +02:00
class ControlParser : public Parser
{
enum State
{
StartState,
2010-07-01 10:42:49 +02:00
IfEndState,
IfBodyState,
2010-06-30 19:58:25 +02:00
IfElseifEndState,
IfElseifBodyState,
IfElseEndState,
IfElseBodyState,
2010-07-01 10:42:49 +02:00
IfEndifState,
WhileEndState,
WhileBodyState,
WhileEndwhileState,
IfElseJunkState
2010-06-30 19:58:25 +02:00
};
2022-09-22 21:26:05 +03:00
2010-06-30 19:58:25 +02:00
typedef std::vector<Interpreter::Type_Code> Codes;
typedef std::vector<std::pair<Codes, Codes>> IfCodes;
2022-09-22 21:26:05 +03:00
Locals& mLocals;
Literals& mLiterals;
2010-06-30 19:58:25 +02:00
Codes mCode;
Codes mCodeBlock;
IfCodes mIfCode; // condition, body
LineParser mLineParser;
ExprParser mExprParser;
State mState;
2022-09-22 21:26:05 +03:00
2010-07-01 10:47:29 +02:00
bool parseIfBody(int keyword, const TokenLoc& loc, Scanner& scanner);
2022-09-22 21:26:05 +03:00
2010-07-01 10:47:29 +02:00
bool parseWhileBody(int keyword, const TokenLoc& loc, Scanner& scanner);
2022-09-22 21:26:05 +03:00
2010-06-30 19:58:25 +02:00
public:
2014-02-14 12:23:00 +01:00
ControlParser(ErrorHandler& errorHandler, const Context& context, Locals& locals, Literals& literals);
2022-09-22 21:26:05 +03:00
2010-06-30 19:58:25 +02:00
void appendCode(std::vector<Interpreter::Type_Code>& code) const;
2014-06-15 15:58:01 +02:00
///< store generated code in \a code.
2022-09-22 21:26:05 +03:00
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
2022-09-22 21:26:05 +03:00
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
2010-06-30 19:58:25 +02:00
///< Handle a keyword token.
/// \return fetch another token?
2022-09-22 21:26:05 +03:00
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
2010-06-30 19:58:25 +02:00
///< Handle a special character token.
/// \return fetch another token?
2022-09-22 21:26:05 +03:00
void reset() override;
2010-06-30 19:58:25 +02:00
///< Reset parser to clean state.
};
}
#endif