-
-
Save 2colours/0b6f4611360746f33ff82462ff79787e 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
#!/usr/bin/env raku | |
grammar Calculator { | |
token TOP { <calc-op> } | |
proto rule calc-op {*} | |
rule calc-op:sym<add> { <num> '+' <num> } | |
rule calc-op:sym<sub> { <num> '-' <num> } | |
token num { \d+ } | |
} | |
class Calculations { | |
method TOP ($/) { make $<calc-op>.made; } | |
proto method calc-op($/) { say 'ASD'; {*} } | |
method calc-op:sym<add> ($/) { make [+] $<num>; } | |
method calc-op:sym<sub> ($/) { make [-] $<num>; } | |
} | |
say Calculator.parse('2 + 3', actions => Calculations).made; | |
# OUTPUT: «5» |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment