Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
Last active October 18, 2016 10:14
Show Gist options
  • Save DmitrySoshnikov/1c43c52e97a4374b027da73d2d09cb48 to your computer and use it in GitHub Desktop.
Save DmitrySoshnikov/1c43c52e97a4374b027da73d2d09cb48 to your computer and use it in GitHub Desktop.
using-calc-parser.php
<?php
require('CalcParser.php');
var_dump(CalcParser::parse('2 + 2 * 2'));
/*
Result:
string(36) "Custom hook on parse begin. Parsing:"
string(9) "2 + 2 * 2"
string(33) "Custom hook on parse end. Parsed:"
object(BinaryExpression)#8 (4) {
["type"]=>
string(6) "Binary"
["left"]=>
object(PrimaryExpression)#4 (2) {
["type"]=>
string(7) "Primary"
["value"]=>
int(2)
}
["right"]=>
object(BinaryExpression)#7 (4) {
["type"]=>
string(6) "Binary"
["left"]=>
object(PrimaryExpression)#5 (2) {
["type"]=>
string(7) "Primary"
["value"]=>
int(2)
}
["right"]=>
object(PrimaryExpression)#6 (2) {
["type"]=>
string(7) "Primary"
["value"]=>
int(2)
}
["op"]=>
string(1) "*"
}
["op"]=>
string(1) "+"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment