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/qstring.h>
12#include <QtCore/qfile.h>
13#include <QtCore/qtextstream.h>
14
15#include <cstdlib>
16
17class Recognizer: protected grammar
18{
19public:
20 Recognizer (Grammar *grammar, bool no_lines);
21 ~Recognizer();
22
23 bool parse (const QString &input_file = QString ());
24
25 inline QString decls () const { return _M_decls; }
26 inline QString impls () const { return _M_impls; }
27
28protected:
29 inline void reallocateStack ();
30
31 inline QString &sym (int index)
32 { return sym_stack [tos + index - 1]; }
33
34protected: // scanner
35 int nextToken();
36
37 inline void inp ()
38 {
39 if (_M_currentChar != _M_lastChar)
40 {
41 ch = *_M_currentChar++;
42
43 if (ch == u'\n')
44 ++_M_line;
45 }
46 else
47 ch = QChar();
48 }
49
50 QString expand (const QString &text) const;
51
52protected:
53 // recognizer
54 int tos;
55 int stack_size;
56 QList<QString> sym_stack;
57 int *state_stack;
58
59 QString _M_contents;
60 QString::const_iterator _M_firstChar;
61 QString::const_iterator _M_lastChar;
62 QString::const_iterator _M_currentChar;
63
64 // scanner
65 QChar ch;
66 int _M_line;
67 int _M_action_line;
68 Grammar *_M_grammar;
69 RulePointer _M_current_rule;
70 QString _M_input_file;
71
72 QString _M_decls;
73 QString _M_impls;
74 QString _M_current_value;
75 bool _M_no_lines;
76};
77
78#endif // RECOGNIZER_H
79

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