Last active
June 14, 2017 10:56
-
-
Save grondilu/8353432388ad8e0da44ff8bc78daca50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://en.wikipedia.org/wiki/Parsing_expression_grammar | |
grammar Arithmetic { | |
rule TOP { ^^ <Exp> $$ } | |
rule Exp { <Sum> } | |
rule Sum { <Product>+ % <[+-]> } | |
rule Product { <Value>+ % <[*/]> } | |
rule Value { <ident>+ | '('<Exp>')' } | |
} | |
say Arithmetic.parse($_) for | |
'a', | |
'a+b', | |
'a*b', | |
'(a-b)*(a+b)', | |
; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment