~ubuntu-branches/ubuntu/quantal/kaptain/quantal

« back to all changes in this revision

Viewing changes to kaptain/kgrammar.h

  • Committer: Bazaar Package Importer
  • Author(s): Bradley Bell
  • Date: 2001-11-30 11:25:19 UTC
  • Revision ID: james.westby@ubuntu.com-20011130112519-uw4jutplvr0h2mgx
Tags: upstream-0.6
Import upstream version 0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          kgrammar.h  -  description
 
3
                             -------------------
 
4
    begin                : Tue Aug 1 2000
 
5
    copyright            : (C) 2000 by Ter�k Zsolt
 
6
    email                : tz124@hszk.bme.hu
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#ifndef KGRAMMAR_H
 
19
#define KGRAMMAR_H
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
 
24
 
 
25
#include <qlist.h>
 
26
#include <qdict.h>
 
27
#include <qstring.h>
 
28
#include "krule.h"
 
29
 
 
30
/**Context-free grammar for Kaptain.
 
31
  *@author Ter�k Zsolt
 
32
  */
 
33
 
 
34
class KGrammar {
 
35
  QDict<int> nonterminals;
 
36
  QList<QString> terminals;
 
37
 
 
38
  QList<KRule> rules;
 
39
 
 
40
  /* The number of the last nonterminal symbol stored, the first is -1, decreasing */
 
41
  int lastNonterminal;
 
42
  /* The number of the next terminal symbol stored, starting with 0, increasing */
 
43
  int nextTerminal;
 
44
 public:
 
45
        KGrammar();
 
46
        ~KGrammar();
 
47
        
 
48
        /* get the rule for the given non-terminal */
 
49
        KRule * getRule(int);
 
50
        KRule * getTopLevelRule();
 
51
  KRule * getStartRule();
 
52
                
 
53
  /* check if a nonterminal has already been stored */
 
54
  bool isNonterminal(QString *);
 
55
        /* get the internal number for a non-terminal symbol */
 
56
        int storeNonterminal(QString *);
 
57
        /* get the internal number for a terminal symbol */
 
58
        int storeTerminal(QString *);
 
59
        
 
60
        /* get value for non-terminal */
 
61
        QString getNonterminal(int);
 
62
        /* get value for terminal */
 
63
        QString getTerminal(int);
 
64
        
 
65
        /* get a number for a non-terminal which has no name */
 
66
        int getNewNonterminal();
 
67
 
 
68
        void addRule(KRule *);
 
69
                
 
70
  /* parse a file */
 
71
  bool parse(const char * fname);
 
72
  bool check();
 
73
};
 
74
 
 
75
#endif