OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
controlparser.hpp
Go to the documentation of this file.
1 #ifndef COMPILER_CONTROLPARSER_H_INCLUDED
2 #define COMPILER_CONTROLPARSER_H_INCLUDED
3 
4 #include <vector>
5 
7 
8 #include "parser.hpp"
9 #include "exprparser.hpp"
10 #include "lineparser.hpp"
11 
12 namespace Compiler
13 {
14  class Locals;
15  class Literals;
16 
17  // Control structure parser
18 
19  class ControlParser : public Parser
20  {
21  enum State
22  {
31  };
32 
33  typedef std::vector<Interpreter::Type_Code> Codes;
34  typedef std::vector<std::pair<Codes, Codes> > IfCodes;
35 
40  IfCodes mIfCode; // condition, body
44 
45  bool parseIfBody (int keyword, const TokenLoc& loc, Scanner& scanner);
46 
47  bool parseWhileBody (int keyword, const TokenLoc& loc, Scanner& scanner);
48 
49  public:
50 
51  ControlParser (ErrorHandler& errorHandler, const Context& context, Locals& locals,
52  Literals& literals);
53 
54  void appendCode (std::vector<Interpreter::Type_Code>& code) const;
56 
57  virtual bool parseName (const std::string& name, const TokenLoc& loc,
58  Scanner& scanner);
61 
62  virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner);
65 
66  virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner);
69 
70  void reset();
72  };
73 }
74 
75 #endif
std::vector< std::pair< Codes, Codes > > IfCodes
Definition: controlparser.hpp:34
State mState
Definition: controlparser.hpp:43
Definition: controlparser.hpp:30
Definition: controlparser.hpp:23
void reset()
Reset parser to clean state.
Definition: controlparser.cpp:264
Definition: controlparser.hpp:25
Definition: context.hpp:10
Location of a token in a source file.
Definition: tokenloc.hpp:10
Definition: exprparser.hpp:16
Definition: controlparser.hpp:26
Codes mCodeBlock
Definition: controlparser.hpp:39
Definition: controlparser.hpp:29
Definition: controlparser.hpp:24
std::vector< Interpreter::Type_Code > Codes
Definition: controlparser.hpp:33
Definition: controlparser.hpp:25
Error handling.
Definition: errorhandler.hpp:14
IfCodes mIfCode
Definition: controlparser.hpp:40
ExprParser mExprParser
Definition: controlparser.hpp:42
Definition: controlparser.hpp:28
Codes mCode
Definition: controlparser.hpp:38
ControlParser(ErrorHandler &errorHandler, const Context &context, Locals &locals, Literals &literals)
Definition: controlparser.cpp:157
Definition: controlparser.hpp:27
bool parseIfBody(int keyword, const TokenLoc &loc, Scanner &scanner)
Definition: controlparser.cpp:14
Definition: controlparser.hpp:28
Definition: controlparser.hpp:19
virtual bool parseSpecial(int code, const TokenLoc &loc, Scanner &scanner)
Definition: controlparser.cpp:225
virtual bool parseKeyword(int keyword, const TokenLoc &loc, Scanner &scanner)
Definition: controlparser.cpp:186
bool parseWhileBody(int keyword, const TokenLoc &loc, Scanner &scanner)
Definition: controlparser.cpp:101
int code
Definition: crashcatcher.cpp:70
Locals & mLocals
Definition: controlparser.hpp:36
Literal values.
Definition: literals.hpp:13
virtual bool parseName(const std::string &name, const TokenLoc &loc, Scanner &scanner)
Definition: controlparser.cpp:172
LineParser mLineParser
Definition: controlparser.hpp:41
Parser base class.
Definition: parser.hpp:17
Definition: controlparser.hpp:26
Definition: controlparser.hpp:24
Literals & mLiterals
Definition: controlparser.hpp:37
void appendCode(std::vector< Interpreter::Type_Code > &code) const
store generated code in code.
Definition: controlparser.cpp:167
State
Definition: controlparser.hpp:21
Local variable declarations.
Definition: locals.hpp:12
Scanner.
Definition: scanner.hpp:21
const char * name
Definition: crashcatcher.cpp:59
Line parser, to be used in console scripts and as part of ScriptParser.
Definition: lineparser.hpp:20