Skip to content

Instantly share code, notes, and snippets.

@Aniq55
Last active June 23, 2017 15:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aniq55/002a92f1a3c85b2078b4606c082cf71b to your computer and use it in GitHub Desktop.
Save Aniq55/002a92f1a3c85b2078b4606c082cf71b to your computer and use it in GitHub Desktop.
syntax for DSL

DSL Syntax

This is the basic syntax for the DSL which is being designed for Learnbot.

Indentation is not required, it is done here only for clarity.

When this code is translated into python, indentation is done automatically.

Print statement

print “<statement>”

Example

print “Learnbot DSL”

Variable declaration

<Variable_name> = <value>

Example

a= 55
b="hello"

Conditional statements

if <condition> then
    <statement1>
    <statement2>
    ...
else if <condition> then
    <statement1>
    <statement2>
    ...
else
    <statement1>
    <statement2>
    ...
end

Example

if alpha>beta then
print "Alpha wins"
else if alpha == beta then
print "Draw"
else if beta>alpha then
print "Beta wins"
else
print "Else is working"
end

Mathematical Operations

<variable_name>= <Mathematical_expression>

Example

gamma = alpha*beta - (alpha+beta)

Loops

Type 1

repeat <number_of_times> times
<statement1>
<statement2>
...
end

Example

repeat 10 times
move_left 2
end

Type 2

repeat <var_name> from <rangle_low> to <range_high>
<statement1>
<statement2>
...
end

Example

repeat i from 1 to 5
print 5*i
set_move 5*i 0    
end

Input

<var_name>= input

Example

x = input

Learnbot-specific statements

turn_right
turn_left
turn_back
turn <angle_in_degrees>
move_left
move_left <time_in_seconds>
move_right
move_right <time_in_seconds>
move_straight
move_straight <time_in_seconds>
stop_bot
set_move <speed> <angular_speed>
<var_name>= get_image
<var_name>= get_distance
<var_name>= get_move
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment