Skip to content

Commit

Permalink
Added exit statement
Browse files Browse the repository at this point in the history
  • Loading branch information
jimtahu committed Apr 27, 2013
1 parent 2c8ab85 commit a4ad682
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ExitStatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ ExitStatement::ExitStatement() {

}

void ExitStatement::Execute(){
throw new ExitCondition();
}

ExitStatement::~ExitStatement() {
// TODO Auto-generated destructor stub
}
Expand Down
5 changes: 5 additions & 0 deletions ExitStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@

namespace ParseTree {

class ExitCondition {

};

class ExitStatement: public ParseTree::Statement {
public:
ExitStatement();
void Execute();
virtual ~ExitStatement();
};

Expand Down
8 changes: 6 additions & 2 deletions Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ extern ParseTree::Program *theProg;

int main(int argc, char *argv[]) {
theProg = new ParseTree::Program();
yyparse();
theProg->run();
try{
yyparse();
theProg->run();
}catch(ParseTree::ExitCondition *ex){
cout<<"Program terminated"<<endl;
}
delete theProg;
return 0;
}//end main
Expand Down

0 comments on commit a4ad682

Please sign in to comment.