From 2df4cb38ee1bb534b98156e1278b346e17a6cd19 Mon Sep 17 00:00:00 2001 From: Aarne Ranta Date: Wed, 10 Apr 2024 12:04:35 +0200 Subject: [PATCH] intro grammars from the lecture --- lab2/intro/Intro.gf | 35 ++++++++++++++++++++++++++++++++++ lab2/intro/IntroEng.gf | 39 ++++++++++++++++++++++++++++++++++++++ lab2/intro/IntroFre.gf | 43 ++++++++++++++++++++++++++++++++++++++++++ lab2/intro/english.cf | 37 ++++++++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 lab2/intro/Intro.gf create mode 100644 lab2/intro/IntroEng.gf create mode 100644 lab2/intro/IntroFre.gf create mode 100644 lab2/intro/english.cf diff --git a/lab2/intro/Intro.gf b/lab2/intro/Intro.gf new file mode 100644 index 0000000..4933642 --- /dev/null +++ b/lab2/intro/Intro.gf @@ -0,0 +1,35 @@ +abstract Intro = { + +cat + S ; + NP ; + VP ; + CN ; + Det ; + Pron ; + Subj ; + N ; + A ; + V2 ; + Adv ; + +fun + PredVP : NP -> VP -> S ; + AdvS : S -> Adv -> S ; + ComplV2 : V2 -> NP -> VP ; + DetCN : Det -> CN -> NP ; + UsePron : Pron -> NP ; + AdjCN : A -> CN -> CN ; + UseN : N -> CN ; + SubjS : Subj -> S -> Adv ; + + the_Det : Det ; + we_Pron : Pron ; + because_Subj : Subj ; + + cat_N : N ; + black_A : A ; + see_V2 : V2 ; + now_Adv : Adv ; + +} diff --git a/lab2/intro/IntroEng.gf b/lab2/intro/IntroEng.gf new file mode 100644 index 0000000..bef3881 --- /dev/null +++ b/lab2/intro/IntroEng.gf @@ -0,0 +1,39 @@ +concrete IntroEng of Intro = { + +lincat + S = Str ; + NP = {s : Case => Str ; a : Agr} ; + VP = Agr => Str ; + CN = Str ; + Det = Str ; + Pron = {s : Case => Str ; a : Agr} ; + Subj = Str ; + N = Str ; + A = Str ; + V2 = Agr => Str ; + Adv = Str ; + +lin + PredVP np vp = np.s ! Nom ++ vp ! np.a ; + AdvS s adv = s ++ adv ; + ComplV2 v2 np = table {a => v2 ! a ++ np.s ! Acc} ; + DetCN det cn = {s = table {_ => det ++ cn} ; a = SgP3} ; + UsePron pron = pron ; + AdjCN a cn = a ++ cn ; + UseN n = n ; + SubjS subj s = subj ++ s ; + + the_Det = "the" ; + we_Pron = {s = table {Nom => "we" ; Acc => "us"} ; a = Other} ; + because_Subj = "because" ; + + cat_N = "cat" ; + black_A = "black" ; + see_V2 = table {SgP3 => "sees" ; Other => "see"} ; + now_Adv = "now" ; + +param + Case = Nom | Acc ; + Agr = SgP3 | Other ; + +} diff --git a/lab2/intro/IntroFre.gf b/lab2/intro/IntroFre.gf new file mode 100644 index 0000000..a6f02a5 --- /dev/null +++ b/lab2/intro/IntroFre.gf @@ -0,0 +1,43 @@ +concrete IntroFre of Intro = { + +lincat + S = Str ; + NP = {s : Case => Str ; a : Agr ; t : NPType} ; + VP = Agr => Str ; + CN = Str ; + Det = Str ; + Pron = {s : Case => Str ; a : Agr} ; + Subj = Str ; + N = Str ; + A = Str ; + V2 = Agr => Str ; + Adv = Str ; + +lin + PredVP np vp = np.s ! Nom ++ vp ! np.a ; + AdvS s adv = s ++ adv ; + ComplV2 v2 np = case np.t of { + NPPron => table {a => np.s ! Acc ++ v2 ! a} ; + NPOther => table {a => v2 ! a ++ np.s ! Acc} + } ; + DetCN det cn = {s = table {_ => det ++ cn} ; a = SgP3 ; t = NPOther} ; + UsePron pron = pron ** {t = NPPron} ; + AdjCN a cn = cn ++ a ; + UseN n = n ; + SubjS subj s = subj ++ s ; + + the_Det = "le" ; + we_Pron = {s = table {Nom => "nous" ; Acc => "nous"} ; a = Other} ; + because_Subj = "parce que" ; + + cat_N = "chat" ; + black_A = "noir" ; + see_V2 = table {SgP3 => "voit" ; Other => "voyons"} ; + now_Adv = "maintenant" ; + +param + Case = Nom | Acc ; + Agr = SgP3 | Other ; + NPType = NPPron | NPOther ; + +} diff --git a/lab2/intro/english.cf b/lab2/intro/english.cf new file mode 100644 index 0000000..6268a22 --- /dev/null +++ b/lab2/intro/english.cf @@ -0,0 +1,37 @@ +-- a tiny context-free grammar for English +-- subcategories with _ in them are an unscalable hack + +-- combination rules + +S ::= NP_subj_3 VP_3 | NP_subj VP | S Adv ; + +VP ::= V2 NP_obj ; +VP_3 ::= V2_3 NP_obj ; + +NP_subj_3 ::= Det CN | Pron_subj_3 ; +NP_subj ::= Pron_subj ; +NP_obj ::= Det CN | Pron_obj ; + +CN ::= A N ; + +Adv ::= Subj S ; + +-- structural words + +Det ::= "the" ; + +Pron_subj ::= "we" ; +Pron_obj ::= "us" ; + +Subj ::= "because" ; + +-- content words + +N ::= "cat" ; +A ::= "black" ; +V2_3 ::= "sees" ; +V2 ::= "see" ; +Adv ::= "now" ; + + +