The following grammar returns a ParseErrorResult (unexpected token "_End_") when you try to parse "hello foo"
========= BEGIN CODE ========
require 'dhaka'
require 'pp'
class LexerSpec < Dhaka::LexerSpecification
%w(hello foo bar).each{|v| for_pattern(v){ create_token(v) } }
for_pattern('\s+'){ }
end
class Gram < Dhaka::Grammar
for_symbol(Dhaka::START_SYMBOL_NAME){ start_1(%w| hello Foo OptionBar |) } # change "Foo" to "foo" or "OptionBar" to "Option"and this grammar successfully parses "hello foo"
for_symbol('Foo'){ foo_1(%w| foo |) }
for_symbol('OptionalBar'){ bar_t(%w| Option |) }
for_symbol('Option') do
option_exists %w| Bar |
option_does_not_exist %w| |
end
for_symbol('Bar'){ bar_1(%w| bar |) }
end
pp Dhaka::Parser.new(Gram).parse(Dhaka::Lexer.new(LexerSpec).lex("hello foo"))
========= END CODE ========
However, I have verified this grammar should parse successfully:
1. Go to http://smlweb.cpsc.ucalgary.ca/start.html.
2. Enter the following into the text field:
Start -> hello Foo OptionBar.
Foo -> foo.
OptionBar -> Option.
Option -> Bar
|.
Bar -> bar.
3. Click "View Vital Statistics"
4. Click "check to see if certain sentences are in the language"
5. Type "hello foo" and press enter
Is this a bug? Or have I mis-specified the grammar? I tried experimenting with Dhaka::END_SYMBOL_NAME without luck. Any help would be welcome. Thanks!
-Ben
|