Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created March 13, 2014 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save practicingruby/9535940 to your computer and use it in GitHub Desktop.
Save practicingruby/9535940 to your computer and use it in GitHub Desktop.
class Parser
rule
string
| a_or_cs abb
| abb
;
a_or_cs
: a_or_cs a_or_c
| a_or_c
;
a_or_c : 'a' | 'c' ;
abb : 'a' 'b' 'b' { puts "I found abb!" };
end
---- header
# $Id$
---- inner
def next_token
@q.shift
end
def parse(text)
@q = []
text.chars.each do |c|
@q.push([c, c])
end
do_parse
rescue Racc::ParseError => e
puts e.message.strip
end
---- footer
parser = Parser.new
parser.parse(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment