Writing a simple sentence parser in lex/yacc
Clay Luther
cluther at ponder.csci.unt.edu
Thu May 23 09:18:52 AEST 1991
Hello All:
I recently found a need to learn and use lex/yacc. I have purchased the
nutshell book, but I find it somewhat lacking. I don't know if it's me or
what. Anyway, I though I would turn to here for some advice.
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
word :== [a-zA-Z]+
It should parse as follows:
throw ball
- verb = throw, verb object = ball
throw ball with "blue stripes"
- verb throw, vo ball, prep with, po "blue stripes"
throw blue ball with white stripes
- v throw, vo blue ball, p with, po white stripes
I cannot seem to create a yacc/lex definition for this. Any help is *greatly*
appreciated.
Thanks.
--
Clay Luther Lonely C++ Programmer
cluther at ponder.csci.unt.edu
cluther at solo.csci.unt.edu I work here now and they still
cluther at supernet.haus.com don't let me have any opinions.
More information about the Comp.unix.wizards
mailing list