From andersen at ontologyworks.com Tue May 29 12:30:51 2007 From: andersen at ontologyworks.com (Bill Andersen) Date: Tue, 29 May 2007 13:30:51 -0400 Subject: [KIF] CLIF grammar ambiguity Message-ID: <5BF44FAA-F2AE-469D-9604-D4D0A5768750@ontologyworks.com> Folks, Just for fun I was using ANTLR 3 to build a CLIF grammar (yeah I know others have done this, but i wanted to learn ANTLR again an v3 in particular). ANTLR identifies the following rules as ambiguous. cltext : phrase* ; phrase : sentence | module | ( '(' CL_IMPORTS interpretable_name ')' ) | ( '(' CL_COMMENT QUOTED_STRING cltext? ')' ) ; The ambiguity is this phrase ( cl:comment quoted_string ) or phrase ( cl:comment quoted_string cltext ) The question is whether the presence of the cltext takes priority (i.e. empty cl text is assumed to be there in this case) Bill Andersen (andersen at ontologyworks.com) Chief Scientist Ontology Works, Inc. (www.ontologyworks.com) 3600 O'Donnell Street, Suite 600 Baltimore, MD 21224 Office: 410-675-1201 Cell: 443-858-6444 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://philebus.tamu.edu/pipermail/kif/attachments/20070529/815e9b42/attachment.htm From rschulz at sonic.net Tue May 29 12:44:12 2007 From: rschulz at sonic.net (Randall R Schulz) Date: Tue, 29 May 2007 10:44:12 -0700 Subject: [KIF] CLIF grammar ambiguity In-Reply-To: <5BF44FAA-F2AE-469D-9604-D4D0A5768750@ontologyworks.com> References: <5BF44FAA-F2AE-469D-9604-D4D0A5768750@ontologyworks.com> Message-ID: <200705291044.12779.rschulz@sonic.net> Bill, On Tuesday 29 May 2007 10:30, Bill Andersen wrote: > Folks, > > ... ANTLR identifies the following rules as ambiguous. > > cltext > : phrase* > ; > > phrase > : sentence | module | > ( '(' CL_IMPORTS interpretable_name ')' ) | > ( '(' CL_COMMENT QUOTED_STRING cltext? ')' ) > ; > > The ambiguity is this > > phrase > ( > cl:comment > quoted_string > ) > > or > > phrase > ( > cl:comment > quoted_string > cltext > ) > > The question is whether the presence of the cltext takes priority > (i.e. empty cl text is assumed to be there in this case) I'm not entirely certain where the ambiguity it detects arises, but it may have something to do with the fact that "cltext" may derive nothing at all, since its only right-hand-side is an unbounded closure. Hence, the zero-or-one closure ('?') on "cltext" in the fourth right-hand-side derivation of "phrase" is redundant. You could try removing it. > Bill Andersen (andersen at ontologyworks.com) Randall Schulz From andersen at ontologyworks.com Tue May 29 12:48:22 2007 From: andersen at ontologyworks.com (Bill Andersen) Date: Tue, 29 May 2007 13:48:22 -0400 Subject: [KIF] CLIF grammar ambiguity In-Reply-To: <200705291044.12779.rschulz@sonic.net> References: <5BF44FAA-F2AE-469D-9604-D4D0A5768750@ontologyworks.com> <200705291044.12779.rschulz@sonic.net> Message-ID: On May 29, 2007, at 13:44 , Randall R Schulz wrote: > Bill, > > On Tuesday 29 May 2007 10:30, Bill Andersen wrote: >> Folks, >> >> ... ANTLR identifies the following rules as ambiguous. >> >> cltext >> : phrase* >> ; >> >> phrase >> : sentence | module | >> ( '(' CL_IMPORTS interpretable_name ')' ) | >> ( '(' CL_COMMENT QUOTED_STRING cltext? ')' ) >> ; >> >> The ambiguity is this >> >> phrase >> ( >> cl:comment >> quoted_string >> ) >> >> or >> >> phrase >> ( >> cl:comment >> quoted_string >> cltext >> ) >> >> The question is whether the presence of the cltext takes priority >> (i.e. empty cl text is assumed to be there in this case) > > I'm not entirely certain where the ambiguity it detects arises, but it > may have something to do with the fact that "cltext" may derive > nothing > at all, since its only right-hand-side is an unbounded closure. Hence, > the zero-or-one closure ('?') on "cltext" in the fourth right-hand- > side > derivation of "phrase" is redundant. You could try removing it. Randall. That's right. But if you remove it then ( cl:comment "foo" (foo a b) ) is not recognized as a phrase, and it should be From rschulz at sonic.net Tue May 29 12:53:32 2007 From: rschulz at sonic.net (Randall R Schulz) Date: Tue, 29 May 2007 10:53:32 -0700 Subject: [KIF] CLIF grammar ambiguity In-Reply-To: References: <5BF44FAA-F2AE-469D-9604-D4D0A5768750@ontologyworks.com> <200705291044.12779.rschulz@sonic.net> Message-ID: <200705291053.32127.rschulz@sonic.net> On Tuesday 29 May 2007 10:48, Bill Andersen wrote: > On May 29, 2007, at 13:44 , Randall R Schulz wrote: > > Bill, > > > > ... > > > > I'm not entirely certain where the ambiguity it detects arises, but > > it may have something to do with the fact that "cltext" may derive > > nothing at all, since its only right-hand-side is an unbounded > > closure. Hence, the zero-or-one closure ('?') on "cltext" in the > > fourth right-hand- side derivation of "phrase" is redundant. You > > could try removing it. > > Randall. That's right. But if you remove it then > > ( cl:comment "foo" (foo a b) ) > > is not recognized as a phrase, and it should be That doesn't make sense to me. I didn't mean remove the "cltext?" from the 4th alternative for "phrase," I meant remove the ? from that derivation. Then it will always derive a cltext, even if it's one that derives zero "phrase"-es. Randall Schulz