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> ::= ... ==> { fail } <structural-sentence> ::= ... ==> { fail } <language-modifying-sentence> ::= ... ==> { fail } <comma-divisible-sentence> ::= ... ==> { fail }
- This is Preform grammar, not regular C code.
§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 | ==> Create relationship3.1; ... = special meaning | ==> Create special meaning3.2; ... = copular verb with priority <cardinal-number> | ==> Create copular verb3.4; ... = verb with priority <cardinal-number> | ==> Create verb3.3; -- <existing-verb> -- = <meaning> | ==> Create SVO usage3.5; -- <existing-verb> ### -- = <meaning> | ==> Create SVPO usage3.6; <existing-verb> -- = <special-meaning> | ==> Create VO usage S3.7; -- <existing-verb> -- = <special-meaning> | ==> Create SVO usage S3.8; -- <existing-verb> ### -- = <special-meaning> | ==> Create SVPO usage S3.9; <existing-verb> -- ### -- = <special-meaning> | ==> Create VSPO usage S3.10; <existing-verb> ### -- ### -- = <special-meaning> | ==> Create VPSPO usage S3.11; ... = <gender> common noun | ==> Create common noun3.12; ... = <gender> proper noun ==> Create proper noun3.13; <gender> ::= neuter | ==> { NEUTER_GENDER, - } masculine | ==> { MASCULINE_GENDER, - } feminine ==> { FEMININE_GENDER, - } <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 }; }
- This is Preform grammar, not regular C code.
§3.1. Create relationship3.1 =
Relating::new(FW[1]);
- This code is used in §3.
§3.2. Create special meaning3.2 =
text_stream *N = Str::new(); WRITE_TO(N, "%W", FW[1]); SpecialMeanings::declare(NULL, N, 0);
- This code is used in §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);
- This code is used in §3.
§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);
- This code is used in §3.
verb *V = (verb *) RP[1]; rel *RN = (rel *) RP[2]; Verbs::add_form(V, NULL, NULL, VerbMeanings::regular(RN), SVO_FS_BIT);
- This code is used in §3.
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);
- This code is used in §3.
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);
- This code is used in §3.
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);
- This code is used in §3.
§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);
- This code is used in §3.
§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);
- This code is used in §3.
§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);
- This code is used in §3.
§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));
- This code is used in §3.
§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));
- This code is used in §3.