I have been assigned with a coding homework in CPP where I'm supposed to create a Matrix calculator. This would be an ok-ish task considering all I need to do is matrix calculations, use polymorphism, consider memory consumption, and some more criteria. What I'm struggling with is that is should be a console like environment.
Meaning start the app and I'm in a prompt where I type commands like:
scan x[3][3] \n // this creates new matrix labeled 'x' and waits for 9 ints ( longs possibly ) to by typed.
z = add xy \n // or
z = x + y \n
I am familiar with automata theory ( to some degree ) and making it this simple shouldn't be a problem. ( that practically has nothing to do with automata ) Simple meaning one command per line - because that's what I'm doing now. I have some parser class that breaks down the command, and than I do the necessary changes. Its more of a if-else tree going from first word to the last. If I encounter unrecognized word - Grammar/Syntax error.
What I'm asking is some tips on how to make it more.. bash like, for instance.
Since the app is run in bash..
FIRST Q: how do i achieve a history of typed commands? rn when i push arrowup i get those ^[[A.
SECOND Q: Some hints how start parsing some more complicated commands like: a = b = c * ( d + q ) ( implying that 'c' can multiply "(d + q)" and 'd' is addable to 'q' etc.. ) bcs that cant be done with the static way my parser works rn.
Thank you all.
For your first question, look at libreadline
or libeditline
. If you do not want to lift a finger, run your program under the rlwrap
wrapper.
For your second question, look at Simple library or implementation for a mathematical expression evaluator . Look for one that allows you to define and use variables.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.