pcosmos.ca

le domaine de Philippe Choquette

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

PCASTL
by Parent and Childset Accessible Syntax Tree Language

Page en français

The PCASTL is an interpreted high level programming language which makes writing self-modifying code easier. Its features are:

  • The "parent" keyword to access a parent node in the code syntax tree.
  • The "childset" keyword to access a child node in the code syntax tree.
  • The use of explicit code segments delimited with ` and '.
  • Allows calls to dynamic-link libraries, shared object libraries or dynamic libraries.
  • Object, array and chained list data types. They are respectively created by internal functions names, array and list.
  • ANSI stdio.h interface for single-byte strings functions.
  • Turing complete.

The most recent version is 2.4 and was released on 2012-11-11.
List of changes.

So, what's a syntax tree?

For example, inside the interpreter, the tree having its root in the variable fact after the following code has been executed:

fact = function(x)
{
   if (x == 1) return(1)
   return(x * fact(x - 1))
}

is:

Syntax Tree

Below you can see how childset and parent keywords can be used to navigate this tree.

> info(fact)
        Node type: function definition
        Parameters: "x"
> info(fact.childset[0])
        Node type: list
        Number of items: 1
> info(fact.childset[0].childset[0])
        Node type: variable
        Name: "x"
> info(fact.childset[1])
        Node type: list
        Number of items: 2
> info(fact.childset[1].childset[0])
        Node type: "if" statement
> info(fact.childset[1].childset[1])
        Node type: function call
        Function name: "return"
        Number of arguments: 1
> info(fact.childset[0].parent)
        Node type: function definition
        Parameters: "x"

Here are ways to edit the tree:

> mknode(fact.childset[1], `if (x < 1) {
+    print("Parameter must be greater than zero.")
+    abort()
+ }', 0)
> fact(-2)
        "Parameter must be greater than zero."
> info(fact.childset[1])
        Node type: list
        Number of items: 3
> info(fact.childset[1].childset[0].childset[1].childset[1])
        Node type: function call
        Function name: "abort"
        Number of arguments: 0
> fact.childset[1].childset[0].childset[1].childset[1] = `return(-1)'
        0x4db020
> info(fact.childset[1].childset[0].childset[1].childset[1])
        Node type: function call
        Function name: "return"
        Number of arguments: 1
> fact(-2)
        "Parameter must be greater than zero."
        -1