DynGenPar
Dynamic Generalized Parser
pgf.h
Go to the documentation of this file.
1 /* DynGenPar: Dynamic Generalized Parser - PGF import
2  Copyright (C) 2010-2012 Kevin Kofler <kevin.kofler@chello.at>
3  Copyright (C) 2014-2015 DAGOPT Optimization Technologies GmbH
4  written by Kevin Kofler <kofler@dagopt.com>
5 
6  Support by the Austrian Science Fund FWF under contract numbers
7  P20631 and P23554 is gratefully acknowledged.
8 
9  This program is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 
22 #pragma once
23 
24 /* We have to use integers as identifiers for categories and functions because
25  their names are not unique (due to the transformations done to GF grammars to
26  convert them to PMCFGs). */
27 #ifndef DYNGENPAR_INTEGER_CATEGORIES
28 #define DYNGENPAR_INTEGER_CATEGORIES
29 #endif
30 
31 #include "dyngenpar.h"
32 #include <QString>
33 #include <QList>
34 #include <QStringList>
35 #include <QByteArray>
36 #include <QHash>
37 #include <QPair>
38 
39 namespace DynGenPar {
40 
44 };
45 DYNGENPAR_DECLARE_TYPEINFO(PgfReservedTokens, Q_PRIMITIVE_TYPE);
46 
47 #define STATIC static
48 STATIC const char * const PreludeBind = "&+";
49 #undef STATIC
50 
52 struct Pgf {
54  Pgf()
57  Pgf(const QString &fileName, const QString &concreteName = QString());
59  QStringList catNames;
60  QStringList functionNames;
61  QHash<QString, int> tokenHash;
63  QHash<QString, QStringList> componentNames;
66 };
67 DYNGENPAR_DECLARE_TYPEINFO(Pgf, Q_MOVABLE_TYPE);
68 
70 class PgfParser : public Parser {
71  public:
72  PgfParser(const Pgf &p);
73  PgfParser(const QString &fileName, const QString &concreteName = QString());
74  virtual ~PgfParser() {delete inputSource;}
75  void setInputStdin();
76  void setInputFile(const QString &fileName);
77  void setInputBytes(const QByteArray &bytes);
78  void setInputString(const QString &string);
79  void setInputBuffer(QByteArray *buffer);
80  QString catName(int cat) const;
81  QString functionName(int id) const {return pgf.functionNames.at(id);}
82  void filterCoercionsFromSyntaxTree(Node &tree) const;
84  private:
85  void init() {if (!loadPmcfg(pgf.pmcfg)) qFatal("invalid PMCFG");}
86 };
87 DYNGENPAR_DECLARE_TYPEINFO(PgfParser, Q_MOVABLE_TYPE);
88 
89 } // end namespace
#define STATIC
Definition: pgf.h:47
node in the parse tree
Definition: dyngenpar.h:320
representation of the information in .pgf files in a format we can process
Definition: pgf.h:52
QStringList catNames
names of categories, in general not unique
Definition: pgf.h:59
QHash< QString, QStringList > componentNames
names of category components
Definition: pgf.h:64
QList< QPair< QString, int > > suffixes
list of &+ suffixes with their IDs
Definition: pgf.h:62
QHash< QString, int > tokenHash
hash table for quick token lexing
Definition: pgf.h:61
int firstFunction
the function ID of the first non-coercion function
Definition: pgf.h:65
PgfReservedTokens
Definition: pgf.h:41
parser for PGF grammars
Definition: pgf.h:70
QStringList functionNames
names of functions, in general not unique
Definition: pgf.h:60
Pgf()
dummy default constructor for bindings
Definition: pgf.h:54
QString functionName(int id) const
Definition: pgf.h:81
virtual ~PgfParser()
Definition: pgf.h:74
Pmcfg pmcfg
the PMCFG (in (almost) standard form)
Definition: pgf.h:58
main class
Definition: dyngenpar.h:1158
STATIC const char *const PreludeBind
Definition: pgf.h:48