Filling a vocabulary bank with nouns, verbs, prepositions and so on.


§1. Keeping the syntax module happy.We are going to need to use the sentence-breaking apparatus from the syntax module, which means that the following four nonterminals need to exist. But in fact they are really just placeholders — they are wired so that they can never match any text.

<dividing-sentence>
    ...

<structural-sentence>
    ...

<language-modifying-sentence>
    ...

<comma-divisible-sentence>
    ...

§2. Loading from a file.The following function reads a file whose name is in arg, feeds it into the lexer, builds a syntax tree of its sentences, and then walks through that tree, applying the Preform nonterminal <vocabulary-line> to each sentence.

void Banking::load_from_file(text_stream *arg) {
    filename *F = Filenames::from_text(arg);
    feed_t FD = Feeds::begin();
    source_file *sf = TextFromFiles::feed_into_lexer(F, NULL_GENERAL_POINTER);
    wording W = Feeds::end(FD);
    if (sf == NULL) { PRINT("File has failed to open\n"); return; }
    parse_node_tree *syntax_tree = SyntaxTree::new();
    Sentences::break(syntax_tree, W);
    SyntaxTree::traverse(syntax_tree, Banking::parse);
}

void Banking::parse(parse_node *p) {
    if (Node::get_type(p) == SENTENCE_NT) {
        wording W = Node::get_text(p);
        if (<vocabulary-line>(W) == FALSE)
            Errors::nowhere("vocabulary line not understood");
    }
}

§3. The file should contain a series of simple declarations, with the grammar below. This is not parsed by the linguistics module at all: we do it all with the facilities offered by the syntax and words modules.

Typical lines in the vocabulary look like this:

    CARRIES = relationship.
    be = copular verb with priority 2.
    -- be on -- = CARRIES-reversed.
    Beth = feminine proper noun.
    sailor = neuter common noun.

And these are parsed by the following simple Preform grammar:

<vocabulary-line>
    ... = relationship |
    ... = special meaning |
    ... = copular verb with priority <cardinal-number> |
    ... = verb with priority <cardinal-number> |
    -- <existing-verb> -- = <meaning> |
    -- <existing-verb> ### -- = <meaning> |
    <existing-verb> -- = <special-meaning> |
    -- <existing-verb> -- = <special-meaning> |
    -- <existing-verb> ### -- = <special-meaning> |
    <existing-verb> -- ### -- = <special-meaning> |
    <existing-verb> ### -- ### -- = <special-meaning> |
    ... = <gender> common noun |
    ... = <gender> proper noun

<gender>
    neuter |
    masculine |
    feminine

<meaning> internal 1
    rel *R = Relating::find(W);
    if (R) {
        ==> { -, R };
        return TRUE;
    }
    ==> { fail nonterminal };
}

<special-meaning> internal 1
    special_meaning_holder *smh = SpecialMeanings::find_from_wording(W);
    if (smh) {
        ==> { -, smh };
        return TRUE;
    }
    ==> { fail nonterminal };
}

<existing-verb> internal
    verb *V;
    LOOP_OVER(V, verb)
        if (WordAssemblages::compare_with_wording(&(V->conjugation->infinitive), W)) {
            ==> { -, V };
            return TRUE;
        }
    ==> { fail nonterminal };
}

§3.1. Create relationship3.1 =

    Relating::new(FW[1]);

§3.2. Create special meaning3.2 =

    text_stream *N = Str::new();
    WRITE_TO(N, "%W", FW[1]);
    SpecialMeanings::declare(NULL, N, 0);

§3.3. Create verb3.3 =

    verb_conjugation *vc =
        Conjugation::conjugate(
            WordAssemblages::from_wording(FW[1]), DefaultLanguage::get(NULL));
    verb *V = Verbs::new_verb(vc, FALSE);
    vc->vc_conjugates = V;
    VerbUsages::register_all_usages_of_verb(V, FALSE, R[1], NULL);

§3.4. Create copular verb3.4 =

    verb_conjugation *vc =
        Conjugation::conjugate(
            WordAssemblages::from_wording(FW[1]), DefaultLanguage::get(NULL));
    verb *V = Verbs::new_verb(vc, TRUE);
    vc->vc_conjugates = V;
    VerbUsages::register_all_usages_of_verb(V, FALSE, R[1], NULL);

§3.5. Create SVO usage3.5 =

    verb *V = (verb *) RP[1];
    rel *RN = (rel *) RP[2];
    Verbs::add_form(V, NULL, NULL, VerbMeanings::regular(RN), SVO_FS_BIT);

§3.6. Create SVPO usage3.6 =

    verb *V = (verb *) RP[1];
    rel *RN = (rel *) RP[2];
    word_assemblage wa = WordAssemblages::from_wording(FW[1]);
    preposition *prep = Prepositions::make(wa, FALSE, NULL);
    Verbs::add_form(V, prep, NULL, VerbMeanings::regular(RN), SVO_FS_BIT);

§3.7. Create VO usage S3.7 =

    verb *V = (verb *) RP[1];
    special_meaning_holder *SM = (special_meaning_holder *) RP[2];
    Verbs::add_form(V, NULL, NULL, VerbMeanings::special(SM), VO_FS_BIT);

§3.8. Create SVO usage S3.8 =

    verb *V = (verb *) RP[1];
    special_meaning_holder *SM = (special_meaning_holder *) RP[2];
    Verbs::add_form(V, NULL, NULL, VerbMeanings::special(SM), SVO_FS_BIT);

§3.9. Create SVPO usage S3.9 =

    verb *V = (verb *) RP[1];
    special_meaning_holder *SM = (special_meaning_holder *) RP[2];
    word_assemblage wa = WordAssemblages::from_wording(FW[1]);
    preposition *prep = Prepositions::make(wa, FALSE, NULL);
    Verbs::add_form(V, prep, NULL, VerbMeanings::special(SM), SVO_FS_BIT);

§3.10. Create VSPO usage S3.10 =

    verb *V = (verb *) RP[1];
    special_meaning_holder *SM = (special_meaning_holder *) RP[2];
    word_assemblage wa = WordAssemblages::from_wording(FW[1]);
    preposition *prep = Prepositions::make(wa, FALSE, NULL);
    Verbs::add_form(V, NULL, prep, VerbMeanings::special(SM), VOO_FS_BIT);

§3.11. Create VPSPO usage S3.11 =

    verb *V = (verb *) RP[1];
    special_meaning_holder *SM = (special_meaning_holder *) RP[2];
    word_assemblage wa1 = WordAssemblages::from_wording(FW[1]);
    word_assemblage wa2 = WordAssemblages::from_wording(FW[2]);
    preposition *prep1 = Prepositions::make(wa1, FALSE, NULL);
    preposition *prep2 = Prepositions::make(wa2, FALSE, NULL);
    Verbs::add_form(V, prep1, prep2, VerbMeanings::special(SM), VOO_FS_BIT);

§3.12. Create common noun3.12 =

    Nouns::new_common_noun(FW[1], R[1], ADD_TO_LEXICON_NTOPT + WITH_PLURAL_FORMS_NTOPT,
        NOUN_MC, NULL_GENERAL_POINTER, DefaultLanguage::get(NULL));

§3.13. Create proper noun3.13 =

    Nouns::new_proper_noun(FW[1], R[1], ADD_TO_LEXICON_NTOPT + WITH_PLURAL_FORMS_NTOPT,
        NOUN_MC, NULL, DefaultLanguage::get(NULL));