@@ -30,4 +30,107 @@ Matching the line against a sentence definition succeeds if the characters, word
3030defined in the ` sentence ` commands and the ` $expression ` placeholders match expressions.
3131
3232When a sentence is matched the syntax analyzer creates a method call to the named mathod using the expressions as
33- arguments. The expressions are passed from left to right.
33+ arguments. The expressions are passed from left to right.
34+
35+ ## Examples
36+
37+ ### Simple sentence
38+
39+ You can define a simple subroutine that asserts that the two arguments are equal and in case they are not then
40+ it signals error:
41+
42+ ```
43+ sub assertEquals(a,b)
44+ if a <> b then
45+ error "equality assertion failed"
46+ endif
47+ endsub
48+ ```
49+
50+ We can invoke it directly from the code calling the method by the name or we can define a sentence
51+
52+ ```
53+ sentence "assert that $expression is the same as $expression" call assertEquals
54+ ```
55+
56+ Following this line we can write
57+
58+ ```
59+ assert that 13+2 is the same as 15
60+ ```
61+
62+ This line will be recognized by the BASIC interpreter and executed as
63+
64+ ```
65+ assertEquals 13+2, 15
66+ ```
67+
68+
69+ ### Start with expression
70+
71+ You can start a sentence with an expression.
72+
73+ ```
74+ sentence "$expression is the answer" call isTheAnswer
75+ 42 is the answer
76+
77+
78+ sub isTheAnswer( a )
79+ if a <> 42 then
80+ error a + " is not the answer"
81+ endif
82+ endsub
83+ ```
84+
85+ will actually work.
86+
87+ You can have many sentences that start with an expression. Together with the previous example you can also have
88+
89+ ```
90+ sentence "$expression is exactly the answer" call isTheAnswer
91+ 42 is exactly the answer
92+ ```
93+
94+ in the same program.
95+
96+ ### Start with keyword
97+
98+ You can also start a sentence with a BASIC keyword.
99+
100+ ```
101+ sentence "for example $expression " call isTheAnswer
102+ for example 42
103+ ```
104+
105+ will just work fine. However it is to note that if there is a syntax error in this line, for example
106+
107+ ```
108+ for exampla 42
109+
110+ ... There is no '=' after the 'FOR'
111+
112+ ```
113+
114+ the syntax analyzer will complain about the missing ` = ` character it expectes in a ` FOR ` statement.
115+
116+ A sentence can not start with a ` ' ` character or with the keyword ` REM ` because these start comment lines and are skipped
117+ by the syntax analysis and such a use of the ` sentence ` definition is also counterintuitive. Thus if you try
118+ to create a sentence
119+
120+ ```
121+ sentence "rem sleep phase start" call StartRemPhase
122+ ```
123+
124+ in your sleep monitoring application then you will get an error starting the code (rather than just not calling the
125+ ` StartRemPhase ` method).
126+
127+ ### Start with special character
128+
129+ You can not only include but you can also start a sentence with some special character. For example
130+
131+ ```
132+ sentence ". this is $expression" call expression
133+ .this is "a string expression"
134+ ```
135+
136+ defines and uses a sentence that starts with a period.
0 commit comments