问题
is there a dart lib that can parse math strings such as (3+4)/4.5
?
I tried to build a basic parser with petitparser, but I am in over my head and its just trial and error right now :) Is there an petitparser (Dart or any other language) implementation of a simple math parser somewhere?
回答1:
The introductory tutorial of PetitParser for Dart explains building a simple expression grammar in the section "Writing a More Complicated Grammar".
There is a more complicated expression grammar in the test suite of PetitParser for Dart, that can help you get started.
The Smalltalk implementation of PetitParser has even more examples. Also it includes a factory object that helps you building expression grammars. Unfortunately this code hasn't been ported yet.
Update: As of version 1.1.0 PetitParser includes a factory for building expression grammars.
来源:https://stackoverflow.com/questions/18924498/is-there-a-math-parser-for-petitparser