cjheath / treetop

A Ruby-based parsing DSL based on parsing expression grammars.
https://cjheath.github.io/treetop
MIT License
306 stars 22 forks source link

Bug with context-sensitive grammar #42

Closed stereobooster closed 3 years ago

stereobooster commented 3 years ago

I took example from Ford's original paper:

A ← aAb/ε
B ← bBc/ε
S ← &(A!b)a∗ B!.

And it seems doesn't work as expected:

grammar ContextSensetive
  rule s
    &(a !'b') 'a'* b
  end

  rule a
    'a' a 'b' / ''
  end

  rule b
    'b' b 'c' / ''
  end
end
require 'rubygems'
require 'treetop'
Treetop.load 'context_sensetive'

parser = ContextSensetiveParser.new
p !parser.parse('aabbcc').nil?  # correct: true
p !parser.parse('aabbccc').nil? # correct: false
p !parser.parse('aaabbcc').nil? # incorrect: true
cjheath commented 3 years ago

The Treetop mailing list is used for support: treetop-dev@googlegroups.com

Your implementation does not detect EOF - the original uses !.

stereobooster commented 3 years ago

Your implementation does not detect EOF - the original uses !.

Yes I know. I wasn't sure how end of file denoted in Treetop

grammar ContextSensetive
  rule s
    &(a !'b') 'a'* b !.
  end

  rule a
    'a' a 'b' / ''
  end

  rule b
    'b' b 'c' / ''
  end
end

this code produces the same error

cjheath commented 3 years ago

Your questions will be answered only if you ask the on the mailing list, not in a github issue. Not really sure if I can find another way to say that :)

stereobooster commented 3 years ago

Case closed. I found paper which shows, that this is indeed an issue in PEG. And it can't handle this grammar the way Ford described https://arxiv.org/pdf/1801.10490.pdf