rupesh4514 / grammatical-framework

Automatically exported from code.google.com/p/grammatical-framework
0 stars 0 forks source link

"," in context-free rules causes parsing failure #41

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Import a .cf file containing

S ::= "S" ; 
S ::= "if" S OptionalComma S ; 
OptionalComma ::= "," ; 
OptionalComma ::= ; 

2. Run 
   p "if S , S"

What is the expected output? 

A parse tree.

What do you see instead?

no trees found; unknown words: , 

What version of the product are you using? On what operating system?

v. 3.1.6 under Windows

Please provide any additional information below.

"if S S" parses fine under this grammar.   But if I switch the order 
of the two rules involving 'OptionalComma', "if S , S" parses but "if 
S S" breaks. Replacing the "," with "c" means that both variants 
parse. If I name the four rules above everything works fine. 

[My guess is that the automatically generated rule names for

OptionalComma ::= "," ; 
OptionalComma ::= ; 

are colliding, or something close to that.]

Original issue reported on code.google.com by moh...@gmail.com on 29 Sep 2010 at 3:24

GoogleCodeExporter commented 9 years ago
Further to this, try:

---Grammar---

S ::= "IFR" IFR ;
IFR ::= "=" ;
IFR ::= "<" ;

---Output---

testAbs> p -cat=IFR "="
no trees found; unknown words: =

------------

Again, naming rules makes this go away. Similarly, removing the "<" rule makes 
the problem go away.

Original comment by moh...@gmail.com on 29 Sep 2010 at 4:19

GoogleCodeExporter commented 9 years ago
The CF parser in GF.Grammar.CF assigns function names to the rules, but they 
are not always unique, causing rules to be dropped in the following CF->GF
conversion. So a pass has been added before the CF->GF conversion, to make
sure that function names are unique.

Original comment by hallg...@chalmers.se on 11 Nov 2013 at 5:05