Jump to content

Arithmetic Evaluator/Go: Difference between revisions

m
Both examples work with Go 1. Library example needed a small tweak to match the API.
(Alternative solution using library functions)
m (Both examples work with Go 1. Library example needed a small tweak to match the API.)
Line 1:
__TOC__
=Operator precedence parser=
{{works with|gc|2010-04-27}}
 
This is an operator precedence parser. The number format used in calculation can be changed with the line "type Number int".
 
Line 287 ⟶ 285:
 
func parseAndEval(exp string) (int, error) {
fstree, err := tokenparser.NewFileSetParseExpr(exp)
tree, err := parser.ParseExpr(fs, "", exp)
if err != nil {
return 0, err
1,707

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.