-
Notifications
You must be signed in to change notification settings - Fork 0
Turtle Speak
lincore81 edited this page Sep 26, 2012
·
16 revisions
Turtle speak or just ts is a dialect of the Logo programming language. It is offered as an alternative way of turtle scripting instead of directly using a turtle instance from jsr-223 scripts. Turtle scripts are very small, even complex scripts often fit on a single line.
This simple script draws a square with a side length of 10 blocks:
rep 4 (fd 10 rt)
A slightly longer version:
repeat 4 (forward 10 right)
- definition:
foo := bar
- terminal string:
"x"
or'x'
- range:
alphabet := "a".."z"
- alternation:
this | that
- option:
[option]
- grouping:
(group)
- repetition:
{thisOccursZeroOrMoreTimes}
- exception:
anyDigitButZero := digit -"0"
- special sequence:
? printable character ?
Note: Everything is case insensitive unless stated otherwise.
whitespace := ? whitespace character \s
ws := whitespace {whitespace}
optional_ws := {whitespace}
digit := "0".."9"
sign := "+" | "-"
integer := [ sign ] digit { digit }
float := integer [ "." digit { digit } ]
argument := integer | float
keyword := "lt" | "left" | "rt" | "right" | "up" | "dn" | "down" |
"fd" | "forward" | "bw" | "backward" | "pu" | "penup" |
"pd" | "pendown" | "rep" | "repeat" |
"goup" | "godn" | "godown" | "reset"
command := keyword ws {argument} optional_ws [block]
block := "(" optional_ws command {ws command} optional_ws ")"
program := command ws {command}
This version introduces string literals, variables and procedures as well as new commands.
character := "A".."Z" | "_"
identifier := character { character | digit}
quote := '"' -'\"'
string character := ? any printable character ?
string := quote {string character -quote} quote
variable := "$" identifier
argument := integer | float | string | variable
procedure name := identifier -keyword
procedure declaration := "to" ws identifier ws {variable} optional_ws block
procedure call := identifier {ws argument}
keyword+ := "block" | "bl"
comment := "//" {string character} ?line end?
Preprocessor?
Could be used to specify which turtle to use, cui arguments needed etc. to make ts scripts runnable without any additional scripting.
Logic & arithmetic expressions?
- logic operators:
== != < > <= >= ! | &
- arithmetic operators:
+ - / * \ ^ ++ -- = += -= /= *=
Ideas:
- for prolonged sanity don't support complex expressions with parens or multiple operations, which would require correct operator precendence.
- when the analyser stumbles upon a literal or variable look ahead to see if the next token is an operator and handle that like a keyword
- prefix operators can be handle like a keyword:
++$x
==>plusplus $x
- the lexer must be modified to separate the tokens correctly:
$x^2
==>{"$x","^","2"}
- Dialects should define the operators just like they do with keywords already.
repeat $foo * 2 ($i *= 1.2 fd $i rt $angle)
if 0 == $x \ 2 (pd) else (pu)
- actually thats bad, use prefix notation:
mod $isOdd $x 2 if $isOdd (foo)
- maybe even better, use blocks
set $foo [add $a [sub $b $c]] // foo = a + (b - c)
nah, that's complicated again.