-
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.
specify c++17, and fix a bug that we don't have to put expression in …
…statements
- Loading branch information
Showing
4 changed files
with
77 additions
and
53 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
57 changes: 36 additions & 21 deletions
57
abstract_interpreter/example/abstract_interpreter/parser.cpp
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 |
---|---|---|
@@ -1,30 +1,45 @@ | ||
#include <fstream> | ||
#include <sstream> | ||
|
||
#include "../../include/parser.hpp" | ||
#include "../../include/ast.hpp" | ||
|
||
|
||
int main(){ | ||
std::string input = R"( | ||
int x, y ; | ||
int x = 4; | ||
int y = 3; | ||
x = 2 * (y - 10); | ||
if (x == 10) { | ||
if (y == 10){ | ||
y = 3; | ||
x = 5; | ||
} | ||
} | ||
while(x != 0){ | ||
int z = 10; | ||
// std::string input = R"( | ||
// int x, y ; | ||
// int x = 4; | ||
// int y = 3; | ||
// x = 2 * (y - 10); | ||
// if (x == 10) { | ||
// if (y == 10){ | ||
// y = 3; | ||
// x = 5; | ||
// } | ||
// } | ||
// while(x != 0){ | ||
// int z = 10; | ||
// } | ||
// )"; | ||
for (int i = 0; i < 1; ++i){ | ||
std::string filename = (i < 10 ? "0" : "") + std::to_string(i); // Add "0" prefix if i < 10 | ||
std::ifstream f("./tests/" + filename + ".c"); | ||
if (!f.is_open()){ | ||
std::cerr << "[ERROR] file cannot open!" << std::endl; | ||
return -1; | ||
} | ||
)"; | ||
|
||
AbstractInterpreterParser AIParser; | ||
auto ast = AIParser.parse(input); | ||
printAST(ast); | ||
// AIParser.parse("-1+(1+2)*3- -1"); | ||
|
||
|
||
// std::cout << "Result: " << root->evaluate() << std::endl; | ||
std::ostringstream buffer; | ||
buffer << f.rdbuf(); | ||
std::string input = buffer.str(); | ||
f.close(); | ||
|
||
std::cout << "Program content:\n" << input << std::endl; | ||
|
||
AbstractInterpreterParser AIParser; | ||
auto ast = AIParser.parse(input); | ||
printAST(ast); | ||
} | ||
|
||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,22 +1,14 @@ | ||
/*******************************************************************/ | ||
/* Cas d'etudes pour le projet du cours d'interpratation abstraite */ | ||
/* Ecrit par Olivier Bouissou ([email protected]) */ | ||
/* Le but de ces cas d'etudes est de vous permettre de tester */ | ||
/* votre projet sur des exemples de programmes contenant chacun */ | ||
/* une difficulte que vous devriez rencontrer. */ | ||
/*******************************************************************/ | ||
/* Caclul arithmetique 1. */ | ||
/* On cherche ici a tester les fonctions arithmetiques des domaines */ | ||
/* abstraits. */ | ||
/*******************************************************************/ | ||
|
||
|
||
int a, b, c, d, e, f; | ||
|
||
void main() { | ||
void main () { | ||
|
||
a = 23; | ||
b = 5; | ||
|
||
if (a == 1) b = 4; | ||
|
||
c = a + b; | ||
d = a + c; | ||
e = d + c + f; | ||
|