You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parsing: texts parsed as conjunctions of sentences (CSwFP/9.5, 9.7) #57
CSwFP treats the full stop between two sentences as a sentence conjunction. In 9.5 the lexicon has the entry lexicon "." = [Cat "." "CONJ" [] []] ("Note that we treat period (full stop) as sentence conjunction"), and preproc drops only the full stop at the end of the input. In 9.7 the rule TXT → S CONJ TXT (prsTXT) then parses Alice smiled. Dorothy laughed. as one right-branching tree, the same as Alice smiled and Dorothy laughed (see also exercise 9.12, on texts being right-branching).
The author finds this odd: parsing should work sentence by sentence, never combining sentences into one tree.
For now the 9.5 port follows CSwFP, and the terse cue in Parsing/Lexicon.lean says what the full stop does.
Things to weigh before changing it:
A text could be split into sentences by the lexer, then parsed one sentence at a time, giving a list of trees instead of a TXT tree.
CSwFP's later chapters consume TXT trees. In the DRT chapter, dintTXT (DRAC.hs) interprets Branch (Cat "_" "TXT" _ _) [s, cnj, txt], and cross-sentence anaphora (A man walked. He smiled.) needs the sentences of a text processed in sequence. A list of sentence trees could be folded over instead, but that changes the interface those chapters expect.
Exercise 9.12 (still TODO in Decide where the remaining CSwFP exercises go #53) is built on the TXT rule. It notes that texts are right-branching, TXT → S CONJ TXT, so S and S and S is parsed as [S CONJ [S CONJ [S]]], and asks the reader to predict what happens if the rule is made left-branching, TXT → TXT CONJ S, then make the change and check. The expected answer is that the parser loops: the rule becomes left-recursive, and the recursive-descent parsers of 9.3 call TXT again without consuming any input. If texts are parsed sentence by sentence, with no TXT tree, the exercise loses the rule it is about. It can then be dropped without leaving a gap, because left recursion is already presented in 9.3 (leftRec in Parsing/Combinators.lean).
Decision: the grammar is a grammar of sentences, not of texts. The full stop is no longer a CONJ.
What changes:
9.5: the lexicon drops the entry for ".". lexer and preproc take one sentence and do no segmentation. The prose says this: splitting a text into sentences is the job of some outer segmentation step, which the book does not define. A full stop inside the input is then an unknown word, and the input does not parse.
and stays a CONJ, and conjR / prsTXT stay for coordinating sentences with and. The rule cannot move into prsS as S → S CONJ S: it would be left-recursive, and the parser would loop. That is why CSwFP keeps TXT apart from S.
Exercise 9.12 keeps its rule, since it is about and-coordination (S and S and S) and the right vs. left branching of TXT. This corrects the last point above: the exercise no longer needs to be dropped.
9.8: no change. CSwFP leaves the semantics of texts and sentence conjunction to chapter 12.
Chapter 12 (DRAC), when it is ported: dintTXT is unchanged for the TXT nodes built from and. A discourse of several sentences (A man walked. He smiled.) becomes a list of sentence trees, given by the outer segmentation, and is interpreted by folding the dynamic conj over the list, from the transition that leaves the context as it is (fun c => [c]). Dynamic conjunction is associative, so the meaning is the same as with CSwFP's right-branching TXT tree. Open points for that chapter: how readings combine when several sentences are ambiguous (the product of the parses of each sentence, e.g. with List.mapM, if that is already presented by then), and where questions (prsYN, prsWH) may occur in a discourse.
S is the start symbol, for sentence (sentença). The grammar has no nonterminal of its own for a clause (oração): it reuses S. CSwFP already labels conditionals (cond1R, cond2R) as S, so coordination gets the same label. The terminology is introduced in a terse cue at the start of Parsing/ParseTrees.lean, which already uses the rule S → S and S as its example.
When 9.7 is ported:
conjR builds Branch (Cat "_" "S" [] []) [s, conj, s'], i.e. the rule S → S CONJ S, still right-branching. It does not loop: the parser of the coordination starts with the parser of a simple clause (prsS), not with itself. Recursion on the left depends on which parser is called first, not on the label of the node.
Exercise 9.12 is stated over S instead of TXT.
In chapter 12, dintTXT matches a coordination by the label S with three daughters, and tells it from a conditional by the middle daughter (CONJ vs. the COND first daughter).
Done for 9.5 in #62: the full stop has no lexicon entry, lexer takes one sentence, and keeps CONJ and joins clauses, and the terms sentença, oração and sintagma (with S reused for clauses) are introduced in Parsing/ParseTrees.lean. Recorded in DEVIATIONS.md.
What is left belongs to the 9.7 port and is tracked in #49: the rule S → S CONJ S in place of TXT, exercise 9.12 over S, and the DEVIATIONS.md entry for 9.7. #62 closes this issue when merged.
Activity
arademaker commentedon Nov 18, 2026
Decision: the grammar is a grammar of sentences, not of texts. The full stop is no longer a
CONJ.What changes:
".".lexerandpreproctake one sentence and do no segmentation. The prose says this: splitting a text into sentences is the job of some outer segmentation step, which the book does not define. A full stop inside the input is then an unknown word, and the input does not parse.andstays aCONJ, andconjR/prsTXTstay for coordinating sentences withand. The rule cannot move intoprsSasS → S CONJ S: it would be left-recursive, and the parser would loop. That is why CSwFP keepsTXTapart fromS.and-coordination (S and S and S) and the right vs. left branching ofTXT. This corrects the last point above: the exercise no longer needs to be dropped.dintTXTis unchanged for theTXTnodes built fromand. A discourse of several sentences (A man walked. He smiled.) becomes a list of sentence trees, given by the outer segmentation, and is interpreted by folding the dynamicconjover the list, from the transition that leaves the context as it is (fun c => [c]). Dynamic conjunction is associative, so the meaning is the same as with CSwFP's right-branchingTXTtree. Open points for that chapter: how readings combine when several sentences are ambiguous (the product of the parses of each sentence, e.g. withList.mapM, if that is already presented by then), and where questions (prsYN,prsWH) may occur in a discourse.DEVIATIONS.mdgets an entry for 9.5.arademaker commentedon Nov 19, 2026
Further decision: rename the label
TXTtoS.Sis the start symbol, for sentence (sentença). The grammar has no nonterminal of its own for a clause (oração): it reusesS. CSwFP already labels conditionals (cond1R,cond2R) asS, so coordination gets the same label. The terminology is introduced in a terse cue at the start ofParsing/ParseTrees.lean, which already uses the ruleS → S and Sas its example.When 9.7 is ported:
conjRbuildsBranch (Cat "_" "S" [] []) [s, conj, s'], i.e. the ruleS → S CONJ S, still right-branching. It does not loop: the parser of the coordination starts with the parser of a simple clause (prsS), not with itself. Recursion on the left depends on which parser is called first, not on the label of the node.Sinstead ofTXT.dintTXTmatches a coordination by the labelSwith three daughters, and tells it from a conditional by the middle daughter (CONJvs. theCONDfirst daughter).DEVIATIONS.mdgets the entry with the 9.7 port.arademaker commentedon Nov 19, 2026
Done for 9.5 in #62: the full stop has no lexicon entry,
lexertakes one sentence,andkeepsCONJand joins clauses, and the terms sentença, oração and sintagma (withSreused for clauses) are introduced inParsing/ParseTrees.lean. Recorded inDEVIATIONS.md.What is left belongs to the 9.7 port and is tracked in #49: the rule
S → S CONJ Sin place ofTXT, exercise 9.12 overS, and theDEVIATIONS.mdentry for 9.7. #62 closes this issue when merged.refactor(Parsing): one sentence at a time, terms, and exercise comple…