PCASTL explained

Designer:Philippe Choquette
Developer:Philippe Choquette
Influenced By:C, R
Latest Release Version:3.5
License:GNU Lesser General Public License
Operating System:Cross-platform
Paradigm:imperative, reflective

The PCASTL (an acronym for by Parent and Childset Accessible Syntax Tree Language) is an interpreted high-level programming language. It was created in 2008 by Philippe Choquette.[1] The PCASTL is designed to ease the writing of self-modifying code. The language has reserved words parent and childset to access the nodes of the syntax tree of the currently written code.[2]

Hello world

The "Hello world program" is quite simple:

<nowiki>
"Hello, world!"
</nowiki>
or
<nowiki>
print("Hello, world!")
</nowiki>
will do the same.

Syntax

The syntax of PCASTL is derived from programming languages C and R. The source of R version 2.5.1 has been studied to write the grammar and the lexer used in the PCASTL interpreter.

Influences

Like in R, statements can, but do not have to, be separated by semicolons.[3] Like in R, a variable can change type in a session. Like in C and R, PCASTL uses balanced brackets () to make blocks.

Operators found in PCASTL have the same precedence and associativity as their counterparts in C.[4] for loops are defined like in C. ++ and -- operators are used like in C to increment or decrement a variable before or after it is used in its expression.

An example of PCASTL using the for reserved word and the ++ operator:for (i = 1; i < 4; i++) print(i)

Functions and comments in PCASTL are defined like in R:

  1. function definition (comment)

a = function

  1. function call

a

parent and childset reserved words

Those reserved words can only be written lowercase and will not be recognized otherwise. The parent reserved word gives a reference to the parent node in the syntax tree of the code where the word is placed. In the following code, the parent node is the operator =.

<nowiki>
a = parent
</nowiki>

The variable "a" will hold a reference to the = node. The following code shows how to get references to the two child nodes of the operator = with the childset reserved word.

<nowiki>
a.childset[0]
a.childset[1]
</nowiki>

To display the value of "a", some ways are given in this example:

<nowiki>
a
a.childset[0].parent
a.childset[1].parent
a.childset[0].parent.childset[0].parent # and so on...
</nowiki>

In the following code: we assign a code segment to the right child of the = node, we execute the = node a second time and we call the newly defined function.

<nowiki>
a.childset[1] = `function print("hello")'
execute(a)
a
</nowiki>

See also

External links

Notes and References

  1. Web site: 2008-06-14. pcosmos.ca . Philippe Choquette .
  2. Web site: 2008-06-14 . PCASTL: by Parent and Childset Accessible Syntax Tree Language . Philippe Choquette .
  3. Web site: 2008-06-14. An Introduction to R . R Development Core Team .
  4. Book: Hanly, Jeri R. . Elliot B. Koffman . Problem Solving & Program Design in C, Third Edition . . 1999 . 0-201-35748-8 . registration .