Dana-Ferguson / dumb_parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This is a dumb parser. The opposite of what a parser should be, but it was a lot of fun to build! 😊

Consider using petiteparser instead.

var calculator = new Calculator();
calculator.addFunction('sin', (arg) => math.sin(arg));
calculator.addFunction('pi', (arg) => math.pi * arg);

var text = 'sin(pi(1/2))*2**1**2';

print(calculator.parse(text).evaluate());

Calculator is a pre-written parser included in this library. Check it out for an example of how to use this.

var parser = new Parser(symbolRules, tokenRules, transformRules);

The parsers are just collections of pattern matching rules.

  1. Symbol Rules match characters to Symbols
  2. Token Rules match Symbols to Tokens (Symbols and Tokens are interchangeable)
  3. Transform Rules turn Tokens into a result

(1) and (2) happen in parse() and (3) happens in evaluate().

About

License:MIT License


Languages

Language:Dart 100.0%