1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef RECOGNIZER_H
5#define RECOGNIZER_H
6
7#include "grammar_p.h"
8
9#include "lalr.h"
10
11#include <QtCore/qdebug.h>
12#include <QtCore/qstring.h>
13#include <QtCore/qfile.h>
14#include <QtCore/qtextstream.h>
15
16#include <cstdlib>
17
18class Recognizer: protected grammar
19{
20public:
21 Recognizer (Grammar *grammar, bool no_lines);
22 ~Recognizer();
23
24 bool parse (const QString &input_file = QString ());
25
26 inline QString decls () const { return _M_decls; }
27 inline QString impls () const { return _M_impls; }
28
29protected:
30 inline void reallocateStack ();
31
32 inline QString &sym (int index)
33 { return sym_stack [tos + index - 1]; }
34
35protected: // scanner
36 int nextToken();
37
38 inline void inp ()
39 {
40 if (_M_currentChar != _M_lastChar)
41 {
42 ch = *_M_currentChar++;
43
44 if (ch == u'\n')
45 ++_M_line;
46 }
47 else
48 ch = QChar();
49 }
50
51 QString expand (const QString &text) const;
52
53protected:
54 // recognizer
55 int tos;
56 int stack_size;
57 QList<QString> sym_stack;
58 int *state_stack;
59
60 QString _M_contents;
61 QString::const_iterator _M_firstChar;
62 QString::const_iterator _M_lastChar;
63 QString::const_iterator _M_currentChar;
64
65 // scanner
66 QChar ch;
67 int _M_line;
68 int _M_action_line;
69 Grammar *_M_grammar;
70 RulePointer _M_current_rule;
71 QString _M_input_file;
72
73 QString _M_decls;
74 QString _M_impls;
75 QString _M_current_value;
76 bool _M_no_lines;
77};
78
79#endif // RECOGNIZER_H
80

source code of qtbase/src/tools/qlalr/recognizer.h