Jumpit :: M -> N -> Language
Jumpit is a family of languages, or more accurately, an explicitly parametrized language template.
Syntax:
Clauses are separated with newlines, empty lines and beginning/ending whitespace in a line are ignored.
Jumpit has two kinds of clauses.
A label clause is any string not starting with the string "if ", labels must be unique.
An if clause is a string of the form {"if " + c}, where c is a label existing in the source.
Semantics:
Ip starts at the first line in the program, and traverses lines from the top down.
M defines semantics for each label.
When an if clause is encountered, it behaves either as a nop, or jumps to where ever the label pointed to by the if clause is.
N defines rules for choosing whether to jump.
Example:
in Jumpit(M = "Push value given by label in global stack.",
N = "Jump if top of global stack is zero, otherwise output TOS." )
the following program would be an infinite loop outputting "4" forever.
12
4
if 12
Loopit :: M -> N -> Language
Loopit, like Jumpit, is a family of languages, or more accurately, an explicitly parametrized language template.
Syntax:
Clauses are separated with newlines, any clause indented N spaces will be a child clause of the last clause indented less than N times. Ending whitespace is ignored, empty lines are ignored.
A label clause is any string not starting with any of the strings "if ", "ifn ", "set " or "loop", labels must be unique.
An if clause is of the form "if " + varname.
An ifn clause is of the form "ifn " + varname.
An else clause is the string "else". An else clause always needs to be preceded by an if clause or an ifn clause on the same indentation level.
A set clause is of the form "set " + varname + " to " + boolean, where varname is any string not containing " to ", and boolean is either "true" or "false".
A loop clause is the string "loop".
A continue clause is the string "continue".
A break clause is the string "break"
Semantics:
Ip starts at the first line in the program, and traverses lines from the top down.
Ip will skip all child clauses of its current clause when advancing.
M defines the semantics of a label clause.
A set clause will set the variable "varname" to "boolean", whatever they are in the clause.
A normal if clause executes all its child clauses if the variable it refers to is true. If there is an else clause after it, its child clauses will be executed otherwise.
A normal ifn clause executes all its child clauses if the variable it refers to is false. If there is an else clause after it, its child clauses will be executed otherwise.
"*" is considered a special variable whose meaning is defined in N.
An else clause is a nop, but its children have a special meaning to if and ifn clauses.
A loop clause will execute its child clauses forever.
A continue clause will find the innermost parent of its that is a loop clause, and jump to the beginning of the loop.
A break clause will find the innermost parent of its that is a loop clause, and advance.
Example:
The Jumpit program show earlier,
12
4
if 12
is, converted to Loopit,
loop
12
4
if *
continue
Problem:
Compile Jumpit(M = "Output label", N = "Jump if random(0..1)<0.5") to Loopit with the same parameters.