Skip to content

Instantly share code, notes, and snippets.

@inariksit
Last active March 10, 2023 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inariksit/daf9b5c6cd374930aca6eec9d57ce3a6 to your computer and use it in GitHub Desktop.
Save inariksit/daf9b5c6cd374930aca6eec9d57ce3a6 to your computer and use it in GitHub Desktop.
abstract Worker = Numeral -- We extend the Numeral abstract syntax to get Digits
** {
flags startcat = Clause ;
cat
Kind ;
Clause ;
-- The categories Int, Float and String are present in all grammars
-- The categories Dig and Digits come from Numeral.
fun
NItemsLiteral : Int -> Kind -> Clause ;
NItemsDig : Digits -> Kind -> Clause ;
Car : Kind ;
} ;
incomplete concrete WorkerI of Worker =
-- 1) Modules that your grammar /inherits/
Numeral -- this is still the abstract version in a functor!
-- 2) Modules that your grammar /opens/
** open
Syntax, -- for CN, S, mkS, mkCl, mkNP, mkCN, mkDet, aPl_Det
Symbolic, -- for symb, mkSymb
Lexicon -- for car_N
in {
-- Marking here explicitly where the imports come from; not needed in reality
lincat
Kind = Syntax.CN ;
Clause = Syntax.S ;
lin
-- Hacky, and produces "1 cars"
NItemsLiteral int kind =
let sym : Symb = Symbolic.mkSymb int.s ; -- mkSymb : Str -> Symb ;
card : Card = Symbolic.symb sym ; -- symb : Symb -> Card ;
det : Det = Syntax.mkDet card ;
in Syntax.mkS (Syntax.mkCl (Syntax.mkNP det kind)) ;
-- Comes from the RGL, produces "1 car"
NItemsDig num kind = Syntax.mkS (Syntax.mkCl (Syntax.mkNP (Syntax.mkDet num) kind)) ;
Car = mkCN Lexicon.car_N ;
}
concrete WorkerIta of Worker =
-- 1) Modules that your grammar /inherits/
NumeralIta -- finally we can instantiate this into a concrete syntax!
**
WorkerI -- this giveas us all the definitions from the functor,
-- with the opened modules instantiated as those below
-- 2) Modules that your grammar /opens/
with
(Syntax = SyntaxIta),
(Lexicon = LexiconIta),
(Symbolic = SymbolicIta) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment