-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw2test.ml
29 lines (22 loc) · 1014 Bytes
/
hw2test.ml
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
let accept_all string = Some string
type my_nonterminals =
|Paragraph | Sentence | NPhrase | VPhrase | Noun | Verb | Adj | Adv
let my_grammar =
(Paragraph,
function
| Paragraph -> [(*[N Paragraph; N Sentence];*)[N Sentence];]
| Sentence -> [[N NPhrase ; N VPhrase; N NPhrase; T "."]]
| NPhrase -> [[N Noun]; [N Adj; N Noun]]
| VPhrase -> [[N Verb]; [N Adv; N Verb]]
| Noun -> [[T"I"];[T"you"];[T"Chocolate"];[T"coding"]]
| Verb -> [[T"kick"];[T"drink"];[T"eat"];[T"twist"]]
| Adj -> [[T"good"];[T"bad"];[T"perfect"];[T"mediocre"]]
| Adv -> [[T"meh"];[T"forcefully"];[T"delightly"];[T"smoothly"]]
)
let make_matcher_test =
((make_matcher my_grammar accept_all ["I"; "kick"; "coding"; "."; "good"; "chocolate"; "twist"; "you"; "."]) = Some ["good"; "chocolate";"twist"; "you"; "."])
let parser_frag = ["I";"twist";"coding"; "."]
let make_parser_test =
match make_parser my_grammar parser_frag with
| Some tree -> parse_tree_leaves tree = parser_frag
| _ -> false