Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!bsg!pg From: pg@bsg.com (Peter Garst) Newsgroups: comp.unix.wizards Subject: Re: Writing a simple sentence parser in lex/yacc Message-ID: <1991May23.181335.4159@bsg.com> Date: 23 May 91 18:13:35 GMT References: Sender: Peter Garst (pg@bsg.com) Organization: Bloomsbury Software Group Lines: 38 In article cluther@ponder.csci.unt.edu (Clay Luther) writes: >I need to create a sentence parser. Right now, it only needs to be very >simple. Here is a sketchy grammer for the language. > >sentences :== sentences sentence >sentence :== verbphrase prepphrase >verbphrase :== verb | verb object >prepphrase :== prep object | EMPTY >verb :== word >prep :== "with" | "in" | "on" | "about" >object :== word | words | string >string :== "\"" words "\"" >words :== words word | word The main problem I see with your grammar is that it is VERY ambiguous. Consider the following input - word word word word word This could be interpreted as five sentences; it could be a verb with four words in the object; or it could be many other things. You might try specifying which words are nouns, which are verbs and so on - that is, verb :== "throw" | "eat" | ... noun :== "ball" | "burger" | ... This is very simple minded, but parsing English in any realistic sense is an extremely complex task. In particular, if you look only at syntax English really is highly ambiguous. Peter Garst pg@bsg.com P.S. - Your job will be far easier if you use a good yacc grammar development tool like ydb (my company's product); in a case like this it could have pointed out the ambiguities and the alternate interpretations right away.