Difference between revisions of "SCI/Specifications/SCI in action/Parser"

Jump to navigation Jump to search
Merging of the SCI documentation. Work in progress.
(Merging of the SCI documentation. Work in progress.)
(Merging of the SCI documentation. Work in progress.)
Line 216: Line 216:
|}
|}


With the notable exception of the first rule, these rules constitute  <span style="white-space:nowrap"><i>P. V := {&chi;|&exist;R &isin;  P.&chi; &exist R}</i></span>; typically, <span style="white-space:nowrap"><i> V = {0&chi;12&fnof;&hellip;0&chi;13&fnof;&sdot; s = m<sub>0</sub></i></span> of the first rule encountered; in all games observed, it was set to 0x13c. &Sigma; contains all word groups and class masks. For the sake of simplicity, we will consider rules matching composite class masks to be several rules. Here is a simplified example of what such a grammar might look like (the hexadecimal prefix '0x' is omitted for brevity):
With the notable exception of the first rule, these rules constitute  <span style="white-space:nowrap"><i>P. V := {&chi;|&exist;R &isin;  P.&chi; &exist R}</i></span>; typically, <span style="white-space:nowrap"><i> V = {0&chi;12&fnof;&hellip;0&chi;13&fnof;}&sdot; s = m<sub>0</sub></i></span> of the first rule encountered; in all games observed, it was set to 0x13c. &Sigma; contains all word groups and class masks. For the sake of simplicity, we will consider rules matching composite class masks to be several rules. Here is a simplified example of what such a grammar might look like (the hexadecimal prefix '0x' is omitted for brevity):


In addition to this grammar, each right-hand non-terminal <i>m<sub>i</sub></i> carries its semantic value <i>&rho;<sub>i</sub></i> , which is not relevant for constructing a syntax tree, but must be considered for the semantic tree <i>T</i><sub>&pi;</sub>. These values were omitted in the example above. As in the example above, the grammar is a context-free (type 2) grammar, almost in Chomsky Normal Form (CNF) in SCI; constructing a grammar with CNF rules from it would be trivial.<ref>FreeSCI constructs a GNF (Greibach Normal Form) representation from these rules for parsing.</ref>
In addition to this grammar, each right-hand non-terminal <i>m<sub>i</sub></i> carries its semantic value <i>&rho;<sub>i</sub></i> , which is not relevant for constructing a syntax tree, but must be considered for the semantic tree <i>T</i><sub>&pi;</sub>. These values were omitted in the example above. As in the example above, the grammar is a context-free (type 2) grammar, almost in Chomsky Normal Form (CNF) in SCI; constructing a grammar with CNF rules from it would be trivial.<ref>FreeSCI constructs a GNF (Greibach Normal Form) representation from these rules for parsing.</ref>
Line 330: Line 330:


Here is an example, based on the previous one:
Here is an example, based on the previous one:
====Example: Parser example====
Parse is called with <i>"open door"</i>.
* <i>"open" &isin; &lang;842,{C<sub>8</sub>0}&rang;</i> (an imperative word of the word group 0x842)
* <i>"door" &isin; &lang;917,{C<sub>1</sub>0}&rang; (a substantive of the word group 0x917)</i>
* <i>I = &lang;842,{C<sub>8</sub>0}&rang;,&lang;917,{C<sub>1</sub>0}&rang;</i>
<i>I</i> is clearly accepted by automatons based on the grammar described above, There are two possible derivations:
{|
|D<sub>0</sub> = 13c
|----
|(13c &#8614; 13b134)
|&#8866; 13b 134
|----
|(13b &#8614; 131)
|&#8866; 131 134
|----
|(131 &#8614; C<sub>80</sub>
|&#8866; C<sub>80</sub> 134
|----
|(134 &#8614; C<sub>10</sub>
|&#8866; C<sub>80</sub> C<sub>10</sub>
|----
|}
<br>
{|
|D<sub>1</sub> = 13c
|----
|(13c &#8614; 13b)
|&#8866; 13b
|----
|(13b &#8614; 131134)
|&#8866; 131 134
|----
|(131 &#8614; C<sub>80</sub>
|&#8866; C<sub>80</sub> 134
|----
|(134 &#8614; C<sub>10</sub>
|&#8866; C<sub>80</sub> C<sub>10</sub>
|----
|}


====Example: Semantic tree example====
====Example: Semantic tree example====
Line 347: Line 392:


The resulting tree would look like this:
The resulting tree would look like this:
<tt><pre>
<pre>
(141 13f
(141 13f
&#09;(141 13b
&#09;(141 13b
Line 353: Line 398:
&#09;)
&#09;)
&#09;(142 134 917)
&#09;(142 134 917)
)</pre></tt>
)</pre>


==Said specs==
To test what the player wanted to say, SCI compares <i>T</i><sub>&pi;</sub> with a second tree, <i>T</i><sub>&Sigma;</sub> , which is built from a so-called Said spec. A Said spec is a variable-sized block in SCI memory which consists of a set of byte-sized operators and special tokens (stored in the range 0xf0 to 0xf9) and word groups (in big-endian notation, so that they don't conflict with the operators); it is terminated by the special token 0xff. The meanings of the operators and special tokens are as follows:


==Notes==
==Notes==
<references/>
<references/>
236

edits

Navigation menu