Skip to content

Commit 0b5f054

Browse files
author
d00mas
committed
fixed CGTFile to work under unix
1 parent c98b5cb commit 0b5f054

File tree

12 files changed

+103
-74
lines changed

12 files changed

+103
-74
lines changed

INSTALL

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@ i) On GCC based environments
66
Be sure that you have a gcc version >= 3.0.
77
You will also need GNU make.
88

9-
then type: make -f gcc-linux.mak
9+
then type: make -f Makefile.gcc
1010
And it will compile the library in directory ./lib
1111

1212
ii) On HPUX
13-
type: make -f acc-hpux.mak
13+
type: make -f Makefile.acc
1414

1515
the compiled library will be created on ./lib
1616

17+
The examples contained in ./examples can be
18+
compiled separately in the same way as the
19+
library.
1720

1821
WINDOWS
1922
-------
2023

2124
Go to the projfiles directory and load the desired
2225
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.
2330

2431

examples/XML/XML.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
7777

7878
// If there are errors report them
7979
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++) {
8181
cout << filename << ":";
8282
cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
8383
}
@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
9696

9797
myErrors = lalr->getErrors();
9898
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++) {
100100
cout << filename << ":";
101101
cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
102102
}

examples/XML/ex_xml.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" standalone="no"?>
22
<svg width="5cm" height="4cm"
3-
xmlns="http://www.w3.org/2000/svg"
3+
xmlns="http://www.w3.org/2000/svg">
44
<desc>Four separate rectangles
55
</desc>
66
<rect x="0.5cm" y="0.5cm" width="2cm" height="1cm"/>

examples/logic/LogicASTCreator.cpp

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Please read AbstractSyntaxGrammr.txt for info on the abstract grammar
88

99
ASTNode *LogicASTCreator::getASTNode (const Symbol *reduction,
10-
ASTNode *parent) {
10+
ASTNode *parent) {
1111
vector <ASTNode*> *children = NULL;
1212
int ind;
1313

@@ -31,7 +31,8 @@ ASTNode *LogicASTCreator::getASTNode (const Symbol *reduction,
3131
// <Start> ::= <NewLineList> <AxiomList>
3232
// Start := AxiomList
3333
if ( ind == RULE_START) {
34-
CREATE_NODE (Start, start);
34+
Start *start = new Start ();
35+
start->init (reduction, parent);
3536

3637
start->addChild (getASTNode(rdcChildren[1], start));
3738
return start;
@@ -40,7 +41,8 @@ ASTNode *LogicASTCreator::getASTNode (const Symbol *reduction,
4041
// <AxiomList> ::= <Axiom> <AxiomList>
4142
// AxiomList := Axiom*
4243
if (ind == RULE_AXIOMLIST) {
43-
CREATE_NODE (AxiomList, axiomList);
44+
AxiomList *axiomList = new AxiomList ();
45+
axiomList->init (reduction, parent);
4446

4547
axiomList->addChild (getASTNode (rdcChildren[0], axiomList));
4648

@@ -53,7 +55,8 @@ ASTNode *LogicASTCreator::getASTNode (const Symbol *reduction,
5355
// <Implication> ::= <DoubleImplication> '->' <Implication>
5456
// Implication:Axiom := Axiom Axiom
5557
if (ind == RULE_IMPLICATION_MINUSGT) {
56-
CREATE_NODE (Implication, implication);
58+
Implication *implication = new Implication ();
59+
implication->init (reduction, parent);
5760

5861
implication->addChild (getASTNode (rdcChildren[0], implication));
5962
implication->addChild (getASTNode (rdcChildren[2], implication));
@@ -63,7 +66,8 @@ ASTNode *LogicASTCreator::getASTNode (const Symbol *reduction,
6366
// <DoubleImplication> ::= <Or> '<->' <DoubleImplication>
6467
// DoubleImplication:Axiom := Axiom Axiom
6568
if (ind == RULE_DOUBLEIMPLICATION_LTMINUSGT) {
66-
CREATE_NODE (DoubleImplication, doubleImplication);
69+
DoubleImplication *doubleImplication = new DoubleImplication ();
70+
doubleImplication->init (reduction, parent);
6771

6872
doubleImplication->addChild (getASTNode (rdcChildren[0],
6973
doubleImplication));
@@ -75,52 +79,58 @@ ASTNode *LogicASTCreator::getASTNode (const Symbol *reduction,
7579
// <Or> ::= <And> OR <Or>
7680
// Or:Axiom := Axiom Axiom
7781
if (ind == RULE_OR_OR) {
78-
CREATE_NODE (Or, or);
82+
Or *_or = new Or ();
83+
_or->init (reduction, parent);
7984

80-
or->addChild (getASTNode (rdcChildren[0], or));
81-
or->addChild (getASTNode (rdcChildren[2], or));
82-
return or;
85+
_or->addChild (getASTNode (rdcChildren[0], _or));
86+
_or->addChild (getASTNode (rdcChildren[2], _or));
87+
return _or;
8388
}
8489

8590
// <And> ::= <Not> AND <And>
8691
// And:Axiom := Axiom Axiom
8792
if (ind == RULE_AND_AND) {
88-
CREATE_NODE (And, and);
93+
And *_and = new And ();
94+
_and->init (reduction, parent);
8995

90-
and->addChild (getASTNode (rdcChildren[0], and));
91-
and->addChild (getASTNode (rdcChildren[2], and));
92-
return and;
96+
_and->addChild (getASTNode (rdcChildren[0], _and));
97+
_and->addChild (getASTNode (rdcChildren[2], _and));
98+
return _and;
9399
}
94100

95101
// <Not> ::= NOT <Value>
96102
// Not:Axiom := Axiom
97103
if (ind == RULE_NOT_NOT) {
98-
CREATE_NODE (Not, not);
104+
Not *_not = new Not ();
105+
_not->init (reduction, parent);
99106

100-
not->addChild (getASTNode (rdcChildren[1], not));
101-
return not;
107+
_not->addChild (getASTNode (rdcChildren[1], _not));
108+
return _not;
102109
}
103110

104111

105112
// <Proposition> ::= ID
106113
// Proposition:Axiom := ID
107114
if (ind == RULE_PROPOSITION_ID) {
108-
CREATE_NODE (Proposition, proposition);
115+
Proposition *proposition = new Proposition ();
116+
proposition->init (reduction, parent);
109117
proposition->addChild (getASTNode (rdcChildren[0],proposition));
110118
return proposition;
111119
}
112120

113-
// Process Terminal Symbols (just create nodes for everyone of it, maybe
114-
// Convert data types from wstring to other more convenient types
121+
// Process Terminal Symbols (just create nodes for everyone of it, maybe also
122+
// convert data types from wstring to other more convenient types)
115123
} else {
116124
ind = reduction->symbolIndex;
117125
// Terminal:
118126
// ID
119127
if (ind == SYMBOL_ID) {
120-
CREATE_NODE (Terminal_ID, id);
128+
Terminal_ID *id = new Terminal_ID ();
129+
id->init (reduction, parent);
121130
return id;
122131
}
123132
}
124133

134+
// Search for equivalent nodes among the childrens of this reduction
125135
return searchEquivNode( rdcChildren, parent);
126136
}

examples/logic/logic.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
3939
ErrorTable *myErrors;
4040
ErrorReporter myReporter;
4141
LogicASTCreator myASTCreator;
42-
42+
4343
// Load grammar file
4444
if (cgtFile.load ("logic.cgt")) {
4545
wprintf (L"%s\n", "Grammar loaded succesfully");
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
7070

7171
// If there are errors report them
7272
if (myErrors->errors.size() > 0) {
73-
for (int i=0; i < myErrors->errors.size(); i++) {
73+
for (unsigned int i=0; i < myErrors->errors.size(); i++) {
7474
cout << filename << ":";
7575
cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
7676
}
@@ -89,7 +89,7 @@ int main(int argc, char *argv[])
8989

9090
myErrors = lalr->getErrors();
9191
if (myErrors->errors.size() != 0) {
92-
for (int i=0; i < myErrors->errors.size(); i++) {
92+
for (unsigned int i=0; i < myErrors->errors.size(); i++) {
9393
cout << filename << ":";
9494
cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
9595
}

examples/logic/logic.dsw

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ Microsoft Developer Studio Workspace File, Format Version 6.00
33

44
###############################################################################
55

6+
Project: "gpengine"="..\..\projfiles\VC6\gpengine.dsp" - Package Owner=<4>
7+
8+
Package=<5>
9+
{{{
10+
}}}
11+
12+
Package=<4>
13+
{{{
14+
}}}
15+
16+
###############################################################################
17+
618
Project: "logic"=".\logic.dsp" - Package Owner=<4>
719

820
Package=<5>

examples/logic/logic.ncb

104 KB
Binary file not shown.

include/ASTNode.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,18 @@
3838

3939
class ASTNode {
4040
protected:
41-
std::wstring symbol;
42-
std::wstring image;
41+
std::wstring m_symbol;
42+
std::wstring m_image;
4343

44-
unsigned short line, col;
44+
ASTNode *m_parent;
45+
unsigned short m_line, m_col;
4546

4647
std::vector <ASTNode*> children;
47-
ASTNode *parent;
48-
48+
4949
public:
50-
ASTNode ();
5150
virtual ~ASTNode ();
5251

53-
void init (const Symbol &s);
52+
void init (const Symbol *s, ASTNode *parent);
5453
void setImage (wstring image);
5554
void setSymbol (wstring symbol);
5655
std::wstring getImage ();

include/ErrorReporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ErrorReporter {
5555
string composeLineCol (const GPError &err);
5656
public:
5757
ErrorReporter ();
58-
~ErrorReporter ();
58+
virtual ~ErrorReporter ();
5959

6060
string composeErrorMsg (const GPError &err);
6161
wstring composeErrorMsgU (const GPError &err);

src/ASTCreator.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
<Start> ::= <ConstList> <DefsList> <StatementList>
6767
6868
if ( sym == L"Start" ) {
69-
CREATE_NODE (Start, start); // Check this macro definition for more details
69+
Start *start = new Start ();
70+
start->init (reduction, parent);
7071
7172
start->addChild (getASTNode(rdcChildren[1], start));
7273
start->addChild (getASTNode(rdcChildren[3], start));
@@ -84,7 +85,8 @@
8485
<StatementList> ::= <Statement>*
8586
8687
if (sym == L"StatementList") {
87-
CREATE_NODE (StatementList, statementList);
88+
StatementList *statementList = new StatementList ();
89+
statementList->init (reduction, parent);
8890
8991
if (rdcChildren.size() == 3) {
9092
statementList->addChild (getASTNode (rdcChildren[0], stmtList));
@@ -98,30 +100,30 @@
98100
*/
99101

100102
/*
101-
If the symbol constants are included it is possible to use a switch-case
102-
for all the rules:
103-
104-
switch (reduction->symbolIndex) {
103+
If the symbol constants are included it is possible to do it in the possible way:
105104
106105
// <If Statement> ::= if <Expression> then <StatementList> end
107-
case RULE_IF_THEN_END_STATEMENT:
108-
CREATE_NODE (IfStatement, ifStmt);
106+
if (sym == RULE_IF_THEN_END_STATEMENT) {
107+
IfStatement *ifStatement = new IfStatement ();
108+
ifStatement->init (reduction, parent);
109109
110110
ifStmt->addChild (getASTNode(rdcChildren[1], ifStmt));
111111
ifStmt->addChild (getASTNode(rdcChildren[3], ifStmt));
112112
113113
return ifStmt;
114+
}
114115
115116
// <If Statement> ::= if <Expression> then <StatementList> else <StatementList> end
116-
case RULE_IF_THEN_END_ELSE_STATEMENT:
117-
CREATE_NODE (IfStatement, ifStatement);
117+
if ( sym == RULE_IF_THEN_END_ELSE_STATEMENT) {
118+
IfStatement *ifStatement = new IfStatement ();
119+
ifStatement->init (reduction, parent);
118120
119121
ifStmt->addChild (getASTNode(rdcChildren[1], ifStmt));
120122
ifStmt->addChild (getASTNode(rdcChildren[3], ifStmt));
121123
ifStmt->addChild (getASTNode(rdcChildren[5], ifStmt));
122124
return ifStmt;
123-
default: return searchEquivNode( rdcChildren, parent);
124-
}
125+
}
126+
125127
126128
*/
127129

0 commit comments

Comments
 (0)