| Accueil | Profil | Contact | Arrière plan |
|
|
Turing machines Turing machine #1.
Require gen-trans-func.txt and
run_machine.txt.
The action can be:
The empty space is represented by Delta. A pushdown automaton.
Require gen-trans-func.txt.
The empty sequence is represented by lambda. The following code demonstrates one of three ways of defining a function that alternatively displays two results. # first way
# function definition:
a = function()
{
print(1)
if (value(a.childset[1].childset[0].childset[1].childset[0]) == 1)
{
a.childset[1].childset[0] = `print(2)'
}
else
{
a.childset[1].childset[0] = `print(1)'
}
{}
}
# function calls
a()
a()
In the first way:
One line comments have to begin with # and we end the statement list of the "a" body with {} to prevent the display of the value of the assignation in the "else". # second way
a = function()
{
print(1)
# arglist, value call, operator==, if, stmtlist
if (value(parent.parent.parent.parent.parent
.childset[0].childset[1].childset[0]) == 1)
{
a.childset[1].childset[0] = `print(2)'
}
else
{
a.childset[1].childset[0] = `print(1)'
}
{}
}
a()
a()
In the second way:
# third way
a = function()
{
print(1)
b = parent.parent.childset[0].childset[1].childset[0]
if (value(b)== 1)
{
*b = `2'
}
else
{
*b = `1'
}
{}
}
a()
a()
In the third way, we use the unary operator * meaning that we want the assignation to be done to the reference holded by the variable "b". If they were not inside a function body, the "else" could not be placed at the beginning of a new line. Placing an "else" at the beginning of a new line would result in a syntax error. A function displaying alternatively three results. A function generating functions displaying alternatively n results. You can use code segments as starting points for genealogical dotted lists. > info(` "abc" ')
Node type: code segment
> info(` "abc" '.childset[0])
Node type: string
Content: "abc"
> info(` "abc" != "cba" '.childset[0])
Node type: relational or logical operator
Number of childs: 2
Operator: !=
> info(` function(x) x '.childset[0])
Node type: function definition
Parameters: "x"
When you assign a code segment to an existing node, you do not have to get the code root using the `{code here}'.childset[0] form. Using the `{code here}' form is enough. PCASTL on Wikipedia (with very basic examples).
|