-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvade_syntax.html
More file actions
205 lines (200 loc) · 9.73 KB
/
Copy pathvade_syntax.html
File metadata and controls
205 lines (200 loc) · 9.73 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SmallBASIC | vade_syntax</title>
<meta name="description" content="SmallBASIC | One more basic">
<link rel="canonical" href="/vade_syntax.html">
<link rel="keywords" href="vade_syntax">
<link rel="stylesheet" href="/css/style.css">
<link rel="icon" type="image/png" href="/images/sb-desktop-32x32.png">
<script src="/clipboard.js"></script>
</head>
<body>
<button onclick="topFunction()" id="BackToTopBtn" title="Go to top">⯅</button>
<script src="/backtotop.js"></script>
<div class="wrapAll clearfix">
<nav class="navigation">
<div class="logo">
<a href="/"><img src='/images/sb-logo.png?v=2' alt="logo"></a>
</div>
<div class="navlinks">
<a href="/pages/download.html">Download</a>
<a href="/pages/news.html">News</a>
<a href="/pages/community.html">Community</a>
<a class='active' href="/pages/articles.html">Resources</a>
<a href="/pages/reference.html">Language Reference</a>
<a href="/pages/guide.html">SmallBASIC Manual</a>
</div>
</nav>
<div class="mainsection">
<div class="tabs clearfix">
<div class="tabsRight">
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/blob/master/_build/pages/vade_syntax.markdown">Edit</a>
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/commits/master/_build/pages/vade_syntax.markdown">History</a>
</div>
</div>
<div class="article">
<h1 id="source-code-format">Source Code Format</h1>
<blockquote>
<p>Written by Elmar Vogt, Fürth, GERMANY</p>
</blockquote>
<div class="siteSub">
<p><a href="/">Home</a> > <a href="/pages/vade.html">Vade</a></p>
</div>
<p>Here you learn about the basics of BASIC, so to speak. This chapter
deals with the way a SmallBASIC program composed.</p>
<p>A program consists of a single source file. It is possible to include
libraries from external source files with the Unit-mechanism.</p>
<p>Source files are simple text files. They can be written in
<strong>ASCII</strong> or <strong>UTF-8</strong>.</p>
<p>The basic program component is a line of text, ending with
<sub>CR</sub> or <sub>LF/CR</sub> characters.<a href="#fn1"
class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></p>
<p>SmallBASIC is <strong>case-insensitive</strong>: The names
<code>myvar</code> and <code>MyVar</code> will always refer to the same
variable or function. Likewise, keywords are case-insensitive: Both
<code>print</code> and <code>PRINT</code> are legal variants of the same
command.</p>
<p><strong>Whitespace</strong> – i.e., non-printing characters like
spaces and tabs – is ignored in SmallBASIC, except inside string
literals where it is retained. <a href="#fn2" class="footnote-ref"
id="fnref2" role="doc-noteref"><sup>2</sup></a></p>
<pre><code>for a = 0 to 10
for a=0to 10</code></pre>
<p>But note that the omission of whitespace can lead to parsing errors:
If the above line were abbreviated to</p>
<pre><code>fora=0to10</code></pre>
<p>this would cause an error, because <code>for</code> and
<code>to</code> wouldn’t be recognized as keywords anymore. Rather,
SmallBASIC would consider <code>fora</code> and <code>to10</code> to be
variable names.<a href="#fn3" class="footnote-ref" id="fnref3"
role="doc-noteref"><sup>3</sup></a></p>
<p>Each program line contains one or more commands. Multiple commands on
a line are <strong>separated by a colon</strong> <sub>:</sub>.</p>
<pre><code>print "Hello world!"
print "Wonderful day."
print "Hello world!" : print "Wonderful day."</code></pre>
<p><strong>Line continuation</strong>: If the ampersand <sub>&</sub>
is the last character on a line, then the interpreter will assume that
the current command extends to the next line as well.</p>
<pre><code>X = 245 * 198 - sqr(5)
X = 245 * 198 &
- sqr(5)</code></pre>
<h1 id="literals">Literals</h1>
<h2 id="numbers">Numbers</h2>
<p>Numbers can be written in the usual manner, using either
<sub>conventional</sub> or scientific notation. All of the following
examples are legal numbers in:</p>
<pre><code>1, 0, -1, 1.2, -23232.5, 1.902e-50, -.423</code></pre>
<p>As is shown in the last example, numbers with an absolute value
<sub><1</sub> need not be preceded with <sub>0</sub>.</p>
<p>Integer numbers can also be represented in hexadecimal, octal and
binary notation with various prefixes:</p>
<p><strong>hexadecimal</strong>: <sub>&h</sub>, <sub>0h</sub>,
<sub>&x</sub>, or <sub>0x</sub></p>
<p><strong>octal</strong>: <sub>&o</sub> or <sub>0o</sub></p>
<p><strong>binary</strong>: <sub>&b</sub> (or <sub>0b</sub>)</p>
<pre><code>&hAFFE0815, &o4242, &b100101011
0hAFFE0815, 0o4242, 0b100101011</code></pre>
<h2 id="string-literals">String literals</h2>
<p>String literals are character sequences which are to be treated as
program data <sub>as is</sub>, not as variable or keyword names. String
literals are bracketed by double quotes <sub>"</sub>.</p>
<pre><code>"This is a string literal"
this will be considered as a sequence of keywords</code></pre>
<p>Note that when a string literal is to be extended across more than
one line, it must be properly closed before the continuation ampersand
and re-opened on the subsequent line with the <sub>"</sub> delimiter
character:</p>
<pre><code>print "Hello &
world!" ' error
print "Hello " &
"world!" ' correct</code></pre>
<h1 id="identifiers">Identifiers</h1>
<p>Identifiers – <sub>names</sub> for variables and functions – follow
the usual conventions:</p>
<p>They consist of a letter or an underscore <sub>_</sub>, followed by
one or more of the following:</p>
<ul>
<li><p>other letters</p></li>
<li><p>digits (<sub>0</sub> – <sub>9</sub>)</p></li>
<li><p>the underscore <sub>_</sub></p></li>
<li><p>the dollar sign <sub>$</sub> (only as the last character of the
identifier, see below)</p></li>
</ul>
<p>A single underscore <sub>_</sub> is a legal complete identifier.</p>
<p>Identifiers can have virtually unlimited length. All characters are
significant in resolving an identifier (ie, to determine whether two
identifiers refer to the same variable.)<a href="#fn4"
class="footnote-ref" id="fnref4" role="doc-noteref"><sup>4</sup></a></p>
<p>Traditionally, in BASIC the <strong>dollar sign</strong>
<code>$</code> serves as a signal to indicate that a name identifies a
string variable, if used as the last character of the identifier (i.e.,
<code>my_name$</code>).</p>
<p>Since SmallBASIC is a typeless language (see below) where variables
can hold values of any type, such a signal would be misleading, yet it
has been retained for the sake of compatibility. It may be placed as the
last character of an identifier only. Here it serves two distinguish
between identifiers (<code>harry</code> and <code>harry$</code> are two
different identifiers), but has otherwise no function.</p>
<h1 id="comments">Comments</h1>
<p><strong>Line comments</strong> can be introduced in three ways:</p>
<ul>
<li><p>With the keyword <code>rem</code>,</p></li>
<li><p>With the apostrophe character <sub>’</sub>,</p></li>
<li><p>With a hash sign <sub>#</sub>.</p></li>
</ul>
<p>Everything on the current line following the comment introduction
will be ignored in program execution.</p>
<p>If the <code>rem</code> keyword is used and it is preceded by other
commands on the current line, it must be separated from the previous
commands by a colon <sub>:</sub> If the hash sign is used, it must be
the first character on the line.</p>
<pre><code>for a=0 to 10 ' this is a valid comment
print a : rem this also
# this is a whole line commented out
next a
rem the last comment
print "Hello world!" rem vain commenting attempt</code></pre>
<p>The <code>rem</code> in the last line above will cause an error,
because it needs to be preceded with a colon <sub>:</sub>.</p>
<p>There are no provision for <strong>block comments</strong>.</p>
<section id="footnotes" class="footnotes footnotes-end-of-document"
role="doc-endnotes">
<hr />
<ol>
<li id="fn1"><p>Don’t worry about this, your operating system will
handle it right. It may only every be an issue if you use source files
written in one OS and then transferred to a different one.<a
href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn2"><p>All listings in the vademecum follow the same convention
and show the source code as you would have typed it in in the IDE. If a
line in the listing begins with a greater-than sign <sub>></sub>,
this indicates a response of the program printed on your screen.<a
href="#fnref2" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn3"><p>As a rule of thumb, it’s advisable to always leave
spaces around keywords.<a href="#fnref3" class="footnote-back"
role="doc-backlink">↩︎</a></p></li>
<li id="fn4"><p>This is in contrast to many older BASICs. The
<em>Commodore BASIC</em> shipped with the honourable C64, for example,
allowed identifiers of arbitrary length, but used only the first two
letters for resolution: <code>hoogla</code> and <code>hooray</code> were
considered to refer to the same variable.<a href="#fnref4"
class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</section>
</div>
<div class="pagefooter">
This page was last edited on Tue, 27 Mar 2018 21:57:51 +1000
|
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
processed with
<a href="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>
</div>
</div>
</div>
</body>
</html>