This afternoon a simple four arithmetic interpreter (interpreter) was written in C #. The interpreter has two main functions: one is to be able to carry out basic arithmetic, namely subtraction; the second is to be able to detect input syntax errors, for illegal operation instructions will prompt errors and give the wrong place. In the evening I wrote this blog post to record the thought process.
Press: This is the previous encounter of a Microsoft technical interview questions, then feel more trouble, to involve the use of tree trees and other data structures, so has been kept in mind. I happened to get the legendary Dragon book this afternoon, so I tried to write it by myself.
The interpreter, which took 2 hours to write, is relatively simple and can only be arithmetic. Parentheses are not yet supported, as well as unary operators, such as the minus sign operator. Source code can be downloaded here: http://files.cnblogs.com/yinyueyouge/Arithemic.7z
The main interface for running is as follows:
The interpreter can also judge illegal input:
Now the interpreter is very primitive. If a bug is found, please indicate it and I will correct it. :)