Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How common is stack machine use in C++ code?

I'm looking at some C++ code and it includes a stack machine for scripting. I learnt C++ years ago, but never used it in my day job, so I don't have any real idea if this is common practice, or is it only used under certain very specific circumstances?

like image 875
T9b Avatar asked Aug 31 '26 16:08

T9b


1 Answers

If you need to evaluate expressions such as 2 + 3 * 7 or x = a + b / sin(c), then a stack oriented approach will work quite well.

I wouldn't say it's overly common. I know that Emacs being built around a lisp interpreter, which in turn is typically implemented as a stack-machine, I'm not sure I know of anything that uses this approach. But that's not to say that in SOME areas this isn't in common use.

Looking/thinking about it I also think that Java VM is essentially a stack machine, as is PostScript (and by extension PDF interpreters, since the concept is based on a simplified PostScript format).

like image 54
Mats Petersson Avatar answered Sep 02 '26 07:09

Mats Petersson