rule as ambiguous and not being applied as desired

43 views
Skip to first unread message

Right_Then

unread,
Jul 28, 2014, 4:42:42 PM7/28/14
to
Dear Fellows

I am attaching a .pdf to make my question clear. please zoom it if it appears small when opened.
Basically the situation when oversimplified is this.

a: Number ;
b: Name ;

ab: a b ;
abc: ab a ;

abcCall: ab 
           |  abc ;


when input is:  1N2 and not 1N , parsed by rule abcCall ,
instead of being parsed by rule abc once it is being parsed twice
 1) by ab as a b
 2) then by abc as a

making it two separate expressions where as it should be one single expression.

Thanks
Regards

Right_Then

funAmbiguousQuestion.7z

Sam Harwell

unread,
Jul 28, 2014, 5:09:07 PM7/28/14
to antlr-di...@googlegroups.com

You didn’t include enough of your grammar to determine what is going on.

 

Can you include a complete example that demonstrates the problem, which we can build and run locally?

 

Thanks,

Sam

 

From: antlr-di...@googlegroups.com [mailto:antlr-di...@googlegroups.com]
Sent: Monday, July 28, 2014 3:43 PM
To: antlr-di...@googlegroups.com
Subject: [antlr-discussion] rule as ambiguous and not being applied as desired

 

Dear Fellows

 

I am attaching a .png to make my question clear. please zoom it if it appears small when opened.

Basically the situation when oversimplified is this.

 

a: Number ;

b: Name ;

 

ab: a b ;

abc: ab a ;

 

abcCall: ab 

           |  abc ;

 

 

when input is:  1N2 and not 1N , parsed by rule abcCall ,

instead of being parsed by rule abc once it is being parsed twice

 1) by ab as a b

 2) then by abc as c

 

making it two separate expressions where as it should be one single expression.

 

Thanks

Regards

 

Right_Then

 

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jim Idle

unread,
Jul 28, 2014, 11:01:09 PM7/28/14
to antlr-di...@googlegroups.com
Are you in charge of what this language looks like? If you are, then you should start again as what you have is going to be extremely difficult to do correctly and could anyway be done much better with something like JSON or even the relative complexity of XML. 

Your png file just points out the your language is completely ambiguous without applying context or multiple guesses. If you cannot change the language itself, then I think you are better off writing a hand crafted parser, probably with syntax directed lexing. If you really feel that you want to do this with ANTLR, then I think that you need to start again and start left factoring rather than just typing things in and hoping that ANTLR works out what you want the ambiguities to resolve as.

If you post your whole grammar, then perhaps something might stand out, but you have not provided anything to go on here grammar wise.

Jim

Right_Then

unread,
Jul 29, 2014, 7:26:16 AM7/29/14
to
Thanks Mr. Sam and Mr. Jim for the replies,

I am sorry i am replying late for my own help.
I am attaching complete grammar along with the files to test.
Please read the readmeFirst.txt file.
There is a .bat file also in the zip, double clicking it would show you GUI`s for two files to be parsed one by one.
you can read their -trace and -diagnostics output from classes directory. Files would be 
  1. parsesCorrectly_Trace1.txt
  2. parsesCorrectly_Diagnostics1.txt
  3. funSigTest_Trace1.txt
  4. funSigTest_Diagnostics1.txt
There are .html files for both code files to see them in browser with syntax highlighting.

Mr. Jim
           Yes i am incharge of this language because i am the only one developing it. Its not that i am working for some company for this,
its my hobby.  Jason and Xml are all right in their own and perhaps can be used as a language for the purpose of storing information.
But this grammar is of a general purpose language just like C++,C# etc..
And such kind of function naming is its feature. I am not at all versed with left factoring or other compiler studies.
So developing a Parser myself would be the last resort. I have waited long for Antlr 4 kind of parser generator and would want it to do parsing for me.
Please see the attachment, then i can elaborate further on your queries.

Mr. Sam
             Your 4.3.1-opt works very well for speeding things up what was taking 5-15 minutes before is only taking 45 seconds now.
I have cleared grammar of many ambiguities from before perhaps that might be assisting in faster parsing too. So thank you very much for that.

Please look for function call { Tvlr }willFlyBackIn{ bussinessClass }prefferedAirlineIs{ montiCarlo } ;
in funSigTest.andthen file where it is not getting parsed as desired. But is rightly parsed in parsesCorrectly.andthen file

Thanks
Regards

Right_Then
Question2.7z
Reply all
Reply to author
Forward
0 new messages