Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

merged with 1.1

  • Loading branch information...
commit 6adb1fe19ad2a95b947be78d34554331f6445005 1 parent 3d14756
authored
1  AUTHORS
... ...
@@ -1 +1,2 @@
1 1
 Manuel Astudillo <d00mas@efd.lth.se>
  2
+Pablo Garcia Gonzalez <pgarcia@web.de>
13  INSTALL
@@ -2,23 +2,30 @@
2 2
 UNIX Instructions
3 3
 -----------------
4 4
 
5  
-i) On Linux and FreeBSD
  5
+i) On GCC based environments
6 6
 Be sure that you have a gcc version >= 3.0.
7 7
 You will also need GNU make.
8 8
 
9  
-then type: make -f gcc-linux.mak
  9
+then type: make -f Makefile.gcc
10 10
 And it will compile the library in directory ./lib
11 11
 
12 12
 ii) On HPUX
13  
-type: make -f acc-hpux.mak
  13
+type: make -f Makefile.acc
14 14
 
15 15
 the compiled library will be created on ./lib
16 16
 
  17
+The examples contained in ./examples can be 
  18
+compiled separately in the same way as the 
  19
+library.
17 20
 
18 21
 WINDOWS
19 22
 -------
20 23
 
21 24
 Go to the projfiles directory and load the desired 
22 25
 Visual Studio project.
  26
+Add in the tools->directories>include the path to the
  27
+include directory in the cpp-gpengine directory.
  28
+
  29
+Project files are also provided for the examples.
23 30
 
24 31
 
0  acc-hpux.mak → Makefile.acc
File renamed without changes
2  gcc-linux.mak → Makefile.gcc
... ...
@@ -1,7 +1,7 @@
1 1
 # Project: cpp-gpengine
2 2
 # Makefile created by Pablo Garcia Ganzalez 
3 3
 # Date: 19.10.2003
4  
-# CVS-ID: $Id: gcc-linux.mak,v 1.3 2003/11/07 00:18:23 xtremox Exp $
  4
+# CVS-ID: $Id: Makefile.gcc,v 1.1.2.1 2003/11/30 12:55:29 d00mas Exp $
5 5
 
6 6
 CPP  = g++ 
7 7
 OBJ  = 	src/ASTCreator.o  src/ASTNode.o src/CGTFile.o src/CharacterSetTable.o src/DFA.o src/DFAStateTable.o src/ErrorReporter.o src/ErrorTable.o src/GrammarInfo.o src/LALR.o src/LALRStateTable.o src/NonTerminal.o src/RuleTable.o src/Symbol.o src/SymbolTable.o src/Terminal.o src/Token.o 
30  README
... ...
@@ -1,30 +0,0 @@
1  
-
2  
- Gold Parser Engine (c) 2002 Manuel Astudillo
3  
- --------------------------------------------
4  
-
5  
- This is a C++ implementation of the gold parser
6  
- engine.
7  
- At this moment the only documentation available
8  
- are the sources and a simple test program.
9  
-
10  
- Project files for .NET and VC6 are provided, and the
11  
- sources can be compiled under linux without any problems, 
12  
- but complete Makefiles are not provided yet.
13  
-
14  
- The use is though pretty simple and looking at the
15  
- sources should be enought to understand how it works.
16  
-
17  
- For any questions e-mail me at:
18  
-  
19  
- d00mas@efd.lth.se
20  
-
21  
-
22  
- Check my webpage for this and other projects:
23  
- 
24  
- www.efd.lth.se/~d00mas/
25  
-
26  
-
27  
- 26th June 2002,
28  
-
29  
- Manuel Astudillo.
30  
-
7  WHATSNEW
... ...
@@ -1,6 +1,13 @@
1 1
 History
2 2
 -------
3 3
 
  4
+version 1.0.6 2003/11/29
  5
+------------------------
  6
++ Added 3 examples to show how to use the engine.
  7
++ Exchange a lot of wchar_t* strings to the more reliable wstring
  8
+- Fixed a buffer overflow bug in the DFA 
  9
+- A few more clean ups
  10
+
4 11
 version 1.0.4 2003/11/11
5 12
 ------------------------
6 13
 + UNIX support. The engine compiles and runs on UNIX-based operating 
0  examples/XML/acc-hpux.mak → examples/XML/Makefile.acc
File renamed without changes
0  examples/XML/gcc-linux.mak → examples/XML/Makefile.gcc
File renamed without changes
4  examples/XML/XML.cpp
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
77 77
   
78 78
   // If there are errors report them
79 79
   if (myErrors->errors.size() > 0) {
80  
-    for (int i=0; i < myErrors->errors.size(); i++) {
  80
+    for (unsigned int i=0; i < myErrors->errors.size(); i++) {
81 81
         cout << filename << ":";
82 82
         cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
83 83
     }
@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
96 96
    
97 97
   myErrors = lalr->getErrors(); 
98 98
   if (myErrors->errors.size() != 0) {
99  
-    for (int i=0; i < myErrors->errors.size(); i++) {
  99
+    for (unsigned int i=0; i < myErrors->errors.size(); i++) {
100 100
         cout << filename << ":";
101 101
         cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
102 102
     }
2  examples/XML/ex_xml.xml
... ...
@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" standalone="no"?>
2 2
 <svg width="5cm" height="4cm"
3  
-     xmlns="http://www.w3.org/2000/svg"
  3
+     xmlns="http://www.w3.org/2000/svg">
4 4
   <desc>Four separate rectangles
5 5
   </desc>
6 6
     <rect x="0.5cm" y="0.5cm" width="2cm" height="1cm"/>
0  examples/simple/acc-hpux.mak → examples/logic/Makefile.acc
File renamed without changes
26  examples/logic/Makefile.gcc
... ...
@@ -0,0 +1,26 @@
  1
+# Project: cpp-gpengine
  2
+# Makefile created by Pablo Garcia Gonzalez 
  3
+# Date: 11.11.2003
  4
+
  5
+CPP  = g++ 
  6
+OBJ  = 	logic.o LogicASTCreator.o 
  7
+LIBS = -L"/usr/lib" -L"../../lib" ../../lib/cpp-gpengine-1.0.4.a  
  8
+CXXINCS = -I"../../include/" -I"/usr/include" 
  9
+BIN  = logic 
  10
+CXXFLAGS = $(CXXINCS)  
  11
+
  12
+all: logic
  13
+
  14
+clean: 
  15
+	rm -f $(OBJ) $(BIN)
  16
+
  17
+$(BIN): $(OBJ)
  18
+	$(CPP) $(OBJ) -o "logic" $(LIBS)
  19
+
  20
+logic.o: logic.cpp
  21
+	$(CPP) -c -Wall logic.cpp -o logic.o $(CXXFLAGS)
  22
+
  23
+LogicASTCreator.o: LogicASTCreator.cpp
  24
+	$(CPP) -c -Wall LogicASTCreator.cpp -o LogicASTCreator.o $(CXXFLAGS)
  25
+
  26
+
24  examples/simple/Makefile.acc
... ...
@@ -0,0 +1,24 @@
  1
+# Project: cpp-gpengine
  2
+# Makefile created by Pablo Garcia Ganzalez 
  3
+# Date: 10.11.2003
  4
+
  5
+CPP  = aCC 
  6
+OBJ  = 	simple.o 
  7
+GPENGINELIB = ../../lib/cpp-gpengine-1.0.4.sl   
  8
+LIBS = -L"../../lib" 
  9
+CXXINCS = -I"../../include/" -I"/usr/include" 
  10
+BIN  = simple
  11
+CXXFLAGS = -AA -D_XOPEN_SOURCE=500 $(CXXINCS) 
  12
+
  13
+all: simple 
  14
+
  15
+clean: 
  16
+	rm -f $(OBJ) $(BIN)
  17
+
  18
+$(BIN): $(OBJ)
  19
+	$(CPP) $(OBJ) $(GPENGINELIB) -AA -o "simple" $(LIBS)
  20
+
  21
+simple.o: simple.cpp
  22
+	$(CPP) -c simple.cpp -o simple.o $(CXXFLAGS)
  23
+
  24
+
0  examples/simple/gcc-linux.mak → examples/simple/Makefile.gcc
File renamed without changes
16  examples/simple/simple.cpp
... ...
@@ -1,11 +1,11 @@
1 1
 /***************************************************************************
2  
-								simple.cpp  
  2
+				simple.cpp  
3 3
                              -------------------
4 4
     begin                : Fri May 31 00:53:11 CEST 2002
5 5
     copyright            : (C) 2002-2003 by Manuel Astudillo
6 6
     email                : d00mas@efd.lth.se
7 7
  ***************************************************************************/
8  
-
  8
+                 
9 9
  /***************************************************************************
10 10
  *                                                                         *
11 11
  *   This program is free software; you can redistribute it and/or modify  *
@@ -14,7 +14,7 @@
14 14
  *   License, or (at your option) any later version.                       *
15 15
  *                                                                         *
16 16
  ***************************************************************************/
17  
- 
  17
+  
18 18
 #include <iostream>
19 19
 #include <stdlib.h>
20 20
 
@@ -37,7 +37,7 @@ int main(int argc, char *argv[])
37 37
   SimpleErrorRep   myReporter; 
38 38
 
39 39
   // Load grammar file
40  
-  if (cgtFile.load ("simple.cgt")) {
  40
+  if (cgtFile.load ("simple.cgt")) {     
41 41
     wprintf (L"%s\n", "Grammar loaded succesfully");
42 42
     cgtFile.printInfo ();
43 43
   } else {
@@ -66,9 +66,9 @@ int main(int argc, char *argv[])
66 66
   
67 67
   // If there are errors report them
68 68
   if (myErrors->errors.size() > 0) {
69  
-    for (int i=0; i < myErrors->errors.size(); i++) {
70  
-        cout << filename << ":";
71  
-        cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
  69
+    for (unsigned int i=0; i < myErrors->errors.size(); i++) {
  70
+      cout << filename << ":";
  71
+      cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
72 72
     }
73 73
     return -1;
74 74
   }
@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
85 85
    
86 86
   myErrors = lalr->getErrors(); 
87 87
   if (myErrors->errors.size() != 0) {
88  
-    for (int i=0; i < myErrors->errors.size(); i++) {
  88
+    for (unsigned int i=0; i < myErrors->errors.size(); i++) {
89 89
         cout << filename << ":";
90 90
         cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
91 91
     }
12  include/ASTCreator.h
... ...
@@ -1,8 +1,8 @@
1 1
 /***************************************************************************
2 2
                           ASTCreator.h 
3  
-						  This class works as a framework for the 
4  
-						  creation of an abstract syntax tree specific 
5  
-						  for a grammar
  3
+              This class works as a framework for the 
  4
+	      creation of an abstract syntax tree specific 
  5
+	      for a grammar
6 6
                           -------------------
7 7
     begin                : Sun Jun 2 2002
8 8
     copyright            : (C) 2002 by Manuel Astudillo
@@ -27,11 +27,7 @@
27 27
 using namespace std;
28 28
 
29 29
 #if defined (WIN32) && defined (_USRDLL)
30  
-    class __declspec(dllexport) ASTCreator;
31  
-#endif
32  
-
33  
-#ifndef CREATE_NODE
34  
-	#define CREATE_NODE(X,x) X *x = new X(); x->init(*reduction); x->setParent(parent);  
  30
+class __declspec(dllexport) ASTCreator;
35 31
 #endif
36 32
 
37 33
 class ASTCreator {
14  include/ASTNode.h
@@ -38,19 +38,19 @@
38 38
  
39 39
  class ASTNode {
40 40
  protected:
41  
-    std::wstring  symbol;
42  
-    std::wstring  image;
  41
+    std::wstring  m_symbol;
  42
+    std::wstring  m_image;
43 43
 
44  
-	unsigned short line, col;
  44
+    ASTNode *m_parent;
  45
+	unsigned short m_line, m_col;
45 46
 	
46 47
 	std::vector <ASTNode*> children;
47  
-	ASTNode *parent;
48  
-
  48
+	
49 49
  public:
50  
-    ASTNode ();
51 50
 	virtual ~ASTNode ();
52 51
 
53  
-	void    init      (const Symbol &s);
  52
+	void    init      (const Symbol *s, ASTNode *parent);
  53
+
54 54
 	void    setImage  (wstring image);
55 55
     void    setSymbol (wstring symbol);
56 56
     std::wstring getImage  ();
2  include/ErrorReporter.h
@@ -55,7 +55,7 @@ class ErrorReporter {
55 55
     string composeLineCol (const GPError &err);
56 56
 public:
57 57
     ErrorReporter ();
58  
-    ~ErrorReporter ();
  58
+    virtual ~ErrorReporter ();
59 59
 
60 60
     string  composeErrorMsg   (const GPError &err);
61 61
     wstring composeErrorMsgU  (const GPError &err);
36  src/ASTCreator.cpp
... ...
@@ -1,8 +1,8 @@
1 1
 /***************************************************************************
2 2
                           ASTCreator.cpp
3  
-						  This class works as a framework for the 
4  
-						  creation of an abstract syntax tree specific 
5  
-						  for a grammar
  3
+	      This class works as a framework for the 
  4
+	      creation of an abstract syntax tree specific 
  5
+	      for a grammar
6 6
                           -------------------
7 7
     begin                : Sun Jun 2 2002
8 8
     copyright            : (C) 2002 by Manuel Astudillo
@@ -36,7 +36,8 @@
36 36
 	  the nodes that are not equivalent.
37 37
 	 */
38 38
 
39  
-	 vector <ASTNode*> *children = NULL;
  39
+   
  40
+	 vector <ASTNode*> *children= NULL;
40 41
 	 wstring sym = reduction->symbol;
41 42
 
42 43
 	 deque <Symbol*> rdcChildren;
@@ -65,7 +66,8 @@
65 66
 	<Start> ::= <ConstList> <DefsList> <StatementList>
66 67
 
67 68
 	 if ( sym == L"Start" ) {
68  
-		CREATE_NODE (Start, start); // Check this macro definition for more details
  69
+		Start *start = new Start ();
  70
+        start->init (reduction, parent);
69 71
 
70 72
 		start->addChild (getASTNode(rdcChildren[1], start));
71 73
 		start->addChild (getASTNode(rdcChildren[3], start));
@@ -83,7 +85,8 @@
83 85
 	<StatementList> ::= <Statement>*
84 86
 
85 87
 	 if (sym == L"StatementList") {
86  
-		CREATE_NODE (StatementList, statementList);
  88
+		StatementList *statementList = new StatementList ();
  89
+        statementList->init (reduction, parent);
87 90
 		
88 91
 		if (rdcChildren.size() == 3) {
89 92
 			statementList->addChild (getASTNode (rdcChildren[0], stmtList));
@@ -95,32 +98,31 @@
95 98
 		return stmtList;
96 99
 	 }
97 100
 */
98  
-
99 101
 	 /*
100  
-        If the symbol constants are included it is possible to use a switch-case 
101  
-        for all the rules:
102  
-
103  
-        switch (reduction->symbolIndex) {
  102
+        If the symbol constants are included it is possible to do it in the possible way: 
104 103
 
105 104
             // <If Statement> ::= if <Expression> then <StatementList> end
106  
-            case RULE_IF_THEN_END_STATEMENT:
107  
-                CREATE_NODE (IfStatement, ifStmt);
  105
+            if (sym == RULE_IF_THEN_END_STATEMENT) {
  106
+                IfStatement *ifStatement = new IfStatement ();
  107
+                ifStatement->init (reduction, parent);
108 108
                     
109 109
                 ifStmt->addChild (getASTNode(rdcChildren[1], ifStmt));
110 110
                 ifStmt->addChild (getASTNode(rdcChildren[3], ifStmt));
111 111
 	
112 112
                 return ifStmt;
  113
+            }
113 114
 
114 115
             // <If Statement> ::= if <Expression> then <StatementList> else <StatementList> end
115  
-            case RULE_IF_THEN_END_ELSE_STATEMENT:
116  
-                CREATE_NODE (IfStatement, ifStatement);
  116
+            if ( sym == RULE_IF_THEN_END_ELSE_STATEMENT) {
  117
+                IfStatement *ifStatement = new IfStatement ();
  118
+                ifStatement->init (reduction, parent);
117 119
 
118 120
                 ifStmt->addChild (getASTNode(rdcChildren[1], ifStmt));
119 121
                 ifStmt->addChild (getASTNode(rdcChildren[3], ifStmt));
120 122
 	            ifStmt->addChild (getASTNode(rdcChildren[5], ifStmt));
121 123
                 return ifStmt;
122  
-            default: return searchEquivNode( rdcChildren, parent);
123  
-        }
  124
+            }
  125
+           
124 126
 
125 127
      */
126 128
 
37  src/ASTNode.cpp
@@ -20,10 +20,6 @@
20 20
  #include "ASTNode.h"
21 21
  #include "Terminal.h"
22 22
 
23  
- ASTNode::ASTNode () {
24  
-	 image = L"";
25  
-     symbol = L"";
26  
- } 
27 23
 
28 24
  ASTNode::~ASTNode () {
29 25
 	for (unsigned int i = 0; i < children.size (); i++) {
@@ -32,34 +28,33 @@
32 28
  }
33 29
 
34 30
  
35  
- void ASTNode::init (const Symbol &s) {
36  
- 	line = s.line;
37  
-	col = s.col;
  31
+ void ASTNode::init (const Symbol *s, ASTNode *parent) {
  32
+ 	m_line = s->line;
  33
+	m_col = s->col;
38 34
     
39  
-	if (s.type == NON_TERMINAL) {
40  
-		image = s.symbol;
  35
+	if (s->type == NON_TERMINAL) {
  36
+		m_image = s->symbol;
41 37
 	} else {
42  
-		image = ((Terminal&) s).image;
  38
+		m_image = ((Terminal*) s)->image;
43 39
 	}
44  
-    symbol = s.symbol;
45  
-    
46  
-	parent = NULL;
  40
+    m_symbol = s->symbol;
  41
+	m_parent = parent;
47 42
  }
48 43
 
49 44
  void ASTNode::setImage (wstring image) {
50  
-    this->image = image;
  45
+    m_image = image;
51 46
  }
52 47
 
53 48
  void ASTNode::setSymbol (wstring symbol) {
54  
-    this->symbol = symbol;
  49
+    m_symbol = symbol;
55 50
  }
56 51
 
57 52
  wstring ASTNode::getImage () {
58  
-    return image;
  53
+    return m_image;
59 54
  }
60 55
 
61 56
  wstring ASTNode::getSymbol () {
62  
-    return symbol;
  57
+    return m_symbol;
63 58
  }
64 59
 
65 60
  void ASTNode::addChild (ASTNode *child) {
@@ -73,7 +68,7 @@
73 68
 
74 69
 
75 70
  ASTNode *ASTNode::getParent () {
76  
-	return parent;
  71
+	return m_parent;
77 72
  }
78 73
 
79 74
 
@@ -84,7 +79,7 @@
84 79
   */
85 80
 
86 81
  void ASTNode::setParent (ASTNode *parent) {
87  
-	this->parent = parent;
  82
+	m_parent = parent;
88 83
  }
89 84
 
90 85
 
@@ -94,9 +89,9 @@
94 89
 		wprintf (L" ");
95 90
 	}
96 91
 
97  
-	wprintf (symbol.c_str());
  92
+	wprintf (m_symbol.c_str());
98 93
 	wprintf (L":");
99  
-	wprintf (image.c_str());
  94
+	wprintf (m_image.c_str());
100 95
 	wprintf (L"\n");
101 96
 	
102 97
 	for (i=0; i < children.size(); i++) {
671  src/CGTFile.cpp
@@ -37,347 +37,348 @@
37 37
    theLALR = NULL;
38 38
  }
39 39
 
40  
- CGTFile::~CGTFile () {
41  
-
42  
-	 delete gInfo;
43  
-
44  
-	 delete [] errorString;
45  
-
46  
-     // Delete tables
47  
-     delete symbolTable;
48  
-     delete stateTable;
49  
-     delete LALRTable;
50  
-     delete ruleTable;
51  
-     delete characterSetTable;
52  
-
53  
-	 delete theDFA;
54  
-	 delete theLALR;
55  
- }
56  
-
57  
- bool CGTFile::load (char *filename) {
58  
-    ifstream cgtStream;
59  
-
60  
-    cgtStream.open (filename, ifstream::in | ifstream::binary);
61  
-
62  
-    if (((void*) cgtStream) == NULL) {
63  
-        return false;
  40
+CGTFile::~CGTFile () {
  41
+  
  42
+  delete gInfo;
  43
+  
  44
+  delete [] errorString;
  45
+  
  46
+  // Delete tables
  47
+  delete symbolTable;
  48
+  delete stateTable;
  49
+  delete LALRTable;
  50
+  delete ruleTable;
  51
+  delete characterSetTable;
  52
+  
  53
+  delete theDFA;
  54
+  delete theLALR;
  55
+}
  56
+
  57
+bool CGTFile::load (char *filename) {
  58
+  ifstream cgtStream;
  59
+  
  60
+  cgtStream.open (filename, ifstream::in | ifstream::binary);
  61
+  
  62
+  if (((void*) cgtStream) == NULL) {
  63
+    return false;
  64
+  }
  65
+  
  66
+  bool result = load (&cgtStream);
  67
+  cgtStream.close();
  68
+  return result;
  69
+}
  70
+
  71
+bool CGTFile::load (ifstream *myStream) {
  72
+  int i;	
  73
+  
  74
+  EntryStruct entry;
  75
+  
  76
+  theStream = myStream;
  77
+  
  78
+  // Read Header
  79
+  //////////////
  80
+  header = readUnicodeString();
  81
+
  82
+  // Read Records
  83
+  ////////////////
  84
+  unsigned char recordType;
  85
+  integer nbrEntries;
  86
+  integer index;
  87
+
  88
+  while (!theStream->eof()) {
  89
+    // Read record type & number of entries
  90
+    theStream->read ((char*)&recordType, 1);
  91
+    if (theStream->fail()) {
  92
+      if (theStream->eof()) {
  93
+	break;
  94
+      } else {
  95
+	return false;
  96
+      }
64 97
     }
65  
-
66  
-    bool result = load (&cgtStream);
67  
-    cgtStream.close();
68  
-    return result;
69  
- }
70  
-
71  
- bool CGTFile::load (ifstream *myStream) {
72  
-   int i;	
73  
-
74  
-   EntryStruct entry;
75  
-
76  
-   theStream = myStream;
77  
-
78  
-   // Read Header
79  
-   //////////////
80  
-   header = readUnicodeString();
81  
-
82  
-   // Read Records
83  
-   ////////////////
84  
-   unsigned char recordType;
85  
-   integer nbrEntries;
86  
-   integer index;
87  
-
88  
-   while (!theStream->eof()) {
89  
-     // Read record type & number of entries
90  
-     theStream->read ((char*)&recordType, 1);
91  
-     if (theStream->fail()) {
92  
-        if (theStream->eof()) {
93  
-			break;
94  
-        } else {
95  
-			return false;
96  
-        }
97  
-     }
98  
-
  98
+    
99 99
     theStream->read ((char*) &nbrEntries, 2);
100 100
     //Convert to little endian if needed.
101 101
     nbrEntries = EndianConversion(nbrEntries);
102 102
     //wprintf (L"Record Type: %i\n", recordType);
103 103
     //wprintf (L"Entries: %i\n", nbrEntries);
104  
-
105  
-     if (recordType != 77) {
106  
-       errorString = "Record type is not supported\n";
107  
-       return false;
108  
-     }
109  
-
110  
-     // Read the type of content
111  
-     byte contentType;
112  
-     readEntry (&entry);
113  
-     contentType = entry.vByte;
114  
-
115  
-     //wprintf (L"Content Type: %d\n", contentType);
116  
-
117  
-     switch (contentType) {
118  
-
119  
-       // Parameters Record	
120  
-       case 'P':
121  
-	   delete gInfo;
122  
-	   gInfo = new GrammarInfo ();
123  
-
124  
-       // read name
125  
-       readEntry (&entry);
126  
-        
127  
-       gInfo->name = entry.vString;
128  
-
129  
-       // read version
130  
-       readEntry (&entry);
131  
-       gInfo->version = entry.vString;
132  
-
133  
-       // read Author
134  
-       readEntry (&entry);
135  
-       gInfo->author = entry.vString;
136  
-
137  
-       // read About
138  
-       readEntry (&entry);
139  
-       gInfo->about = entry.vString;
140  
-
141  
-       // Case
142  
-       readEntry (&entry);
143  
-       caseSensitive = entry.vBool;
144  
-
145  
-       // start symbol
146  
-       readEntry  (&entry);
147  
-       startSymbol = entry.vInteger;
148  
-
149  
-       break;
150  
-
151  
-       // Table Counts
152  
-       case 'T' :
153  
-       readEntry (&entry);
154  
-       nbrSymbolTable = entry.vInteger;
155  
-
156  
-       // Delete & Create a Symbol Table
157  
-       delete symbolTable;
158  
-       symbolTable = new SymbolTable (nbrSymbolTable);
159  
-
160  
-       readEntry (&entry);
161  
-       nbrCharacterSets = entry.vInteger;
162  
-
163  
-       // Delete & Create a Character Sets Table
164  
-       delete characterSetTable;
165  
-       characterSetTable = new CharacterSetTable (nbrCharacterSets);
166  
-
167  
-       // Delete & Create a Rule Table
168  
-       readEntry (&entry);
169  
-       nbrRuleTable = entry.vInteger;
170  
-       delete ruleTable;
171  
-       ruleTable = new RuleTable (nbrRuleTable);
172  
-
173  
-       // Delete & Create a DFAStateTable
174  
-       readEntry (&entry);
175  
-       nbrDFATable = entry.vInteger;
176  
-       delete stateTable;
177  
-       stateTable = new DFAStateTable (nbrDFATable);
178  
-
179  
-        // Delete & Create a LALR Table
180  
-       readEntry (&entry);
181  
-       nbrLALRTable = entry.vInteger;
182  
-       delete LALRTable;
183  
-       LALRTable = new LALRStateTable (nbrLALRTable);
184  
-
185  
-       break;
186  
-
187  
-       // Character Set Table Entry
188  
-       case 'C' :
189  
-       readEntry (&entry);
190  
-       index = entry.vInteger;
191  
-
192  
-       readEntry (&entry);
193  
-       characterSetTable->characters[index] =  entry.vString;
194  
-       break;
195  
-
196  
-       // Symbol Table Entry
197  
-       case 'S' :
198  
-       readEntry (&entry);
199  
-       index = entry.vInteger;
200  
-
201  
-       readEntry (&entry);
202  
-       symbolTable->symbols[index].name = entry.vString;
203  
-
204  
-       readEntry (&entry);
205  
-       symbolTable->symbols[index].kind = (SymbolType) entry.vInteger;
206  
-       break;
207  
-
208  
-       // Rule
209  
-       case 'R' :
210  
-       readEntry (&entry);
211  
-       index = entry.vInteger;
212  
-       ruleTable->rules[index].ruleIndex = index;
213  
-
214  
-       readEntry (&entry);
215  
-       ruleTable->rules[index].symbolIndex = entry.vInteger;
216  
-
217  
-       // Read empty field
218  
-       readEntry (&entry);
219  
-
220  
-       // Read symbols for this rule (nonTerminal -> symbol0 symbol1 ... symboln)
221  
-       for (i=0; i < nbrEntries-4; i++) {
222  
-         readEntry (&entry);
  104
+    
  105
+    if (recordType != 77) {
  106
+      errorString = "Record type is not supported\n";
  107
+      return false;
  108
+    }
  109
+    
  110
+    // Read the type of content
  111
+    byte contentType;
  112
+    readEntry (&entry);
  113
+    contentType = entry.vByte;
  114
+    
  115
+    //wprintf (L"Content Type: %d\n", contentType);
  116
+    
  117
+    switch (contentType) {
  118
+      // Parameters Record	
  119
+    case 'P':
  120
+      delete gInfo;
  121
+      gInfo = new GrammarInfo ();
  122
+      
  123
+      // read name
  124
+      readEntry (&entry);  
  125
+      gInfo->name = entry.vString;
  126
+      
  127
+      // read version
  128
+      readEntry (&entry);
  129
+      gInfo->version = entry.vString;
  130
+      
  131
+      // read Author
  132
+      readEntry (&entry);
  133
+      gInfo->author = entry.vString;
  134
+      
  135
+      // read About
  136
+      readEntry (&entry);
  137
+      gInfo->about = entry.vString;
  138
+      
  139
+      // Case
  140
+      readEntry (&entry);
  141
+      caseSensitive = entry.vBool;
  142
+      
  143
+      // start symbol
  144
+      readEntry  (&entry);
  145
+      startSymbol = entry.vInteger;
  146
+      
  147
+      break;
  148
+      
  149
+      // Table Counts
  150
+    case 'T' :
  151
+      readEntry (&entry);
  152
+      nbrSymbolTable = entry.vInteger;
  153
+      
  154
+      // Delete & Create a Symbol Table
  155
+      delete symbolTable;
  156
+      symbolTable = new SymbolTable (nbrSymbolTable);
  157
+      
  158
+      readEntry (&entry);
  159
+      nbrCharacterSets = entry.vInteger;
  160
+      
  161
+      // Delete & Create a Character Sets Table
  162
+      delete characterSetTable;
  163
+      characterSetTable = new CharacterSetTable (nbrCharacterSets);
  164
+      
  165
+      // Delete & Create a Rule Table
  166
+      readEntry (&entry);
  167
+      nbrRuleTable = entry.vInteger;
  168
+      delete ruleTable;
  169
+      ruleTable = new RuleTable (nbrRuleTable);
  170
+      
  171
+      // Delete & Create a DFAStateTable
  172
+      readEntry (&entry);
  173
+      nbrDFATable = entry.vInteger;
  174
+      delete stateTable;
  175
+      stateTable = new DFAStateTable (nbrDFATable);
  176
+      
  177
+      // Delete & Create a LALR Table
  178
+      readEntry (&entry);
  179
+      nbrLALRTable = entry.vInteger;
  180
+      delete LALRTable;
  181
+      LALRTable = new LALRStateTable (nbrLALRTable);
  182
+      
  183
+      break;
  184
+      
  185
+      // Character Set Table Entry
  186
+    case 'C' :
  187
+      readEntry (&entry);
  188
+      index = entry.vInteger;
  189
+      
  190
+      readEntry (&entry);
  191
+      characterSetTable->characters[index] =  entry.vString;
  192
+      break;
  193
+      
  194
+      // Symbol Table Entry
  195
+    case 'S' :
  196
+      readEntry (&entry);
  197
+      index = entry.vInteger;
  198
+      
  199
+      readEntry (&entry);
  200
+      symbolTable->symbols[index].name = entry.vString;
  201
+      
  202
+      readEntry (&entry);
  203
+      symbolTable->symbols[index].kind = (SymbolType) entry.vInteger;
  204
+      break;
  205
+      
  206
+      // Rule
  207
+    case 'R' :
  208
+      readEntry (&entry);
  209
+      index = entry.vInteger;
  210
+      ruleTable->rules[index].ruleIndex = index;
  211
+      
  212
+      readEntry (&entry);
  213
+      ruleTable->rules[index].symbolIndex = entry.vInteger;
  214
+      
  215
+      // Read empty field
  216
+      readEntry (&entry);
  217
+      
  218
+      // Read symbols for this rule (nonTerminal -> symbol0 symbol1 ... symboln)
  219
+      for (i=0; i < nbrEntries-4; i++) {
  220
+	readEntry (&entry);
223 221
         // ruleTable->rules[index].symbols.push_back (entry.vInteger);
224  
-		 RuleStruct *rst = &ruleTable->rules[index];
225  
-		 
226  
-		 vector <integer> *s = &rst->symbols;
227  
-		 s->push_back (entry.vInteger);
228  
-       }
229  
-       break;
230  
-
231  
-       // Initial States
232  
-       case 'I' :
233  
-       readEntry(&entry);
234  
-       DFAInit = entry.vInteger;
235  
-
236  
-       readEntry (&entry);
237  
-       LALRInit = entry.vInteger;
238  
-       break;
239  
-
240  
-
241  
-       // DFA State Entry
242  
-       case 'D':
243  
-       readEntry (&entry);
244  
-       index = entry.vInteger;
245  
-
246  
-       // create a new State an insert it in the table
247  
-       readEntry (&entry);
248  
-       stateTable->states[index].accept = entry.vBool;
249  
-
250  
-       readEntry(&entry);
251  
-       stateTable->states[index].acceptIndex = entry.vInteger;
252  
-
253  
-       readEntry(&entry);
254  
-
255  
-       Edge edge;
256  
-       for (i=0; i < nbrEntries-5; i+=3) {
257  
-
258  
-         readEntry(&entry);
259  
-         edge.characterSetIndex = entry.vInteger;
260  
-
261  
-         readEntry(&entry);
262  
-         edge.targetIndex = entry.vInteger;
263  
-
264  
-         readEntry(&entry);
265  
-
266  
-         stateTable->states[index].edges.push_back(edge);
267  
-       }
268  
-       break;
269  
-
270  
-       // LALR State entry
271  
-       case 'L':
272  
-       readEntry(&entry);
273  
-       index = entry.vInteger;
274  
-
275  
-       readEntry(&entry);
276  
-
277  
-       Action action;
278  
-       for (i=0; i < nbrEntries-3; i+=4) {
279  
-         readEntry(&entry);
280  
-         action.symbolIndex = entry.vInteger;
281  
-
282  
-         readEntry(&entry);
283  
-         action.action = entry.vInteger;
284  
-
285  
-         readEntry(&entry);
286  
-         action.target = entry.vInteger;
287  
-
288  
-         readEntry(&entry);
289  
-
290  
-         LALRTable->states[index].actions.push_back(action);
291  
-       }
292  
-
  222
+	RuleStruct *rst = &ruleTable->rules[index];
  223
+	
  224
+	vector <integer> *s = &rst->symbols;
  225
+	s->push_back (entry.vInteger);
  226
+      }
293 227
       break;
294  
-
295  
-     }
296  
-
297  
-   }
298  
-   return true;
299  
- }
300  
-
301  
-   /*
302  
-   Reads an entry in a record
303  
-   */
304  
-   void CGTFile::readEntry (EntryStruct *entry) {
305  
-
306  
-     char tmpChar;
307  
-     char dataType;
308  
-
309  
-     theStream->get (dataType);
310  
-     if (theStream->fail()) {
311  
-		 wprintf (L"Error reading entry\n");
312  
-	 } else {
313  
-		 switch (dataType) {
314  
-		case 'E': break;
315  
-		case 'B':
316  
-		theStream->get (tmpChar);
317  
-        if (tmpChar) {
318  
-		  entry->vBool = true;
319  
-		} else {
320  
-		  entry->vBool = false;
321  
-		}
322  
-		break;
323  
-		case 'b':
324  
-		theStream->read ((char*) &entry->vByte, 1);
325  
-        break;
326  
-		case 'I':
327  
-		theStream->read ((char*) &entry->vInteger, 2);
328  
-        entry->vInteger = EndianConversion(entry->vInteger); 
329  
-        break;
330  
-		case 'S':
331  
-		entry->vString = readUnicodeString();
332  
-		break;
333  
-     }
334  
-	}
335  
-
336  
-   }
337  
-
338  
-
339  
- /*
340  
- Reads a Unicode String
341  
- */
342  
-
343  
- wstring CGTFile::readUnicodeString () {
344  
-   wchar_t readChar;
345  
-   wstring str;
346  
-   
347  
-   theStream->read ((char*) &readChar, 2);
348  
-   while (readChar != 0) {
349  
-        str.append (1, readChar);
350  
-        theStream->read ((char*)&readChar, 2);
351  
-   }
352  
-
353  
-   return str;
354  
- }
355  
-
356  
-
357  
- GrammarInfo *CGTFile::getInfo () {
358  
-	return gInfo;
359  
- }
360  
-
361  
- DFA *CGTFile::getScanner () {
362  
-     delete theDFA;
363  
-	 theDFA = new DFA (stateTable, symbolTable,
364  
-     characterSetTable, DFAInit, caseSensitive);
365  
-     return theDFA;
366  
- }
367  
-
368  
-
369  
- LALR *CGTFile::getParser () {
370  
-	 delete theLALR;
371  
-     theLALR = new LALR (LALRTable, symbolTable, ruleTable, LALRInit);
372  
-     return theLALR;
373  
- }
374  
-
375  
- void CGTFile::printInfo () {
376  
-    // Prints the info of this grammar
377  
-    wprintf (L"Grammar Information\n");
378  
-    wprintf (L"Name: %s\n", gInfo->name.c_str());
379  
-	wprintf (L"Version: %s\n", gInfo->version.c_str());
380  
-	wprintf (L"Author: %s\n", gInfo->author.c_str());
381  
-	wprintf (L"About: %s\n", gInfo->about.c_str());
382  
- }
  228
+      
  229
+      // Initial States
  230
+    case 'I' :
  231
+      readEntry(&entry);
  232
+      DFAInit = entry.vInteger;
  233
+      
  234
+      readEntry (&entry);
  235
+      LALRInit = entry.vInteger;
  236
+      break;
  237
+      
  238
+      
  239
+      // DFA State Entry
  240
+    case 'D':
  241
+      readEntry (&entry);
  242
+      index = entry.vInteger;
  243
+      
  244
+      // create a new State an insert it in the table
  245
+      readEntry (&entry);
  246
+      stateTable->states[index].accept = entry.vBool;
  247
+      
  248
+      readEntry(&entry);
  249
+      stateTable->states[index].acceptIndex = entry.vInteger;
  250
+      
  251
+      readEntry(&entry);
  252
+      
  253
+      Edge edge;
  254
+      for (i=0; i < nbrEntries-5; i+=3) {
  255
+	
  256
+	readEntry(&entry);
  257
+	edge.characterSetIndex = entry.vInteger;
  258
+	
  259
+	readEntry(&entry);
  260
+	edge.targetIndex = entry.vInteger;
  261
+	
  262
+	readEntry(&entry);
  263
+	
  264
+	stateTable->states[index].edges.push_back(edge);
  265
+      }
  266
+      break;
  267
+      
  268
+      // LALR State entry
  269
+    case 'L':
  270
+      readEntry(&entry);
  271
+      index = entry.vInteger;
  272
+      
  273
+      readEntry(&entry);
  274
+      
  275
+      Action action;
  276
+      for (i=0; i < nbrEntries-3; i+=4) {
  277
+	readEntry(&entry);
  278
+	action.symbolIndex = entry.vInteger;
  279
+	
  280
+	readEntry(&entry);
  281
+	action.action = entry.vInteger;
  282
+	
  283
+	readEntry(&entry);
  284
+	action.target = entry.vInteger;
  285
+	
  286
+	readEntry(&entry);
  287
+	
  288
+	LALRTable->states[index].actions.push_back(action);
  289
+      }
  290
+      
  291
+      break;
  292
+      
  293
+    }
  294
+    
  295
+  }
  296
+  return true;
  297
+}
  298
+
  299
+/*
  300
+  Reads an entry in a record
  301
+*/
  302
+void CGTFile::readEntry (EntryStruct *entry) {
  303
+  
  304
+  char tmpChar;
  305
+  char dataType;
  306
+  
  307
+  theStream->get (dataType);
  308
+  if (theStream->fail()) {
  309
+    wprintf (L"Error reading entry\n");
  310
+  } else {
  311
+    switch (dataType) {
  312
+    case 'E': break;
  313
+    case 'B':
  314
+      theStream->get (tmpChar);
  315
+      if (tmpChar) {
  316
+	entry->vBool = true;
  317
+      } else {
  318
+	entry->vBool = false;
  319
+      }
  320
+      break;
  321
+    case 'b':
  322
+      theStream->read ((char*) &entry->vByte, 1);
  323
+      break;
  324
+    case 'I':
  325
+      theStream->read ((char*) &entry->vInteger, 2);
  326
+      entry->vInteger = EndianConversion(entry->vInteger); 
  327
+      break;
  328
+    case 'S':
  329
+      entry->vString = readUnicodeString();
  330
+      break;
  331
+    }
  332
+  }
  333
+  
  334
+}
  335
+
  336
+
  337
+/*
  338
+  Reads a Unicode String
  339
+*/
  340
+
  341
+wstring CGTFile::readUnicodeString () {
  342
+  char readChar[2];
  343
+  wstring str;
  344
+  
  345
+  theStream->read ((char*) &readChar, 2);
  346
+  while ((readChar[0] != 0) && (!theStream->eof())){
  347
+    str.append (1, (wchar_t) ((readChar[1] << 8) | readChar[0]));
  348
+    theStream->read ((char*) &readChar, 2);
  349
+  }
  350
+  return str;
  351
+}
  352
+
  353
+GrammarInfo *CGTFile::getInfo () {
  354
+  return gInfo;
  355
+}
  356
+
  357
+DFA *CGTFile::getScanner () {
  358
+  delete theDFA;
  359
+  theDFA = new DFA (stateTable, symbolTable,
  360
+		    characterSetTable, DFAInit, caseSensitive);
  361
+  return theDFA;
  362
+}
  363
+
  364
+
  365
+LALR *CGTFile::getParser () {
  366
+  delete theLALR;
  367
+  theLALR = new LALR (LALRTable, symbolTable, ruleTable, LALRInit);
  368
+  return theLALR;
  369
+}
  370
+
  371
+void CGTFile::printInfo () {
  372
+  // Prints the info of this grammar
  373
+  wprintf (L"Grammar Information\n");
  374
+  wprintf (L"Name: ");
  375
+  wprintf (gInfo->name.c_str());
  376
+  wprintf (L"\nVersion: ");
  377
+  wprintf (gInfo->version.c_str());
  378
+  wprintf (L"\nAuthor: ");
  379
+  wprintf (gInfo->author.c_str());
  380
+  wprintf (L"\nAbout: ");
  381
+  wprintf (gInfo->about.c_str());
  382
+  wprintf (L"\n");
  383
+}
383 384
 

0 notes on commit 6adb1fe

Please sign in to comment.
Something went wrong with that request. Please try again.