parsing and evaluating simple language using javacc

天大地大妈咪最大 提交于 2019-12-05 22:44:42

You can do this by letting JavaCC create an AST for you 1, and then creating custom nodes while you walk the tree. Once your tree is constructed, you invoke the root node's eval(...) method to evaluate the entire expression/tree.

A demo of how to evaluate simple expressions with JavaCC + JJTree: http://www.cs.nmsu.edu/~rth/cs/cs471/InterpretersJavaCC.html

A more extensive example, including functions: https://github.com/bkiers/Curta


1https://javacc.java.net/doc/JJTree.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!