-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grammar.ne
97 lines (71 loc) · 3.84 KB
/
Grammar.ne
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
## This is a grammar for Shrdlite, written for the Nearley Javascript chartparser
## To compile into a TypeScript file: nearleyc Grammar.ne > Grammar.ts
## More information about Nearley: https://github.com/Hardmath123/nearley
## Note that for simplicity this grammar does not recognise uppcase, whitespace or punctuation.
## This means that it has to be called with a contracted lowercase string, i.e.,
## the string "Take the blue ball!" is not recognised, but instead "taketheblueball"
@preprocessor typescript
@{%
import {
Command, TakeCommand, DropCommand, MoveCommand, WhereisCommand,
Location, Entity,
Object, RelativeObject, SimpleObject,
} from "./Types";
%}
## Grammar rules
main --> will_you:? please:? command please:? {% (d) => d[2] %}
command --> take entity {% (d) => new TakeCommand(d[1]) %}
command --> move it location {% (d) => new DropCommand(d[2]) %}
command --> move entity location {% (d) => new MoveCommand(d[1], d[2]) %}
# command --> where_is entity {% (d) => new WhereisCommand(d[1], d[2]) %}
location --> relation entity {% (d) => new Location(d[0], d[1]) %}
entity --> quantifierSG simpleObjectSG {% (d) => new Entity(d[0], d[1]) %}
entity --> quantifierSG relativeObjectSG {% (d) => new Entity(d[0], d[1]) %}
entity --> quantifierPL simpleObjectPL {% (d) => new Entity(d[0], d[1]) %}
entity --> quantifierPL relativeObjectPL {% (d) => new Entity(d[0], d[1]) %}
relativeObjectSG --> simpleObjectSG that_is:? location {% (d) => new RelativeObject(d[0], d[2]) %}
relativeObjectPL --> simpleObjectPL that_are:? location {% (d) => new RelativeObject(d[0], d[2]) %}
simpleObjectSG --> size:? color:? formSG {% (d) => new SimpleObject(d[0], d[1], d[2]) %}
simpleObjectPL --> size:? color:? formPL {% (d) => new SimpleObject(d[0], d[1], d[2]) %}
## Lexical rules
quantifierSG --> ("any" | "an" | "a") {% (d) => "any" %}
quantifierSG --> ("the") {% (d) => "the" %}
quantifierSG --> ("every") {% (d) => "all" %}
quantifierPL --> ("all") {% (d) => "all" %}
relation --> ("left" "of" | "to" "the" "left" "of") {% (d) => "leftof" %}
relation --> ("right" "of" | "to" "the" "right" "of") {% (d) => "rightof" %}
relation --> ("inside" | "in" | "into") {% (d) => "inside" %}
relation --> ("on" | "on" "top" "of") {% (d) => "ontop" %}
relation --> ("under" | "below") {% (d) => "under" %}
relation --> ("beside") {% (d) => "beside" %}
relation --> ("above") {% (d) => "above" %}
relation --> ("behind" | "in" "back" "of" | "to" "the" "back" "of") {% (d) => "behind" %}
relation --> ("before" | "in" "front" "of" | "to" "the" "front" "of") {% (d) => "before" %}
size --> ("small" | "tiny") {% (d) => "small" %}
size --> ("large" | "big") {% (d) => "large" %}
color --> "black" {% (d) => "black" %}
color --> "white" {% (d) => "white" %}
color --> "blue" {% (d) => "blue" %}
color --> "green" {% (d) => "green" %}
color --> "yellow" {% (d) => "yellow" %}
color --> "red" {% (d) => "red" %}
formSG --> form {% (d) => d[0] %}
formPL --> form "s" {% (d) => d[0] %}
formSG --> "box" {% (d) => "box" %}
formPL --> "boxes" {% (d) => "box" %}
form --> ("object" | "thing" | "form") {% (d) => "anyform" %}
form --> "brick" {% (d) => "brick" %}
form --> "plank" {% (d) => "plank" %}
form --> "ball" {% (d) => "ball" %}
form --> "pyramid" {% (d) => "pyramid" %}
form --> "table" {% (d) => "table" %}
form --> "cup" {% (d) => "cup" %}
form --> "floor" {% (d) => "floor" %}
## Lexicon (without semantic content)
take --> "take" | "grasp" | "pick" "up"
move --> "move" | "put" | "drop"
it --> "it"
that_is --> "that" "is"
that_are --> "that" "are"
will_you --> ("will" | "can" | "could") "you"
please --> "please"