1. Give the Prolog code produced by the DCG rule:
a --> b, c. (Don’t worry about the names used for variables; you can use any names you like.)
2. Assume we have a grammar similar to the one above (i.e. a --> b, c.), however it is a complete grammar with definitions for b, c, and whatever else is needed. Write a Prolog predicate, parse_a(WordList), that succeeds when WordList is an ‘a’ phrase in the grammar, that is, when it matches whatever the “a -->” rules are, with no words left over.
3.Here’s a simple grammar for arithmetic expressions:
4. Given the following database:
Carnivores only eat meat and cheese
Vegetarians, only eat vegetables and cheese
If someone isn’t carnivore or vegetarian, they’re an omnivore and so they eat anything.
Everybody either eats a food or hates it; there’s no inbetween.
5. Given the grammar:
上面几个问题我没有翻译成中文,如果需要的话,我再翻译吧
a --> b, c. (Don’t worry about the names used for variables; you can use any names you like.)
2. Assume we have a grammar similar to the one above (i.e. a --> b, c.), however it is a complete grammar with definitions for b, c, and whatever else is needed. Write a Prolog predicate, parse_a(WordList), that succeeds when WordList is an ‘a’ phrase in the grammar, that is, when it matches whatever the “a -->” rules are, with no words left over.
3.Here’s a simple grammar for arithmetic expressions:
- 代码:
expression --> term.
expression --> term, [ '+' ], expression.
term --> factor.
term --> factor, [ '*' ], term.
factor --> [ Number ], { integer(Number) }.
4. Given the following database:
- 代码:
meat(beef).
meat(chicken).
vegetable(carrots).
vegetable(broccoli).
carnivore(john).
carnivore(mary).
vegetarian(bruce).
Carnivores only eat meat and cheese
Vegetarians, only eat vegetables and cheese
If someone isn’t carnivore or vegetarian, they’re an omnivore and so they eat anything.
Everybody either eats a food or hates it; there’s no inbetween.
5. Given the grammar:
- 代码:
assertion(LF) --> np(S), vp(S^LF).
np(john) --> [john].
np(mary) --> [mary].
np(bruce) --> [bruce].
np(jenny) --> [jenny].
np(carrots) --> [carrots].
np(broccoli) --> [broccoli].
np(chicken) --> [chicken].
np(beef) --> [beef].
np(cheese) --> [cheese].
vp(S^LF) --> v(S^O^LF), np(O).
v(S^O^eats(S, O)) --> [eats].
v(S^O^hates(S, O)) --> [hates].
上面几个问题我没有翻译成中文,如果需要的话,我再翻译吧