% File: b.p % grammar for a shapes micro-world % pseudo-code for semantic action added :- ['process.p']. sentence --> cmmnd. sentence --> query. sentence --> []. cmmnd --> [place], indefArticle, color, [square], [at], number, number, [with], [side], number, ['.']. /* { Add a square to the knowledge base at give (x,y) coordinates. Article may be either 'a' or 'an'; color red, blue, or green. } */ cmmnd --> [place], indefArticle, color, [rectangle], [at], number, number, [of], [height], number, [and], [width], number, ['.']. /* { Add a rectangle ... } */ cmmnd --> [place], indefArticle, color, [circle], [at], number, number, [of], [radius], number, ['.']. /* { Add a circle ... } */ cmmnd --> [stop], ['.']. query --> [what], shapes, [are], [there], ['?']. /* { enumerate the specified objects. } */ query --> [what], [color], shapes, [are], [present], ['?']. /* { respond with the colors of the specified shape. } */ query --> [are], [there], [any], color, shapes, [present], ['?']. /* { respond with yes/no } */ query --> [how], [big], [is], defArticle, shape, [at], number, number, ['?']. /* { respond with length for squares, height and width for rectangles, radius for circles } */ defArticle --> [the]. indefArticle --> [a]. indefArticle --> [an]. color --> [red]. color --> [blue]. color --> [green]. number --> [N], { number(N) }. shape --> [square]. shape --> [rectangle]. shape --> [circle]. shape --> [shape]. shapes --> [squares]. shapes --> [rectangles]. shapes --> [circles]. shapes --> [shapes].