~ubuntu-branches/ubuntu/vivid/inform/vivid

« back to all changes in this revision

Viewing changes to html/sectionA4.html

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2008-05-26 22:09:44 UTC
  • mfrom: (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526220944-ba7phz0d1k4vo7wx
Tags: 6.31.1+dfsg-1
* Remove a considerable number of files from the package
  due to unacceptable licensing terms.
* Repair library symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<HTML><HEAD><TITLE>Section A4: Grammar</TITLE></HEAD>
2
 
<BODY BGCOLOR="#FFFFFF">
3
 
<TABLE><P>
4
 
<TR><TD Valign="top"><A HREF="contents.html">Contents</A><BR><A HREF="sectionA3.html">Back</A><BR><A HREF="sectionA5.html">Forward</A><TD bgcolor="#F5DEB3"><BLOCKQUOTE><H3>A4. Grammar</H3></BLOCKQUOTE><TR><TD><TD>
5
 
A 'verb' is a set of possible initial words in keyboard command, which are
6
 
treated synonymously (for example, "wear'' and "don'') together with
7
 
a 'grammar'.  A grammar is a list of 'lines' which the parser tries to match,
8
 
one at a time, and accepts the first one which matches.  The directive
9
 
<BLOCKQUOTE>
10
 
Verb [<TT>meta</TT>] <I><B>&#60;verb-word-1&#62;</B></I> ... <I><B>&#60;verb-word-<I>n</I>&#62;</B></I> <I><B>&#60;grammar&#62;</B></I>
11
 
</BLOCKQUOTE>
12
 
 
13
 
creates a new verb.  If it is said to be <TT>meta</TT> then it will count as 'out
14
 
of the game': for instance "score'' or "save''.  New synonyms can be added
15
 
to an old verb with:
16
 
<BLOCKQUOTE>
17
 
Verb <I><B>&#60;new-word-1&#62;</B></I> ... <I><B>&#60;new-word-<I>n</I>&#62;</B></I> <TT>=</TT> <I><B>&#60;existing-verb-word&#62;</B></I>
18
 
</BLOCKQUOTE>
19
 
 
20
 
An old verb can be modified with the directive
21
 
<BLOCKQUOTE>
22
 
Extend [<TT>only</TT>] <I><B>&#60;existing-word-1&#62;</B></I> ... <I><B>&#60;existing-word-<I>n</I>&#62;</B></I> [<I><B>&#60;priority&#62;</B></I>] <I><B>&#60;grammar&#62;</B></I>
23
 
</BLOCKQUOTE>
24
 
 
25
 
If <TT>only</TT> is specified, the existing words given (which must all be from the same
26
 
existing verb) are split off into a new independent copy of the verb.
27
 
If not, the directive extends the whole existing verb.
28
 
The priority can be <TT>first</TT> (insert
29
 
this grammar at the head of the list), <TT>last</TT> (insert it at the end) or <TT>replace</TT>
30
 
(throw away the old list and use this instead); the default is <TT>last</TT>.
31
 
<P>
32
 
 
33
 
A line is a list of 'tokens' together with the action generated if each
34
 
token matches so that the line is accepted.  The syntax of a line is
35
 
<BLOCKQUOTE>
36
 
<TT>*</TT> <I><B>&#60;token-1&#62;</B></I> <I><B>&#60;token-2&#62;</B></I> ...<I><B>&#60;token-<I>n</I>&#62;</B></I> <TT>-&#62;</TT> <I><B>&#60;action&#62;</B></I>
37
 
</BLOCKQUOTE>
38
 
 
39
 
where
40
 
0 &#60;= n &#60;= 31.
41
 
The action is named without initial <TT>##</TT> signs and if
42
 
an action which isn't in the standard library set is named then an action
43
 
routine (named with the action name followed by <TT>Sub</TT>) must be defined
44
 
somewhere in the game.
45
 
<P>
46
 
 
47
 
A grammar line can optionally be followed by the word
48
 
<TT>reverse</TT>.  This signals that the action to be generated has
49
 
two parameters, but which have been parsed in the wrong
50
 
order and need to swapped over.  (Note that a <TT>topic</TT> is
51
 
not a parameter, and nor is a preposition.)
52
 
<P>
53
 
 
54
 
<P>
55
 
 
56
 
A token matches a single particle of what has been typed.  The possible
57
 
tokens are:
58
 
 
59
 
<BR><TABLE Border><TR><TD> <TABLE Border><TR><TD><TT>"</TT><I><B>&#60;word&#62;</B></I><TT>"</TT></TABLE> <TD>    that literal word only
60
 
<TR><TD> <TABLE Border><TR><TD><TT>noun</TT></TABLE>          <TD>    any object in scope
61
 
<TR><TD> <TABLE Border><TR><TD><TT>held</TT></TABLE>          <TD>    object held by the player
62
 
<TR><TD> <TABLE Border><TR><TD><TT>multi</TT></TABLE>         <TD>    one or more objects in scope
63
 
<TR><TD> <TABLE Border><TR><TD><TT>multiheld</TT></TABLE>     <TD>    one or more held objects
64
 
<TR><TD> <TABLE Border><TR><TD><TT>multiexcept</TT></TABLE>   <TD>    one or more in scope, except the other
65
 
<TR><TD> <TABLE Border><TR><TD><TT>multiinside</TT></TABLE>   <TD>    one or more in scope, inside the other
66
 
<TR><TD> <TABLE Border><TR><TD><I><B>&#60;attribute&#62;</B></I></TABLE>  <TD>    any object in scope which has the attribute
67
 
<TR><TD> <TABLE Border><TR><TD><TT>creature</TT></TABLE>      <TD>    an object in scope which is <TT>animate</TT>
68
 
<TR><TD> <TABLE Border><TR><TD><TT>noun = </TT><I><B>&#60;Routine&#62;</B></I></TABLE> <TD>    any object in scope passing the given test
69
 
<TR><TD> <TABLE Border><TR><TD><TT>scope = </TT><I><B>&#60;Routine&#62;</B></I></TABLE> <TD>    an object in this definition of scope
70
 
<TR><TD> <TABLE Border><TR><TD><TT>number</TT></TABLE>        <TD>    a number only
71
 
<TR><TD> <TABLE Border><TR><TD><I><B>&#60;Routine&#62;</B></I></TABLE>    <TD>    refer to this general parsing routine
72
 
<TR><TD> <TABLE Border><TR><TD><TT>topic</TT></TABLE>         <TD>    any text at all
73
 
<TR><TD> <TABLE Border><TR><TD><TT>special</TT></TABLE>       <TD>    any single word or number
74
 
</TABLE>
75
 
<P>
76
 
 
77
 
Two or more literal words (only) can be written with slash
78
 
signs <TT>/</TT> between them as alternatives.  E.g., <TT>"in"/"on"</TT>
79
 
matches either the word "in'' or the word "on''.
80
 
<P>
81
 
 
82
 
For the <TABLE Border><TR><TD><TT>noun = </TT><I><B>&#60;Routine&#62;</B></I></TABLE> token,
83
 
the test routine must decide whether or not the
84
 
object in the <TT>noun</TT> variable is acceptable and return true or false.
85
 
<P>
86
 
 
87
 
For the <TABLE Border><TR><TD><TT>scope = </TT><I><B>&#60;Routine&#62;</B></I></TABLE> token,
88
 
the routine must look at the variable <TT>scope_stage</TT>.
89
 
If this is 1, then it must decide whether or not to allow a multiple object
90
 
(such as "all'') here and return true or false.  If 2, then the routine may
91
 
put objects into scope by calling either <TT>PlaceInScope(obj)</TT> to put just <TT>obj</TT>
92
 
in, or <TT>ScopeWithin(obj)</TT> to put the contents of <TT>obj</TT> into scope.  It must
93
 
then return either true (to prevent any other objects from entering scope) or
94
 
false (to let the parser put in all the usual objects).  If <TT>scope_stage=3</TT>,
95
 
it must print a suitable message to tell the player that this token was
96
 
misunderstood.
97
 
<P>
98
 
 
99
 
A general parsing routine can match any text it likes.  It should use <TT>wn</TT>,
100
 
the variable holding the number of the word currently being parsed (counting
101
 
from the verb being word 1) and the routine <TT>NextWord()</TT> to read the next
102
 
word and move <TT>wn</TT> on by 1.  The routine returns:
103
 
<BLOCKQUOTE>
104
 
-1<SAMP>      </SAMP> if the user's input isn't understood,<BR>
105
 
0<SAMP>      </SAMP> if it's understood but doesn't refer to anything,<BR>
106
 
1<SAMP>      </SAMP> if there is a numerical value resulting, or<BR>
107
 
<I>n</I><SAMP>      </SAMP> if object <I>n</I> is understood.<BR>
108
 
</BLOCKQUOTE>
109
 
 
110
 
In the case of a number, the actual value should be put into the variable
111
 
<TT>parsed_number</TT>.
112
 
On an unsuccessful match (returning -1) it doesn't matter what the final
113
 
value of <TT>wn</TT> is.  Otherwise it should be left pointing to the next
114
 
thing <I> after</I> what the routine understood.
115
 
<P>
116
 
</TABLE>
117
 
<HR><A HREF="contents.html">Contents</A> / <A HREF="sectionA3.html">Back</A> / <A HREF="sectionA5.html">Forward</A> <BR>
118
 
<A HREF="chapter1.html">Chapter I</A> / <A HREF="chapter2.html">Chapter II</A> / <A HREF="chapter3.html">Chapter III</A> / <A HREF="chapter4.html">Chapter IV</A> / <A HREF="chapter5.html">Chapter V</A> / <A HREF="chapter6.html">Chapter VI</A> / <A HREF="chapterA.html">Appendix</A><HR><SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright &#169; Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>