Skip to content

Instantly share code, notes, and snippets.

@Tom-Alexander
Last active February 25, 2019 08:12
Show Gist options
  • Save Tom-Alexander/96a300202d068717dc90da555eb2cf53 to your computer and use it in GitHub Desktop.
Save Tom-Alexander/96a300202d068717dc90da555eb2cf53 to your computer and use it in GitHub Desktop.
Recursive descent parser
# 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