Giter VIP home page Giter VIP logo

php-shunting-yard's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

php-shunting-yard's Issues

Handling errors

Hi there:
I'm trying to catch error to prevent php to stop if there's no parseable string, but I can't figure out how to do it ...
I've tried many options:
catch (RR\Shunt\Exception\RuntimeError | RR\Shunt\Exception\ParseError $e)
catch (ParseError $e)
catch (Exception $e)
...
but no luck ...

Any idea ? ;-)

Percentages

I'm looking to enhance the parser allowing the % symbol, not as MOD, but a percentage of the previous number.

I like how Google handles this:
5 + 25% becomes 5 + (5 * 25 / 100)
5 * 25% becomes 5 * 25 / 100

To avoid collision with the "mod" operator, that has two numbers (one in the left and one in the right) , I thought about pre-parsing the string:

		$string_m = preg_replace("/\s/", "", $term);
		preg_match("/([0-9]*)([^0-9])([0-9]*)\%([^0-9])/", $string_m . " ", $m);
		if (isSet($m[2])) { // Operand + or *
			if ($m[2] == "+") {
				$string = str_replace($m[3]."%", "(".$m[1]."*".$m[3]."/100)", $string_m);
			}
			if ($m[2] == "*") {
				$string = str_replace($m[3]."%", $m[3]."/100", $string_m);
			}
		}

With this:
12 + 150 * 15% + 3 becomes 12 + 150 * 15/100 + 3
12 + 150 + 15% + 3 becomes 12 + 150 + (150*15/100) + 3

So then the Parser can continue with no problems ;-)

Would you like to include in your parser ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.