2021-01-21 13:40:28 +01:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
|
|
|
<title>.</title>
|
|
|
|
<style type="text/css">
|
|
|
|
|
|
|
|
* { color: #000; background: #fff; max-width: 700px; }
|
|
|
|
tt, pre { background: #dedede; color: #111; font-family: monospace;
|
|
|
|
white-space: pre; display: block; width: 100%; }
|
|
|
|
.indentedcode { margin-left: 2em; margin-right: 2em; }
|
|
|
|
.codeblock {
|
|
|
|
background: #dedede; color: #111; font-family: monospace;
|
|
|
|
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
|
|
|
padding: 7px;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.indentedlist { margin-left: 2em; color: #000; }
|
|
|
|
|
|
|
|
span { white-space: pre; }
|
|
|
|
.text { color: #000; white-space: pre; background: #dedede; }
|
|
|
|
.colon { color: #000; background: #dedede; }
|
|
|
|
.note { color: #000; background: #dedede; }
|
|
|
|
.str { color: #000; text-decoration: underline; background: #dedede; }
|
|
|
|
.num { color: #000; background: #dedede; font-weight: bold; font-style: italic; }
|
|
|
|
.fnum { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.ptr { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.fetch { color: #000; font-style: italic; background: #dedede; }
|
|
|
|
.store { color: #000; font-style: italic; background: #dedede; }
|
|
|
|
.char { color: #000; background: #dedede; }
|
|
|
|
.inst { color: #000; background: #dedede; }
|
|
|
|
.defer { color: #000; background: #dedede; }
|
|
|
|
.imm { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.prim { color: #000; font-weight: bolder; background: #dedede; }
|
|
|
|
|
|
|
|
.tt { white-space: pre; font-family: monospace; background: #dedede; }
|
|
|
|
|
|
|
|
.h1, .h2, .h3, .h4 { white-space: normal; }
|
|
|
|
.h1 { font-size: 125%; }
|
|
|
|
.h2 { font-size: 120%; }
|
|
|
|
.h3 { font-size: 115%; }
|
|
|
|
.h4 { font-size: 110%; }
|
|
|
|
.hr { display: block; height: 2px; background: #000000; }
|
|
|
|
</style>
|
|
|
|
</head><body>
|
|
|
|
<p><span class="h1">Syntax</span>
|
|
|
|
<br/><br/>
|
2021-05-17 19:04:42 +02:00
|
|
|
Retro has more syntax than a traditional Forth due to ideas
|
2021-01-21 13:40:28 +01:00
|
|
|
borrowed from ColorForth and some design decisions. This has
|
|
|
|
some useful traits, and helps to make the language more
|
|
|
|
consistent.
|
|
|
|
<br/><br/>
|
|
|
|
<span class="h2">Tokens</span>
|
|
|
|
<br/><br/>
|
|
|
|
Input is divided into a series of whitespace delimited tokens.
|
|
|
|
Each of these is then processed individually. There are no
|
2021-05-17 19:04:42 +02:00
|
|
|
parsing words in Retro.
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
2021-05-17 19:04:42 +02:00
|
|
|
Tokens may have a single character <strong>sigil</strong>, which Retro will
|
2021-01-21 13:40:28 +01:00
|
|
|
use to decide how to process the token.
|
|
|
|
<br/><br/>
|
2021-03-30 13:58:25 +02:00
|
|
|
<span class="h2">Sigils</span>
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
2021-03-30 13:58:25 +02:00
|
|
|
Sigils are single characters added to the start of a token
|
2021-01-21 13:40:28 +01:00
|
|
|
to guide the compiler. The use of these is a major way in
|
2021-05-17 19:04:42 +02:00
|
|
|
which Retro differs from traditional Forth.
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
2021-05-17 19:04:42 +02:00
|
|
|
When a token is passed to <span class="tt">interpret</span>, Retro first takes the
|
2021-01-21 13:40:28 +01:00
|
|
|
initial character and looks to see if there is a word that
|
|
|
|
matches this. If so, it will pass the rest of the token to
|
|
|
|
that word to handle.
|
|
|
|
<br/><br/>
|
|
|
|
In a traditional Forth, the interpret process is something
|
|
|
|
like:
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>get token</tt>
|
|
|
|
<tt class='indentedcode'>is token in the dictionary?</tt>
|
|
|
|
<tt class='indentedcode'> yes:</tt>
|
|
|
|
<tt class='indentedcode'> is it immediate?</tt>
|
|
|
|
<tt class='indentedcode'> yes: call the word.</tt>
|
|
|
|
<tt class='indentedcode'> no: are we interpreting?</tt>
|
|
|
|
<tt class='indentedcode'> yes: call the word</tt>
|
|
|
|
<tt class='indentedcode'> no: compile a call to the word</tt>
|
|
|
|
<tt class='indentedcode'> no:</tt>
|
|
|
|
<tt class='indentedcode'> is it a number?</tt>
|
|
|
|
<tt class='indentedcode'> yes: are we interpreting?</tt>
|
|
|
|
<tt class='indentedcode'> yes: push the number to the stack</tt>
|
|
|
|
<tt class='indentedcode'> no: compile the number as a literal</tt>
|
|
|
|
<tt class='indentedcode'> no: report an error ("not found")</tt>
|
|
|
|
<br/><br/>
|
2021-05-17 19:04:42 +02:00
|
|
|
In Retro, the interpret process is basically:
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>get token</tt>
|
2021-03-30 13:58:25 +02:00
|
|
|
<tt class='indentedcode'>does the first character match a `sigil:` word?</tt>
|
|
|
|
<tt class='indentedcode'> yes: pass the token to the sigil handler</tt>
|
2021-01-21 13:40:28 +01:00
|
|
|
<tt class='indentedcode'> no: is token a word in the dictionary?</tt>
|
|
|
|
<tt class='indentedcode'> yes: push the XT to the stack and call the</tt>
|
|
|
|
<tt class='indentedcode'> class handler</tt>
|
|
|
|
<tt class='indentedcode'> no: report an error ("not found")</tt>
|
|
|
|
<br/><br/>
|
|
|
|
All of the actual logic for how to deal with tokens is moved
|
2021-03-30 13:58:25 +02:00
|
|
|
to the individual sigil handlers, and the logic for handling
|
2021-01-21 13:40:28 +01:00
|
|
|
words is moved to word class handlers.
|
|
|
|
<br/><br/>
|
2021-03-30 13:58:25 +02:00
|
|
|
This means that sigils are used for a lot of things. Numbers?
|
|
|
|
Handled by a <span class="tt">#</span> sigil. Strings? Use the <span class="tt">'</span> sigil. Comments?
|
|
|
|
Use <span class="tt">(</span>. Making a new word? Use the <span class="tt">:</span> sigil.
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
2021-03-30 13:58:25 +02:00
|
|
|
The major sigils are:
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
2021-03-30 13:58:25 +02:00
|
|
|
<tt class='indentedcode'>| Sigil | Used For |</tt>
|
2021-01-21 13:40:28 +01:00
|
|
|
<tt class='indentedcode'>| ------ | ----------------------------- |</tt>
|
|
|
|
<tt class='indentedcode'>| @ | Fetch from variable |</tt>
|
|
|
|
<tt class='indentedcode'>| ! | Store into variable |</tt>
|
|
|
|
<tt class='indentedcode'>| & | Pointer to named item |</tt>
|
|
|
|
<tt class='indentedcode'>| # | Numbers |</tt>
|
|
|
|
<tt class='indentedcode'>| $ | ASCII characters |</tt>
|
|
|
|
<tt class='indentedcode'>| ' | Strings |</tt>
|
|
|
|
<tt class='indentedcode'>| ( | Comments |</tt>
|
|
|
|
<tt class='indentedcode'>| : | Define a word |</tt>
|
|
|
|
<br/><br/>
|
2021-03-30 13:58:25 +02:00
|
|
|
The individual sigils will be covered in more detail in the
|
2021-01-21 13:40:28 +01:00
|
|
|
later chapters on working with different data types.
|
|
|
|
<br/><br/>
|
|
|
|
<br/><br/>
|
|
|
|
Word classes are words which take a pointer and do something
|
|
|
|
with it. These are covered in detail in their own chapter,
|
|
|
|
but essentially they decide <strong>how</strong> to execute or compile specific
|
|
|
|
types of words.
|
|
|
|
<br/><br/>
|
|
|
|
</p>
|
|
|
|
</body></html>
|