-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar2_cnf.txt
executable file
·187 lines (150 loc) · 4.08 KB
/
grammar2_cnf.txt
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Symbols in the grammar are case-sensitive.
#
# This grammar uses a convention that
# - terminals are lowercase (president)
# - preterminals are capitalized (Noun)
# - other nonterminals are all-caps (NP)
#
# This convention just makes grammars more readable to humans. Thus:
#
# - When *you* are writing grammars, you should
# follow this convention unless you have a good reason not to.
#
# - But the *program* should still work with grammars that don't
# follow this convention. So how can the program reliably tell
# the difference between terminal and nonterminal symbols? If
# there is at least one rule for rewriting a symbol, then that
# symbol is a nonterminal and should be rewritten.
#######################
# Rules for creating full sentences.
1 ROOT S Punctuation
1 ROOT ISITTRUETHATS Question # mixing terminals and nonterminals is ok.
# The basic grammar rules. Here's what the abbreviations stand for:
# S = sentence
# NP = noun phrase
# VP = verb phrase
# PP = prepositional phrase
# Det = determiner (sometimes called "article")
# Prep = preposition
# Adj = adjective
1 S NP VP
1 VP Verb NP
1 NP Det Noun
1 NP NP PP
1 PP Prep NP
1 Noun Adj Noun
1 Noun Noun Noun
1 Noun CHIEF_OF Staff
1 CHIEF_OF Chief Of
1 ISITTRUETHATS ISITTRUETHAT S
1 ISITTRUETHAT ISIT TRUETHAT
1 ISIT Is It
1 TRUETHAT True That
# Q3:
1 S NP VP2 # (yuval) (is nice) (h)
1 S Name VP2 # (yuval) (ate a sandwithc) (h)
1 S Name VP # (yuval) (ate a sandwithc) (h)
1 S NP VP2_p # (yuval) (is nice)
1 VP2 Verb2_s Adj # is(singular) nice
1 VP2_p Verb2_p Adj # are(plural) nice
1 VP2 Verb2_s VP_4 # is(singular) eating a dog (i)
1 VP2_p Verb2_p VP_4 # are(plural) eating a dog
1 NP NP2 Conj2_t # A and B -> are
1 NP Name Conj2_t # A and B -> are
1 Conj2_t Conj NP2
1 NP2 Det Noun
1 NP2 Det Name
1 S Pronoun VP3_1 # (e) it.. that..
1 VP3_1 VP_3 THAT_1 # () ,()
1 THAT_1 That NP # (),(that ___ )
1 VP_3 Verb NP2 # (ate the dog),()
1 VP_3 Verb3 NP2 # (ate the dog),()
1 NP NP Verb # the dog ate
1 NP NP Verb3 # the dog ate
# sentence b
1 VP VP Conj_t
1 VP Verb Conj_t
1 Conj_t Conj VP
# sentence c
1 S NP Verb3 # the president sighed .
# sentence d
1 Verb thought
1 VP Verb THAT_1
# sentence e
1 VP Verb Noun
1 THAT_1 That S
1 Verb perplexed
1 NP Pronoun Verb
# sentence f
1 Adverb Adverb Adverb
1 Adj Adverb Adj
1 VP Det VP
# sentence g
1 Verb worked
1 Noun proposal
1 Noun desk
1 S NP PP
# sentence h
1 Adj lazy
# sentence h
1 VP2 Verb2_s NP # the president thought that sally is a sandwich
1 Noun Adj_1 Noun # (f)
1 Adj_1 Adverb_1 Adj #
1 Adverb_1 Adverb_1 Adverb # loop
#2 Adverb_1 Adverb # end
# 1 VP Verb NP_on # (g)
1 NP_on Prep Det_1 # on the ...
1 Det_1 NP2 NP_on # on the (loop)
#3 Det_1 NP2 # on the (stop)
1 VP_4 Verb_pp NP # eating.. (the dog) (i)
# Vocabulary. Your program can see that "ate" is a terminal
# symbol because there exists no rule for rewriting it.
# Any symbol that can rewrite as a terminal (or a string of
# terminals, like "chief of staff") is called a "preterminal." Notice
# that a preterminal is a special kind of nonterminal.
1 Verb ate
1 Verb wanted
1 Verb kissed
1 Verb understood
1 Verb pickled
1 Verb_pp eating
1 Verb_pp drinking
1 Det the
1 Det a
1 Det every
1 Noun president
1 Noun sandwich
1 Noun pickle
# 1 Noun chief of staff
1 Noun floor
1 Adj fine
1 Adj delicious
1 Adj perplexed
1 Adj pickled
1 Prep with
1 Prep on
1 Prep under
1 Prep in
1 Is is
1 It it
1 True true
1 That that
1 Question ?
1 Punctuation !
1 Punctuation .
1 Chief chief
1 Of of
1 Staff staff
# Q3:
1 Name Rick
1 Name Morty
1 Name Sally
1 Verb2_s is
1 Verb2_p are
1 Verb3 sighed
1 Verb3 pondered
1 Conj and
1 Conj or
1 Pronoun it
1 Adverb very
# 1 Adverb only