File: controlparser.hpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (76 lines) | stat: -rw-r--r-- 2,100 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#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;

    // Control structure parser

    class ControlParser : public Parser
    {
        enum State
        {
            StartState,
            IfEndState,
            IfBodyState,
            IfElseifEndState,
            IfElseifBodyState,
            IfElseEndState,
            IfElseBodyState,
            IfEndifState,
            WhileEndState,
            WhileBodyState,
            WhileEndwhileState,
            IfElseJunkState
        };

        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;

        bool parseIfBody(int keyword, const TokenLoc& loc, Scanner& scanner);

        bool parseWhileBody(int keyword, const TokenLoc& loc, Scanner& scanner);

    public:
        ControlParser(ErrorHandler& errorHandler, const Context& context, Locals& locals, Literals& literals);

        void appendCode(std::vector<Interpreter::Type_Code>& code) const;
        ///< store generated code in \a code.

        bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
        ///< Handle a name token.
        /// \return fetch another token?

        bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
        ///< Handle a keyword token.
        /// \return fetch another token?

        bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
        ///< Handle a special character token.
        /// \return fetch another token?

        void reset() override;
        ///< Reset parser to clean state.
    };
}

#endif