You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
15 years ago
|
#ifndef COMPILER_CONTROLPARSER_H_INCLUDED
|
||
|
#define COMPILER_CONTROLPARSER_H_INCLUDED
|
||
|
|
||
|
#include <vector>
|
||
|
|
||
|
#include <components/interpreter/types.hpp>
|
||
|
|
||
|
#include "parser.hpp"
|
||
|
#include "exprparser.hpp"
|
||
|
#include "lineparser.hpp"
|
||
|
|
||
|
namespace Compiler
|
||
|
{
|
||
|
class Locals;
|
||
|
class Literals;
|
||
|
|
||
|
// Control structure parser
|
||
|
|
||
|
class ControlParser : public Parser
|
||
|
{
|
||
|
enum State
|
||
|
{
|
||
|
StartState,
|
||
|
IfState, IfEndState, IfBodyState,
|
||
|
IfElseifEndState, IfElseifBodyState,
|
||
|
IfElseEndState, IfElseBodyState,
|
||
|
IfEndifState
|
||
|
};
|
||
|
|
||
|
typedef std::vector<Interpreter::Type_Code> Codes;
|
||
|
typedef std::vector<std::pair<Codes, Codes> > IfCodes;
|
||
|
|
||
|
Locals& mLocals;
|
||
|
Literals& mLiterals;
|
||
|
Codes mCode;
|
||
|
Codes mCodeBlock;
|
||
|
IfCodes mIfCode; // condition, body
|
||
|
LineParser mLineParser;
|
||
|
ExprParser mExprParser;
|
||
|
State mState;
|
||
|
|
||
|
public:
|
||
|
|
||
|
ControlParser (ErrorHandler& errorHandler, Context& context, Locals& locals,
|
||
|
Literals& literals);
|
||
|
|
||
|
void appendCode (std::vector<Interpreter::Type_Code>& code) const;
|
||
|
///< store generated code in \æ code.
|
||
|
|
||
|
virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner);
|
||
|
///< Handle a keyword token.
|
||
|
/// \return fetch another token?
|
||
|
|
||
|
virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner);
|
||
|
///< Handle a special character token.
|
||
|
/// \return fetch another token?
|
||
|
|
||
|
void reset();
|
||
|
///< Reset parser to clean state.
|
||
|
};
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
|