-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now creates a parse tree off of the input
- Loading branch information
Showing
5 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,6 @@ | |
#include "ExitStatement.h" | ||
#include "PrintStatement.h" | ||
|
||
#include "Program.h" | ||
|
||
#endif /* PARSETREE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Program.cpp | ||
* | ||
* Created on: Apr 26, 2013 | ||
* Author: jimtahu | ||
*/ | ||
|
||
#include "Program.h" | ||
|
||
namespace ParseTree { | ||
|
||
Program::Program() { | ||
|
||
} | ||
|
||
void Program::add(Statement *stmt){ | ||
this->code.push_back(stmt); | ||
} | ||
|
||
void Program::run(){ | ||
for(std::vector<Statement *>::iterator i=code.begin(); i!=code.end(); i++){ | ||
(*i)->Execute(); | ||
} | ||
return; | ||
} | ||
|
||
Program::~Program() { | ||
|
||
} | ||
|
||
} /* namespace ParseTree */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Program.h | ||
* | ||
* Created on: Apr 26, 2013 | ||
* Author: jimtahu | ||
*/ | ||
|
||
#ifndef PROGRAM_H_ | ||
#define PROGRAM_H_ | ||
|
||
#include <vector> | ||
#include "Statement.h" | ||
|
||
namespace ParseTree { | ||
|
||
class Program { | ||
private: | ||
std::vector<Statement *> code; | ||
public: | ||
Program(); | ||
void add(Statement *stmt); | ||
void run(); | ||
virtual ~Program(); | ||
}; | ||
|
||
} /* namespace ParseTree */ | ||
#endif /* PROGRAM_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <sstream> | ||
#include <iostream> | ||
#include <map> | ||
|
||
#include "ParseTree.h" | ||
|
||
using namespace std; | ||
|
||
void yyerror(std::string s); | ||
int yyparse (void); | ||
|
||
|
||
/** | ||
* Converts a string into a double. | ||
* @return The double repersented by the string. | ||
* @param text The string to convert. | ||
* Uses stringstream for the conversion, so 7k.89 is 7. | ||
*/ | ||
double str2num(string text){ | ||
stringstream ss(text); | ||
double ret; | ||
ss>>ret ? ret : throw text; | ||
return ret; | ||
}//end str2num | ||
|
||
/** | ||
* Converts a double to a string. | ||
* @param val The double to convert. | ||
* @return The string repersenting the double. | ||
*/ | ||
string num2str(double val){ | ||
stringstream ss; | ||
ss<<val; | ||
return ss.str(); | ||
}//end num2str | ||
|
||
extern ParseTree::Program *theProg; | ||
|
||
int main(int argc, char *argv[]) { | ||
theProg = new ParseTree::Program(); | ||
yyparse(); | ||
theProg->run(); | ||
delete theProg; | ||
return 0; | ||
}//end main | ||
|