OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
exprparser.hpp
Go to the documentation of this file.
1 #ifndef COMPILER_EXPRPARSER_H_INCLUDED
2 #define COMPILER_EXPRPARSER_H_INCLUDED
3 
4 #include <vector>
5 
7 
8 #include "parser.hpp"
9 #include "tokenloc.hpp"
10 
11 namespace Compiler
12 {
13  class Locals;
14  class Literals;
15 
16  class ExprParser : public Parser
17  {
20  std::vector<char> mOperands;
21  std::vector<char> mOperators;
24  std::vector<Interpreter::Type_Code> mCode;
25  bool mFirst;
26  bool mArgument;
27  std::string mExplicit;
28  bool mRefOp;
29  bool mMemberOp;
30 
31  int getPriority (char op) const;
32 
33  char getOperandType (int Index = 0) const;
34 
35  char getOperator() const;
36 
37  bool isOpen() const;
38 
39  void popOperator();
40 
41  void popOperand();
42 
43  void replaceBinaryOperands();
44 
45  void pop();
46 
47  void pushIntegerLiteral (int value);
48 
49  void pushFloatLiteral (float value);
50 
51  void pushBinaryOperator (char c);
52 
53  void close();
54 
55  int parseArguments (const std::string& arguments, Scanner& scanner);
56 
57  bool handleMemberAccess (const std::string& name);
58 
59  public:
60 
61  ExprParser (ErrorHandler& errorHandler, const Context& context, Locals& locals,
62  Literals& literals, bool argument = false);
66 
67  char getType() const;
69 
70  virtual bool parseInt (int value, const TokenLoc& loc, Scanner& scanner);
73 
74  virtual bool parseFloat (float value, const TokenLoc& loc, Scanner& scanner);
77 
78  virtual bool parseName (const std::string& name, const TokenLoc& loc,
79  Scanner& scanner);
82 
83  virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner);
86 
87  virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner);
90 
91  void reset();
93 
94  char append (std::vector<Interpreter::Type_Code>& code);
97 
98  int parseArguments (const std::string& arguments, Scanner& scanner,
99  std::vector<Interpreter::Type_Code>& code, int ignoreKeyword = -1);
106 
107  const TokenLoc& getTokenLoc() const;
108  };
109 }
110 
111 #endif
int getPriority(char op) const
Definition: exprparser.cpp:23
virtual bool parseInt(int value, const TokenLoc &loc, Scanner &scanner)
Definition: exprparser.cpp:229
std::string mExplicit
Definition: exprparser.hpp:27
void popOperator()
Definition: exprparser.cpp:77
char getOperator() const
Definition: exprparser.cpp:66
std::vector< char > mOperators
Definition: exprparser.hpp:21
void popOperand()
Definition: exprparser.cpp:83
ExprParser(ErrorHandler &errorHandler, const Context &context, Locals &locals, Literals &literals, bool argument=false)
Definition: exprparser.cpp:223
void pushIntegerLiteral(int value)
Definition: exprparser.cpp:165
char getOperandType(int Index=0) const
Definition: exprparser.cpp:58
Definition: context.hpp:10
Location of a token in a source file.
Definition: tokenloc.hpp:10
Definition: exprparser.hpp:16
bool mNextOperand
Definition: exprparser.hpp:22
bool mMemberOp
Definition: exprparser.hpp:29
virtual bool parseKeyword(int keyword, const TokenLoc &loc, Scanner &scanner)
Definition: exprparser.cpp:346
std::vector< Interpreter::Type_Code > mCode
Definition: exprparser.hpp:24
Error handling.
Definition: errorhandler.hpp:14
std::vector< char > mOperands
Definition: exprparser.hpp:20
virtual bool parseSpecial(int code, const TokenLoc &loc, Scanner &scanner)
Definition: exprparser.cpp:594
virtual bool parseName(const std::string &name, const TokenLoc &loc, Scanner &scanner)
Definition: exprparser.cpp:275
void replaceBinaryOperands()
Definition: exprparser.cpp:89
bool isOpen() const
Definition: exprparser.cpp:72
void reset()
Reset parser to clean state.
Definition: exprparser.cpp:729
int parseArguments(const std::string &arguments, Scanner &scanner)
Definition: exprparser.cpp:196
void pushFloatLiteral(float value)
Definition: exprparser.cpp:172
Locals & mLocals
Definition: exprparser.hpp:18
void pop()
Definition: exprparser.cpp:105
char append(std::vector< Interpreter::Type_Code > &code)
Definition: exprparser.cpp:742
const TokenLoc & getTokenLoc() const
Definition: exprparser.cpp:883
bool mFirst
Definition: exprparser.hpp:25
virtual bool parseFloat(float value, const TokenLoc &loc, Scanner &scanner)
Definition: exprparser.cpp:252
Literals & mLiterals
Definition: exprparser.hpp:19
void close()
Definition: exprparser.cpp:188
void pushBinaryOperator(char c)
Definition: exprparser.cpp:179
bool mRefOp
Definition: exprparser.hpp:28
int code
Definition: crashcatcher.cpp:70
Literal values.
Definition: literals.hpp:13
bool handleMemberAccess(const std::string &name)
Definition: exprparser.cpp:201
Parser base class.
Definition: parser.hpp:17
bool mArgument
Definition: exprparser.hpp:26
char getType() const
Return type of parsed expression ('l' integer, 'f' float)
Local variable declarations.
Definition: locals.hpp:12
TokenLoc mTokenLoc
Definition: exprparser.hpp:23
Scanner.
Definition: scanner.hpp:21
const char * name
Definition: crashcatcher.cpp:59