OpenMW
components/compiler/controlparser.hpp
Go to the documentation of this file.
00001 #ifndef COMPILER_CONTROLPARSER_H_INCLUDED
00002 #define COMPILER_CONTROLPARSER_H_INCLUDED
00003 
00004 #include <vector>
00005 
00006 #include <components/interpreter/types.hpp>
00007 
00008 #include "parser.hpp"
00009 #include "exprparser.hpp"
00010 #include "lineparser.hpp"
00011 
00012 namespace Compiler
00013 {
00014     class Locals;
00015     class Literals;
00016 
00017     // Control structure parser
00018 
00019     class ControlParser : public Parser
00020     {
00021             enum State
00022             {
00023                 StartState,
00024                 IfEndState, IfBodyState,
00025                 IfElseifEndState, IfElseifBodyState,
00026                 IfElseEndState, IfElseBodyState,
00027                 IfEndifState,
00028                 WhileEndState, WhileBodyState,
00029                 WhileEndwhileState
00030             };
00031 
00032             typedef std::vector<Interpreter::Type_Code> Codes;
00033             typedef std::vector<std::pair<Codes, Codes> > IfCodes;
00034 
00035             Locals& mLocals;
00036             Literals& mLiterals;
00037             Codes mCode;
00038             Codes mCodeBlock;
00039             IfCodes mIfCode; // condition, body
00040             LineParser mLineParser;
00041             ExprParser mExprParser;
00042             State mState;
00043 
00044             bool parseIfBody (int keyword, const TokenLoc& loc, Scanner& scanner);
00045 
00046             bool parseWhileBody (int keyword, const TokenLoc& loc, Scanner& scanner);
00047 
00048         public:
00049 
00050             ControlParser (ErrorHandler& errorHandler, Context& context, Locals& locals,
00051                 Literals& literals);
00052 
00053             void appendCode (std::vector<Interpreter::Type_Code>& code) const;
00055 
00056             virtual bool parseName (const std::string& name, const TokenLoc& loc,
00057                 Scanner& scanner);
00060 
00061             virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner);
00064 
00065             virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner);
00068 
00069             void reset();
00071     };
00072 }
00073 
00074 #endif