Created
December 27, 2019 21:38
-
-
Save russ/40223aa58a1ffc48f0038c7bf3b1a742 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
token whitespace = /[ \n\t]+/ [ skip ]; | |
token true = /true/; | |
token false = /false/; | |
token and = /and/; | |
token or = /or/; | |
rule S = expr; | |
rule expr = tkn | expr and tkn | expr or tkn; | |
rule tkn = true | false; |
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
type boolean = $$ Bool $$ | |
typerules boolean = [ S, expr, tkn ] | |
init = $$ $$ | |
rule expr(0) = $$ $out = $0 $$ | |
rule expr(1) = $$ $out = $0 & $2 $$ | |
rule expr(2) = $$ $out = $0 | $2 $$ | |
rule tkn(0) = $$ $out = true $$ | |
rule tkn(1) = $$ $out = false $$ |
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/bash | |
pegasus < bool.grammar > bool.json | |
pegasus-crystalsem -l bool.json -a bool.sem -s bool.cr | |
crystal test.cr |
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
require "./bool.cr" | |
puts Pegasus::Generated.process("true or false or true").inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment