Last active
February 25, 2019 08:12
-
-
Save Tom-Alexander/96a300202d068717dc90da555eb2cf53 to your computer and use it in GitHub Desktop.
Recursive descent parser
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
# Recursive descent parser | |
# http://adayinthepit.com/2011/07/19/hanging-in-the-treetops/ | |
def exp(stack) | |
token = stack.shift | |
return stack if token =~ /[0-9]/ || token =~ /X/ && exp(stack) || token =~ /Y|Z/ && exp(stack) && exp(stack) | |
false | |
end | |
def parse(source) | |
stack = exp(source.split('')) | |
stack && stack.size == 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment