The hardest part of this is evaluating expressions. The usual solutions are:
A) Convert to reverse polish notation (the algorithm is not hard to find) and execute using a stack-based machine (if you have used HP calculators or programmed the 8087 FPU you'll get a good idea of how this works).
B) Write a recursive-descent parser.
C) Use a parser generator, like bison or yacc. I am sure there are newer ones, but I am a dinosaur. ;)
D) Use Boost.Spirit.
You already said you can't use D, and it sounds like C might not be acceptable either. B is a great exercise and I strongly recommend you go that route. If you try it and have trouble with it, post your attempt and I can help you fix it.
By the way, why the restriction of not using third-party libraries? Homework?
Show differencesHistory of post edits
#2Álvaro
Posted 16 December 2012 - 04:11 PM
The hardest part of this is evaluating expressions. The usual solutions are:
A) Convert to reverse polish notation (the algorithm is not hard to find) and execute using a stack-based machine (if you have used HP calculators or programmed the 8087 FPU you'll get a good idea of how this works).
B) Write a recursive-descent parser.
C) Use a stand-alone parser, like bison or yacc. I am sure there are newer ones, but I am a dinosaur. ;)
D) Use Boost.Spirit.
You already said you can't use D, and it sounds like C might not be acceptable either. B is a great exercise and I strongly recommend you go that route. If you try it and have trouble with it, post your attempt and I can help you fix it.
By the way, why the restriction of not using third-party libraries? Homework?
A) Convert to reverse polish notation (the algorithm is not hard to find) and execute using a stack-based machine (if you have used HP calculators or programmed the 8087 FPU you'll get a good idea of how this works).
B) Write a recursive-descent parser.
C) Use a stand-alone parser, like bison or yacc. I am sure there are newer ones, but I am a dinosaur. ;)
D) Use Boost.Spirit.
You already said you can't use D, and it sounds like C might not be acceptable either. B is a great exercise and I strongly recommend you go that route. If you try it and have trouble with it, post your attempt and I can help you fix it.
By the way, why the restriction of not using third-party libraries? Homework?
#1Álvaro
Posted 16 December 2012 - 04:09 PM
The hardest part of this is evaluating expressions. The usual solutions are:
A) Convert to reverse polish notation (the algorithm is not hard to find) and execute using a stack-based machine (if you have used HP calculators or programmed the 8087 FPU you'll get a good idea of how this works).
B) Write a recursive-descent parser.
C) Use a stand-alone parser, like bison or yacc. I am sure there are newer ones, but I am a dinosaur. ;)
D) Use Boost.Spirit.
It sounds like C and D are out of the question. B is a great exercise and I strongly recommend you go that route. If you try it and have trouble with it, post your attempt and I can help you fix it.
A) Convert to reverse polish notation (the algorithm is not hard to find) and execute using a stack-based machine (if you have used HP calculators or programmed the 8087 FPU you'll get a good idea of how this works).
B) Write a recursive-descent parser.
C) Use a stand-alone parser, like bison or yacc. I am sure there are newer ones, but I am a dinosaur. ;)
D) Use Boost.Spirit.
It sounds like C and D are out of the question. B is a great exercise and I strongly recommend you go that route. If you try it and have trouble with it, post your attempt and I can help you fix it.