This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
54 lines (48 loc) · 4.88 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Test cases (where the AST is very pretty! Feel free to use `:debug ast on`):
*
* 10(4)-2(4^2/4)/2/(1/2)+9 = 41
* -10/(20/2^2*5/5)*8-2 = -18
* -4--9(3-(3^3+9)) = -301
* ((-84/-7)^3--9)*-11+-11 = -19118
* ((-96/-4)^2-11)*-3+-3 = -1698
* ((90/5)^3-10)*2+2 = 11646
* ((-96/-4)^3--11)*-4+-4 = -55344
* -6--4(-5-(-5^3+-4)) = 490
* ((3!)!)!^2 = 6766339992365551114339279006945958959036295893251077848460122777324930630161276040154931162616546517344156433719635122049096969036907531380662649736254698908861530270203104467890472269195658583198477960376694951955441411557247116537966557423086941081310451405315559162640025061215688809916033970492151531514940284322825239661859499108699300117808515113360544158848068771631251602916478690391464950154895730864625540768628460025854634247992468329093546582403963590873971163225580754742491321831137257025624673371274397517196504905990224440132652790577032972156955291034447269846713025436427497370195768076846385918600238056193767564997182904559998693973873669374280053010672624364155443385621918328382432771078254817040844401472659261264178609592594139018083830873878641779784665303145798928653383699992384628885393843473356603022424672638903131112934716686664663932204874330564191534758689978188971373726425617584503300511558311724926311641436876846695855758144323468978643405990440272356969570791674506536522848770448858940351044865242690327696588906839704137532472201875960003344191806781298370587300278632006649384891840012312775410186757246143901875523866766176036771833914845544910080651065504468075142051135452421165121755747586806207045068113468789892981679679224665061625402426106359272632075068561507153391030666661964796675393051113630832923025795406755051346977010935009401168844578649634228355494136052428238206155052363188549696956428224558329365748946891847868423461975864241587327479696793910746607780438994807811767069587198450663439571878610864240434816739186476792747256621540348372428160322937534876175420148344430173570822179718748132658048472813647853667482247463905473968060181162820648960308066090102243218905734496674215896995812610443958101951845656833894385178062987338344453482954522192334360621937992776751295969384416290748510143346322917407128868918689554045813514061772011418387099730513377598910803294788344541847913447409772881476880822865874852433678516291283239977956608842805951149918735637990049166377075755802075016002631559365613857319663733769855746556026574674237103429472986628349679413503817235524056748643945074944841762969355146868201120991165430852177772217203056740733070790540489520758508785890579546574899101082768062937939510457775384652225761338876159153077649115303192692839422641198309945471469970767539856961287966713213765624178011755715846801068890953227743676121704729369996418322504364032526025816127096000541936616393274521873604089362836131108175823734821650287309892041316880213141629746476674280657829785433707983789573136635746963164402621465555185099013220206032634312098123490462722629487258052291036830972749009927471187146132935300573102859216451711438080542440111865994379000639872839827794161134641627615283838344722192408914034989408649511499848043251131832509594292278866770215851973815410065975106106216768685055860309983828662039120940351495779603420389921754615047759886960617570537071859695006956536056330311878216667313496400633771350906437665518308992653454465649794412425028261835393301367582708880720333964573478785403819066921300903061011285378399037135257600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
*
* There are intentionally no spaces to test just how much of a beating the
* tokenizer can take when it comes to figuring out which operators are unary
* and which are binary. It evaluates these just fine, but feel free to try to
* break it!
*
* Source for the first two:
* https://www.basic-mathematics.com/hard-order-of-operations-problems.html
*
* Source for everything else (except for the last one):
* http://www.math-aids.com/cgi/pdf_viewer_7.cgi?script_name=OoO_adv.pl&skill=1&type=4&parity=2&language=0&memo=&answer=1&x=110&y=40
*
* Source for the last one: this very calculator, and WolframAlpha
*/
#define LD_USE_TERMCOLOR
#define LD_USE_LINENOISE
#include "boilerplate/ld_boilerplate.hpp"
#include "RationalCalculator.cpp"
#include "CalcInputLoop.hpp"
/**
* Main function, executed when the program starts.
*/
int main() {
/**
* Welcome the user
*/
LD::log(L"Welcome to my calculator!\nType :help for help.\n");
/**
* The calculator, used for storing state between inputs
*/
RationalCalculator calc;
/**
* Just start the input loop
*/
input_loop(calc);
}