Writing a simple sentence parser in lex/yacc
Peter Garst
pg at bsg.com
Fri May 24 04:13:35 AEST 1991
In article <cluther.674954332 at ponder> cluther at 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 at 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.
More information about the Comp.unix.wizards
mailing list