Context-free grammars, in the tagless-final style
Documentation
Syntactic categories: non-terminals of CFG
class Symantics repr whereSource
This class defines the syntax of our fragment (the grammar,
essentially). Its instances will show interpretations
of the grammar, or semantics
The names r1, r2, etc. are the labels of CFG rules. These names are evocative of Montague
show the inferred types, as well as the inferred types for the phrases like
The first sample sentence, or CFG derivation The inferred type is S. So, sen1 is a derivations of a complete sentence.
We now define the first interpretation of a CFG derivations: We interpret the derivation to give the parsed string. That is, we generate a yield of a CFG derivation, in English.
We represent each node in the derivation tree by an English phrase
Symantics EN | |
Quantifier EN | Sample sentences (or, CFG derivations) We stress that the inferred type of sen2-sen4 is S. So, these are the derivations of complete sentences. We extend our EN interpreter (interpreter of derivations as English phrases) to deal with QNP. |
Pronoun EN | |
Quantifier EN | Sample sentences (or, CFG derivations): compare with those in QCFG.hs We stress that the inferred type of sen2-sen4 is S. So, these are the derivations of complete sentences. We extend our EN interpreter (interpreter of derivations as English phrases) to deal with quantifiers. |
Show (EN a) |
Show the English form of sen1
We now define semantics of a phrase represented by a derivation. It is a different interpretation of the phrase and its types.
We first interpret syntactic types (NP, VP, etc) in terms of the types of the language of logic formulas. The type class Lambda defines the language of logic formulas (STT, or higher-order logic) with types Entity, Bool, and the arrows.
Lambda lrepr => Symantics (Sem lrepr) | |
Lambda lrepr => Quantifier (Sem lrepr) | |
Dynamics lrepr => Pronoun (Sem lrepr) | |
Lambda lrepr => Quantifier (Sem lrepr) | We can now see the English sentences that correspond to the derivations sen2-sen4. We also extend the semantics interpreter: the interpreter of a derivation into a formula of STT, or Lambda-calculus. We reconstruct Montague's ``pronoun trick'' |
Show (Sem (P C) a) | |
Show (Sem C a) | |
Show (Sem (D (P C)) S) | |
Show (Sem (D C) S) |