From fe9fd23ac2d0de0ba965d7bd63569e0fa618bea5 Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Thu, 18 Mar 2021 21:37:18 +0100 Subject: [PATCH] Improve the flowchart translator and add history API. (#15) --- src/input_output_test.cpp | 2 + test/Flowchart/doloop/output | 5 ++- test/Flowchart/example/output | 38 +++++++++++++++++- test/Flowchart/if-returned-0/output | 25 ++++++------ test/Flowchart/if-returned-1/output | 25 ++++++------ test/Flowchart/if-returned-2/output | 25 ++++++------ test/Flowchart/if-returned-3/output | 25 ++++++------ test/Flowchart/if-returned-4/output | 25 ++++++------ test/Flowchart/if-returned-5/output | 25 ++++++------ test/Flowchart/if-returned-6/output | 23 ++++++----- test/Flowchart/if-returned-7/output | 21 +++++----- test/Flowchart/if_1/output | 7 +++- test/Flowchart/if_1_brace/output | 7 +++- test/Flowchart/if_2/output | 9 ++++- test/Flowchart/if_3/output | 11 +++++- test/Flowchart/if_with_space_condition/output | 7 +++- test/Flowchart/whileloop/output | 5 ++- .../xkcd-do-you-understand-flowchart-2/output | 15 ++++++- .../output | 15 ++++++- .../xkcd-do-you-understand-flowchart/output | 39 ++++++++++++++++++- .../xkcd-local-computer-expert/output | 12 +++++- 21 files changed, 257 insertions(+), 109 deletions(-) diff --git a/src/input_output_test.cpp b/src/input_output_test.cpp index 9e9b844..53a6736 100644 --- a/src/input_output_test.cpp +++ b/src/input_output_test.cpp @@ -73,6 +73,8 @@ int main(int, const char**) { std::cout << output << std::endl; std::cout << "---------------------" << std::endl; result = EXIT_FAILURE; + + //std::ofstream(test.path() / "output") << output_computed; } } } diff --git a/test/Flowchart/doloop/output b/test/Flowchart/doloop/output index 1274c43..dbeb46e 100644 --- a/test/Flowchart/doloop/output +++ b/test/Flowchart/doloop/output @@ -1,2 +1,3 @@ -while("arthur") - "chocolat" +┌─────────────┐ +│Unimplemented│ +└─────────────┘ diff --git a/test/Flowchart/example/output b/test/Flowchart/example/output index 1274c43..88216b7 100644 --- a/test/Flowchart/example/output +++ b/test/Flowchart/example/output @@ -1,2 +1,36 @@ -while("arthur") - "chocolat" + ┌─────┐ + │start│ + └──┬──┘ + __________▽__________ + ╱ ╲ ┌──────────────┐ +╱ ╲________________________________________________________________________________________│Very expensive│ +╲ Does it cost > 1000 ? ╱yes └──────────────┘ + ╲_____________________╱ + │no + _________▽_________ ___________________ + ╱ ╲ ╱ ╲ ┌──────────────┐ + ╱ ╲__________________ ╱ ╲_______________________________│Very expensive│ + ╲ Does it cost > 100? ╱yes ╲ Does it cost > 0.5? ╱yes └──────────────┘ + ╲___________________╱ ╲___________________╱ + │no │no + ________▽_________ _________▽_________ + ╱ ╲ ┌───────┐ ╱ ╲ ┌─────────┐ + ╱ ╲_________│Correct│ ╱ ╲____________________│expensive│ + ╲ Does it cost > 10? ╱yes └───────┘ ╲ Does it cost > 0.1? ╱yes └─────────┘ + ╲__________________╱ ╲___________________╱ + │no │no + ________▽________ _________▽__________ + ╱ ╲ ┌─────┐ ╱ ╲ ┌───────┐ + ╱ ╲___│Cheap│ ╱ ╲__________│Correct│ + ╲ Does it cost > 1? ╱yes└─────┘ ╲ Does it cost > 0.01? ╱yes └───────┘ + ╲_________________╱ ╲____________________╱ + │no │no + ┌───▽──┐ __________▽__________ + │coucou│ ╱ ╲ ┌─────┐ + └──────┘ ╱ ╲___│Cheap│ + ╲ Does it cost > 0.001? ╱yes└─────┘ + ╲_____________________╱ + │no + ┌──────▽──────┐ + │Take my money│ + └─────────────┘ diff --git a/test/Flowchart/if-returned-0/output b/test/Flowchart/if-returned-0/output index f404ea3..e25e233 100644 --- a/test/Flowchart/if-returned-0/output +++ b/test/Flowchart/if-returned-0/output @@ -1,11 +1,14 @@ - ┌─┐ ┌─┐ ┌─┐ - │a│─>│b│─>│c│ - └┬┘ └┬┘ └┬┘ - ┌▽┐ ┌▽┐ │ - │e│ │d│ │ - └┬┘ └┬┘ │ - │ └─┬──┘ - └──┬───┘ - ┌▽┐ - │f│ - └─┘ + ___ ___ + ╱ ╲ ╱ ╲ ┌─┐ +╱ ╲___╱ ╲___│c│ +╲ a ╱yes╲ b ╱yes└┬┘ + ╲___╱ ╲___╱ │ + │no │no │ + ┌▽┐ ┌▽┐ │ + │e│ │d│ │ + └┬┘ └┬┘ │ + │ └───┬───┘ + └──────┬──────┘ + ┌▽┐ + │f│ + └─┘ diff --git a/test/Flowchart/if-returned-1/output b/test/Flowchart/if-returned-1/output index 7f86892..9558b9b 100644 --- a/test/Flowchart/if-returned-1/output +++ b/test/Flowchart/if-returned-1/output @@ -1,11 +1,14 @@ - ┌─┐ ┌─┐ ┌─┐ - │a│─>│b│─>│c│ - └┬┘ └┬┘ └─┘ - ┌▽┐ ┌▽┐ - │e│ │d│ - └┬┘ └┬┘ - │ │ - └─┬──┘ - ┌▽┐ - │f│ - └─┘ + ___ ___ + ╱ ╲ ╱ ╲ ┌─┐ +╱ ╲___╱ ╲___│c│ +╲ a ╱yes╲ b ╱yes└─┘ + ╲___╱ ╲___╱ + │no │no + ┌▽┐ ┌▽┐ + │e│ │d│ + └┬┘ └┬┘ + │ │ + └────┬────┘ + ┌▽┐ + │f│ + └─┘ diff --git a/test/Flowchart/if-returned-2/output b/test/Flowchart/if-returned-2/output index 224526c..b3ed917 100644 --- a/test/Flowchart/if-returned-2/output +++ b/test/Flowchart/if-returned-2/output @@ -1,11 +1,14 @@ - ┌─┐ ┌─┐ ┌─┐ - │a│─>│b│─>│c│ - └┬┘ └┬┘ └┬┘ - ┌▽┐ ┌▽┐ │ - │e│ │d│ │ - └┬┘ └─┘ │ - │ │ - └────┬────┘ - ┌▽┐ - │f│ - └─┘ + ___ ___ + ╱ ╲ ╱ ╲ ┌─┐ +╱ ╲___╱ ╲___│c│ +╲ a ╱yes╲ b ╱yes└┬┘ + ╲___╱ ╲___╱ │ + │no │no │ + ┌▽┐ ┌▽┐ │ + │e│ │d│ │ + └┬┘ └─┘ │ + │ │ + └────────┬────────┘ + ┌▽┐ + │f│ + └─┘ diff --git a/test/Flowchart/if-returned-3/output b/test/Flowchart/if-returned-3/output index 478308f..bc993a6 100644 --- a/test/Flowchart/if-returned-3/output +++ b/test/Flowchart/if-returned-3/output @@ -1,11 +1,14 @@ - ┌─┐ ┌─┐ ┌─┐ - │a│─>│b│─>│c│ - └┬┘ └┬┘ └┬┘ - ┌▽┐ ┌▽┐ │ - │e│ │d│ │ - └─┘ └┬┘ │ - └─┬──┘ - │ - ┌▽┐ - │f│ - └─┘ + ___ ___ + ╱ ╲ ╱ ╲ ┌─┐ +╱ ╲___╱ ╲___│c│ +╲ a ╱yes╲ b ╱yes└┬┘ + ╲___╱ ╲___╱ │ + │no │no │ + ┌▽┐ ┌▽┐ │ + │e│ │d│ │ + └─┘ └┬┘ │ + └───┬───┘ + │ + ┌▽┐ + │f│ + └─┘ diff --git a/test/Flowchart/if-returned-4/output b/test/Flowchart/if-returned-4/output index f09abd5..741f53a 100644 --- a/test/Flowchart/if-returned-4/output +++ b/test/Flowchart/if-returned-4/output @@ -1,11 +1,14 @@ - ┌─┐ ┌─┐ ┌─┐ - │a│─>│b│─>│c│ - └┬┘ └┬┘ └─┘ - ┌▽┐ ┌▽┐ - │e│ │d│ - └─┘ └┬┘ - │ - │ - ┌▽┐ - │f│ - └─┘ + ___ ___ + ╱ ╲ ╱ ╲ ┌─┐ +╱ ╲___╱ ╲___│c│ +╲ a ╱yes╲ b ╱yes└─┘ + ╲___╱ ╲___╱ + │no │no + ┌▽┐ ┌▽┐ + │e│ │d│ + └─┘ └┬┘ + │ + │ + ┌▽┐ + │f│ + └─┘ diff --git a/test/Flowchart/if-returned-5/output b/test/Flowchart/if-returned-5/output index 5513467..34deee1 100644 --- a/test/Flowchart/if-returned-5/output +++ b/test/Flowchart/if-returned-5/output @@ -1,11 +1,14 @@ - ┌─┐ ┌─┐ ┌─┐ - │a│─>│b│─>│c│ - └┬┘ └┬┘ └┬┘ - ┌▽┐ ┌▽┐ │ - │e│ │d│ │ - └─┘ └─┘ │ - │ - │ - ┌▽┐ - │f│ - └─┘ + ___ ___ + ╱ ╲ ╱ ╲ ┌─┐ +╱ ╲___╱ ╲___│c│ +╲ a ╱yes╲ b ╱yes└┬┘ + ╲___╱ ╲___╱ │ + │no │no │ + ┌▽┐ ┌▽┐ │ + │e│ │d│ │ + └─┘ └─┘ │ + │ + │ + ┌▽┐ + │f│ + └─┘ diff --git a/test/Flowchart/if-returned-6/output b/test/Flowchart/if-returned-6/output index 7d7d2cc..09d7aad 100644 --- a/test/Flowchart/if-returned-6/output +++ b/test/Flowchart/if-returned-6/output @@ -1,10 +1,13 @@ - ┌─┐ ┌─┐ ┌─┐ - │a│─>│b│─>│c│ - └┬┘ └┬┘ └─┘ - ┌▽┐ ┌▽┐ - │e│ │d│ - └┬┘ └─┘ - │ - ┌▽┐ - │f│ - └─┘ + ___ ___ + ╱ ╲ ╱ ╲ ┌─┐ +╱ ╲___╱ ╲___│c│ +╲ a ╱yes╲ b ╱yes└─┘ + ╲___╱ ╲___╱ + │no │no + ┌▽┐ ┌▽┐ + │e│ │d│ + └┬┘ └─┘ + │ + ┌▽┐ + │f│ + └─┘ diff --git a/test/Flowchart/if-returned-7/output b/test/Flowchart/if-returned-7/output index 101df4a..32d2259 100644 --- a/test/Flowchart/if-returned-7/output +++ b/test/Flowchart/if-returned-7/output @@ -1,9 +1,12 @@ - ┌─┐ ┌─┐ ┌─┐ - │a│─>│b│─>│c│ - └┬┘ └┬┘ └─┘ - ┌▽┐ ┌▽┐ - │e│ │d│ - └─┘ └─┘ - ┌─┐ - │f│ - └─┘ + ___ ___ + ╱ ╲ ╱ ╲ ┌─┐ +╱ ╲___╱ ╲___│c│ +╲ a ╱yes╲ b ╱yes└─┘ + ╲___╱ ╲___╱ + │no │no + ┌▽┐ ┌▽┐ + │e│ │d│ + └─┘ └─┘ +┌─┐ +│f│ +└─┘ diff --git a/test/Flowchart/if_1/output b/test/Flowchart/if_1/output index 404b26f..9b71fe4 100644 --- a/test/Flowchart/if_1/output +++ b/test/Flowchart/if_1/output @@ -1,2 +1,5 @@ -┌┬┐ -└┴┘ + ___ + ╱ ╲ ┌─┐ +╱ ╲│b│ +╲ a ╱└─┘ + ╲___╱ diff --git a/test/Flowchart/if_1_brace/output b/test/Flowchart/if_1_brace/output index 404b26f..9b71fe4 100644 --- a/test/Flowchart/if_1_brace/output +++ b/test/Flowchart/if_1_brace/output @@ -1,2 +1,5 @@ -┌┬┐ -└┴┘ + ___ + ╱ ╲ ┌─┐ +╱ ╲│b│ +╲ a ╱└─┘ + ╲___╱ diff --git a/test/Flowchart/if_2/output b/test/Flowchart/if_2/output index 404b26f..7da7683 100644 --- a/test/Flowchart/if_2/output +++ b/test/Flowchart/if_2/output @@ -1,2 +1,7 @@ -┌┬┐ -└┴┘ + ___ + ╱ ╲ ┌─┐ +╱ ╲│b│ +╲ a ╱└┬┘ + ╲___╱ ┌▽┐ + │c│ + └─┘ diff --git a/test/Flowchart/if_3/output b/test/Flowchart/if_3/output index 404b26f..0601022 100644 --- a/test/Flowchart/if_3/output +++ b/test/Flowchart/if_3/output @@ -1,2 +1,9 @@ -┌┬┐ -└┴┘ + ___ + ╱ ╲ ┌─┐ +╱ ╲│b│ +╲ a ╱└┬┘ + ╲_│_╱ │ + ├────┘ + ┌▽┐ + │c│ + └─┘ diff --git a/test/Flowchart/if_with_space_condition/output b/test/Flowchart/if_with_space_condition/output index 404b26f..30b5612 100644 --- a/test/Flowchart/if_with_space_condition/output +++ b/test/Flowchart/if_with_space_condition/output @@ -1,2 +1,5 @@ -┌┬┐ -└┴┘ + ___ + ╱ ╲ ┌───┐ +╱ ╲│c d│ +╲ a b ╱└───┘ + ╲___╱ diff --git a/test/Flowchart/whileloop/output b/test/Flowchart/whileloop/output index 1274c43..dbeb46e 100644 --- a/test/Flowchart/whileloop/output +++ b/test/Flowchart/whileloop/output @@ -1,2 +1,3 @@ -while("arthur") - "chocolat" +┌─────────────┐ +│Unimplemented│ +└─────────────┘ diff --git a/test/Flowchart/xkcd-do-you-understand-flowchart-2/output b/test/Flowchart/xkcd-do-you-understand-flowchart-2/output index 1274c43..1fd0044 100644 --- a/test/Flowchart/xkcd-do-you-understand-flowchart-2/output +++ b/test/Flowchart/xkcd-do-you-understand-flowchart-2/output @@ -1,2 +1,13 @@ -while("arthur") - "chocolat" + ┌─────────────┐ + │Unimplemented│ + └──────┬──────┘ + ┌───────▽──────┐ + │LET'S GO DRING│ + └───────┬──────┘ + ┌────▽───┐ + │6 DRINKS│ + └────┬───┘ +┌─────────▽─────────┐ +│HEY, I SHOULD TRY │ +│INSTALLING FREEBSD!│ +└───────────────────┘ diff --git a/test/Flowchart/xkcd-do-you-understand-flowchart-switch/output b/test/Flowchart/xkcd-do-you-understand-flowchart-switch/output index 1274c43..1fd0044 100644 --- a/test/Flowchart/xkcd-do-you-understand-flowchart-switch/output +++ b/test/Flowchart/xkcd-do-you-understand-flowchart-switch/output @@ -1,2 +1,13 @@ -while("arthur") - "chocolat" + ┌─────────────┐ + │Unimplemented│ + └──────┬──────┘ + ┌───────▽──────┐ + │LET'S GO DRING│ + └───────┬──────┘ + ┌────▽───┐ + │6 DRINKS│ + └────┬───┘ +┌─────────▽─────────┐ +│HEY, I SHOULD TRY │ +│INSTALLING FREEBSD!│ +└───────────────────┘ diff --git a/test/Flowchart/xkcd-do-you-understand-flowchart/output b/test/Flowchart/xkcd-do-you-understand-flowchart/output index 1274c43..b2e1538 100644 --- a/test/Flowchart/xkcd-do-you-understand-flowchart/output +++ b/test/Flowchart/xkcd-do-you-understand-flowchart/output @@ -1,2 +1,37 @@ -while("arthur") - "chocolat" + _________________ + ╱ ╲ ┌─────┐ + ╱ DO YOU UNDERSTAND ╲____________________________________________________│GOOD!│ + ╲ FLOW CHARTS? ╱yes └──┬──┘ + ╲_________________╱ │ + │no │ + _________▽_________ ______________________ │ + ╱ ╲ ╱ ╲ ┌────┐ │ +╱ OKAY, YOU SEE THE ╲________________╱ ... AND YOU CAN SEE ╲___│GOOD│ │ +╲ LINE LABELED "YES"? ╱yes ╲ THE ONES LABELED "NO"? ╱yes└──┬─┘ │ + ╲___________________╱ ╲______________________╱ │ │ + │no │no │ │ + ________▽_________ _________▽__________ │ │ + ╱ ╲ ┌───────────┐ ╱ ╲ │ │ + ╱ BUT YOU SEE THE ╲___│WAIT, WHAT?│ ╱ BUT YOU JUST ╲___ │ │ + ╲ ONES LABELED "NO"? ╱yes└───────────┘ ╲ FOLLOWED THEM TWICE? ╱yes│ │ │ + ╲__________________╱ ╲____________________╱ │ │ │ + │no │no │ │ │ + ┌───▽───┐ │ │ │ │ + │LISTEN.│ └───────┬───────┘ │ │ + └───┬───┘ ┌──────▽─────┐ │ │ + ┌─────▽────┐ │(THAT WASN'T│ │ │ + │I HATE YOU│ │A QUESTION) │ │ │ + └──────────┘ └──────┬─────┘ │ │ + ┌────▽───┐ │ │ + │SCREW IT│ │ │ + └────┬───┘ │ │ + └─────┬─────┘ │ + │ │ + └─────┬─────┘ + ┌───────▽──────┐ + │LET'S GO DRING│ + └───────┬──────┘ + ┌─────────▽─────────┐ + │HEY, I SHOULD TRY │ + │INSTALLING FREEBSD!│ + └───────────────────┘ diff --git a/test/Flowchart/xkcd-local-computer-expert/output b/test/Flowchart/xkcd-local-computer-expert/output index 1274c43..63111a3 100644 --- a/test/Flowchart/xkcd-local-computer-expert/output +++ b/test/Flowchart/xkcd-local-computer-expert/output @@ -1,2 +1,10 @@ -while("arthur") - "chocolat" + ┌─────┐ + │START│ + └──┬──┘ + ┌──────▽──────┐ + │Unimplemented│ + └──────┬──────┘ +┌────────▽───────┐ +│ASK SOMEONE FOR │ +│HELP OR GIVE UP.│ +└────────────────┘