Skip to content

Parsing: texts parsed as conjunctions of sentences (CSwFP/9.5, 9.7) #57

Closed

Description

@arademaker

Part of #49.

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).

Activity

  1. added
    content
    needs-decision
    on Nov 18, 2026
  2. arademaker commented on Nov 18, 2026

    @arademaker
    MemberAuthor

    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.
    • DEVIATIONS.md gets an entry for 9.5.
  3. removed
    needs-decision
    on Nov 19, 2026
  4. arademaker commented on Nov 19, 2026

    @arademaker
    MemberAuthor

    Further decision: rename the label TXT to S.

    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).
    • DEVIATIONS.md gets the entry with the 9.7 port.
  5. arademaker commented on Nov 19, 2026

    @arademaker
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    content

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions