1 Textual Language
#lang scratchy | package: scratchy |
Here’s a program for a fish that swims randomly:
1.1 Example
#lang scratchy ------------------------------------- fish image is @fish-image do forever { wait 0.02 forward by 2 turn by (random 5) - 2 }
The ---...- starts a sprite declaration, where the sprite is named fish. In addition, if the file name is "fish-land.rkt", then fish-land is defined as the land where fish starts.
1.2 Grammar
Here’s the grammar of this textual language (click on a keyword for more information):
| ‹prog› | ::= | ‹use›* ‹sprite›* |
| ‹use› | ::= | use ‹id› |
| ‹sprite› | ::= | ---...- ‹id› ‹clause›* |
| ‹clause› | ::= | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | do ‹statement›* |
| ‹expr› | ::= | ‹number› | ‹image› | ‹string› |
|
| | | ‹id› |
|
| | | ‹expr› ‹binary-op› ‹expr› |
|
| | | ‹unary-op› ‹expr› |
|
| | | random ‹expr› |
|
| | | touches ‹expr› |
|
| | | ( ‹expr› ) |
| ‹statement› | ::= | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | wait ‹expr› |
|
| | | say ‹expr› |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | |
|
| | | watch ‹expr› |
|
| | | |
|
| | | forever { ‹statement›* } |
|
| | | while ‹expr› { ‹statement›* } |
|
| | | if ‹expr› { ‹statement›* } |
|
| | | ‹id› = ‹expr› |
| ‹unary-op› | ::= | - |
|
| | | + |
| ‹binary-op› | ::= | + | - | * | / | < | > | <= | >= | = |
| ‹key› | ::= | ‹id› | + | - | * | / | < | > | = |
| ‹id› | ::= | a letter (in a/A to z/Z) followed by letters, numbers, and _s |
|
| | | @ followed by a sequence of letters, numbers, _s, and -s |
| ‹number› | ::= | a decimal number |
| ‹string› | ::= | sequence of characters between "s |
1.3 Syntactic Forms
syntax
use ‹id›
syntax
do ‹statement›*
syntax
random ‹expr›
syntax
touches ‹expr›
syntax
wait ‹expr›
syntax
say ‹expr›
syntax
syntax
watch ‹expr›
syntax
forever { ‹statement›* }
syntax
while ‹expr› { ‹statement›* }
syntax
if ‹expr› { ‹statement›* }