-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage.cpp
80 lines (69 loc) · 2.44 KB
/
language.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "codepoints.hpp"
#include "parser.hpp"
#include "session.hpp"
using namespace std;
// Nonterminals.
#define N(kind, tier) nonterminal{ENCODE("|" kind "|"), tier}
// Token terminals.
#define T(text) token_terminal{ENCODE(text)}
// Macros used directly in the code below.
#define RESULT(level, kind, tier) { level current{*this, N(kind, tier), true};
#define SLOT current.add_slot();
#define TERMINAL(text) current.add_alternative_to_last_slot(T(text));
#define NONTERMINAL(kind, tier) current.add_alternative_to_last_slot(N(kind, tier));
#define OTHER(parseme) current.add_alternative_to_last_slot(parseme);
#define DONE current.justify(); }
session::session() {
// Parentheses
RESULT(wording, "left parenthesis", 0);
SLOT TERMINAL("(");
DONE;
RESULT(wording, "right parenthesis", 0);
SLOT TERMINAL(")");
DONE;
// Digits
RESULT(wording, "digits", 0);
SLOT OTHER(digits_terminal{});
DONE;
// Words
RESULT(wording, "word", 0);
SLOT OTHER(word_terminal{});
DONE;
// Name words
RESULT(wording, "name word", 0);
SLOT OTHER(name_word_terminal{});
DONE;
// Sentence endings
RESULT(sentence, "end of a sentence with paragraph break (internal)", 0);
SLOT TERMINAL("|"); // TODO: Replace this placeholder with a working implementation.
DONE;
RESULT(sentence, "end of a sentence with full stop (internal)", 0);
SLOT TERMINAL(".");
DONE;
RESULT(sentence, "end of a sentence with semicolon (internal)", 0);
SLOT TERMINAL(";");
DONE;
RESULT(sentence, "end of a sentence with colon (internal)", 0);
SLOT TERMINAL(":");
DONE;
RESULT(sentence, "end of a sentence", 0);
SLOT NONTERMINAL("end of a sentence with paragraph break (internal)", 0) NONTERMINAL("end of a sentence with full stop (internal)", 0) NONTERMINAL("end of a sentence with semicolon (internal)", 0) NONTERMINAL("end of a sentence with colon (internal)", 0);
DONE;
// Name words (internal)
RESULT(wording, "name words (internal)", 0);
SLOT NONTERMINAL("name word", 0);
DONE;
RESULT(wording, "name words (internal)", 0);
SLOT NONTERMINAL("name words (internal)", 0);
SLOT NONTERMINAL("name word", 0);
DONE;
// Nonterminal declarations
RESULT(sentence, "a nonterminal declaration", 0);
SLOT TERMINAL("#");
SLOT NONTERMINAL("name words (internal)", 0);
SLOT TERMINAL("is");
SLOT TERMINAL("a");
SLOT TERMINAL("wording") TERMINAL("line") TERMINAL("sentence") TERMINAL("passage");
SLOT NONTERMINAL("end of a sentence", 0);
DONE;
}