pcosmos.ca

le domaine de Philippe Choquette

Accueil Profil Contact Arrière plan
Half-Life
Diseases
PCASTL
Operators
Data Types
Internal Functions
Tree Structure
Batch Execution
Examples
Interpreter Informatique
OpenGL
Grow
Elements
Lecture
Liens
 
PCASTL Examples

Page en français

Turing machines
Pushdown automaton
Finite automaton
Toggles
Code Segments
Other examples

  page top Turing machines

Turing machine #1. Require gen-trans-func.txt and run_machine.txt.
Turing machine 1
Near transitions, the two symbols (x / y) are:

  • x: the symbol under the head
  • y: the action taken

The action can be:

  • R: move the head to the right
  • L: move the head to the left
  • other: the symbol to write

The empty space is represented by Delta.

  page top Pushdown automaton

A pushdown automaton. Require gen-trans-func.txt.
pushdown automaton
Over transitions, the three symbols (x, y; z) are:

  • x: the symbol read
  • y: the symbol popped
  • z: the symbol pushed

The empty sequence is represented by lambda.

  page top Finite automaton

A finite state machine.
finite automaton

  page top Toggles

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:

  • a.childset[0] would give a reference to the parameter name list of the "a" function. The function definition tree structure is illustrated here.
  • a.childset[1] gives a reference to the statement list of the "a" function.
  • a.childset[1].childset[0] gives a reference to the first statement in the previous list.
  • a.childset[1].childset[0].childset[0] would give a reference to function name node of the "print" call. The function call tree structure is illustrated here.
  • a.childset[1].childset[0].childset[1] gives a reference to the argument list of the "print" call.
  • a.childset[1].childset[0].childset[1].childset[0] gives a reference to the first element of the previous list, ie to the first argument of the "print" call.

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:

  • parent gives a reference to the argument list node of the "value" call.
  • parent.parent gives a reference to the "value" call node.
  • parent.parent.parent gives a reference to the operator == node. This node is also the condition node of the "if" statement.
  • parent.parent.parent.parent gives a reference to the "if" node.
  • parent.parent.parent.parent.parent gives a reference to the statement list node of the "a" function.
  • The additional .childset[0] gives a reference to the "print" call node.
  • The additional .childset[1] gives a reference to the argument list of the "print" call.
  • The additional .childset[0] gives a reference to the first argument of the "print" call.
# 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.

  page top Code Segments

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.

  page top Other examples

A recursive function.

PCASTL on Wikipedia (with very basic examples).

 

back to PCASTL