pdautomata_p.h 3.07 KB
Newer Older
victor's avatar
 
victor committed
1 2 3 4 5
#ifndef PDAUTOMATA_P_H
#define PDAUTOMATA_P_H

#include <QtCore>
#include "statement.h"
victor's avatar
 
victor committed
6
#include "dataformats/ast.h"
victor's avatar
 
victor committed
7 8 9 10 11 12 13 14

using namespace Shared;

namespace KumirAnalizer {

struct Script {
    QMetaMethod method;
    QList<QVariant> arguments;
victor's avatar
 
victor committed
15
    QString source;
victor's avatar
 
victor committed
16 17
};

victor's avatar
 
victor committed
18 19
typedef QList<Script> * ScriptListPtr;

victor's avatar
 
victor committed
20 21
struct RuleRightPart {
    QStringList nonTerminals;
victor's avatar
 
victor committed
22
    ScriptListPtr script;
victor's avatar
 
victor committed
23 24 25 26 27 28 29 30 31 32 33 34
    bool isEpsilon;
    int priority;
    inline bool operator< (const RuleRightPart &other) const {
            return priority < other.priority;
    }
    int ruleLine;
};

typedef QList<RuleRightPart> Rules;

typedef QMap<QString,Rules> Matrix;

victor's avatar
 
victor committed
35 36 37 38 39 40
struct PDStackElem {
        QString nonTerminal;
        int iterateStart;
        int priority;
};

victor's avatar
 
victor committed
41 42 43 44 45 46 47 48
class PDAutomataPrivate:
        public QObject
{
    Q_OBJECT;
public:

    void loadRules(const QString &rulesRoot);
    class PDAutomata * q;
49
    ~PDAutomataPrivate();
victor's avatar
 
victor committed
50
    AST::Data * ast;
victor's avatar
 
victor committed
51
    AST::Algorhitm * algorhitm;
victor's avatar
 
victor committed
52
    bool teacherMode;
victor's avatar
 
victor committed
53 54

    Matrix matrix;
victor's avatar
 
victor committed
55
    QList<Statement*> source;
victor's avatar
 
victor committed
56 57 58 59 60
    bool allowSkipParts;

    int currentPosition;
    QVector<ScriptListPtr> scripts;
    QStack<PDStackElem> stack;
victor's avatar
 
victor committed
61

victor's avatar
 
victor committed
62 63 64
    QStack<int> history_currentPosition;
    QStack< QVector<ScriptListPtr> > history_scripts;
    QStack< QStack<PDStackElem> > history_stack;
victor's avatar
 
victor committed
65

victor's avatar
 
victor committed
66 67
    QVector<ScriptListPtr> fixedScripts;
    QVector<int> nextPointers;
victor's avatar
 
victor committed
68

victor's avatar
 
victor committed
69 70
    AST::Module * currentModule;
    AST::Algorhitm * currentAlgorhitm;
victor's avatar
 
victor committed
71
    QStack< QList<AST::Statement*> * > currentContext;
victor's avatar
 
victor committed
72 73 74 75 76 77

    int maxPriorityValue;

    void matchScript(const QString &text, ScriptListPtr & scripts);

    int errorsCount;
victor's avatar
 
victor committed
78 79

public slots:
victor's avatar
 
victor committed
80
    void addDummyAlgHeader();
victor's avatar
 
victor committed
81
    void setCurrentError(const QString & value);
82
    void setCurrentErrorRaisePosition(Lexem::ErrorRaisePosition pos);
victor's avatar
 
victor committed
83
    void setOutOfAlgError();
victor's avatar
 
victor committed
84
    void setModuleBeginError(const QString & value);
victor's avatar
 
victor committed
85 86
    void setCurrentIndentRank(int start, int end);
    void processCorrectEndOfLoop();
victor's avatar
 
victor committed
87
    void processAlgEndInsteadOfLoopEnd();
victor's avatar
 
victor committed
88
    void processModEndInsteadOfAlgEnd();
victor's avatar
 
victor committed
89 90 91
    void processCorrectCase();
    void processCorrectIf();
    void processCorrectThen();
victor's avatar
 
victor committed
92
    void processCorrectThenIfNotExists();
victor's avatar
 
victor committed
93
    void processCorrectThenIfNotExists2();
victor's avatar
 
victor committed
94 95 96 97 98 99 100
    void processCorrectFi();
    void processCorrectElse();
    void processCorrectSwitch();
    void processCorrectBeginOfLoop();
    void processCorrectAlgHeader();
    void processCorrectAlgBegin();
    void processCorrectDocLine();
victor's avatar
 
victor committed
101
    void processCorrectRestrictionLine();
victor's avatar
 
victor committed
102 103 104 105 106 107 108 109 110
    void processCorrectAlgEnd();
    void processCorrectModuleBegin();
    void processCorrectModuleEnd();
    void processCorrectLoad();
    void appendSimpleLine();
    void setGarbageAlgError();
    void setGarbageIfThenError();
    void setGarbageSwitchCaseError();
    void setCorrespondingIfBroken();
victor's avatar
 
victor committed
111 112
    void setExtraOpenKeywordError(const QString & kw);
    void setExtraCloseKeywordError(const QString & kw);
victor's avatar
 
victor committed
113

victor's avatar
 
victor committed
114 115 116 117 118 119 120 121
    void setTooManyErrors();
    void finalizeIterativeRule(const PDStackElem & stackElem);
    void nextStep();
    void saveData();
    void restoreData();
    void popHistory();
    void clearDataHistory();

victor's avatar
 
victor committed
122 123 124 125 126
};

}

#endif // PDAUTOMATA_P_H