HOME

TheInfoList



OR:

The PCASTL (an acronym for ''by Parent and Childset Accessible Syntax Tree Language'') is an interpreted
high-level programming language In computer science, a high-level programming language is a programming language with strong abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ''elements'', be easier to ...
. It was created in 2008 by Philippe Choquette. The PCASTL is designed to ease the writing of
self-modifying code In computer science, self-modifying code (SMC) is code that alters its own instructions while it is executing – usually to reduce the instruction path length and improve performance or simply to reduce otherwise repetitively similar code ...
. The language has
reserved word In a computer language, a reserved word (also known as a reserved identifier) is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". This is a syntactic definition, and a r ...
s parent and childset to access the nodes of the
syntax tree Syntax tree may refer to: * Abstract syntax tree, used in computer science * Concrete syntax tree, used in linguistics {{Disambig ...
of the currently written code.


Hello world

The "
Hello world program ''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses ''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the '' Norwich ...
" is quite simple:

"Hello, world!"
or

print("Hello, world!")
will do the same.


Syntax

The syntax of PCASTL is derived from
programming languages A programming language is a system of notation for writing computer program, computer programs. Most programming languages are text-based formal languages, but they may also be visual programming language, graphical. They are a kind of computer ...
C and R. The source of R version 2.5.1 has been studied to write the
grammar In linguistics, the grammar of a natural language is its set of structure, structural constraints on speakers' or writers' composition of clause (linguistics), clauses, phrases, and words. The term can also refer to the study of such constraint ...
and the
lexer In computer science, lexical analysis, lexing or tokenization is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of ''lexical tokens'' (strings with an assigned and thus identified m ...
used in the PCASTL interpreter.


Influences

Like in R, statements can, but do not have to, be separated by
semicolon The semicolon or semi-colon is a symbol commonly used as orthographic punctuation. In the English language, a semicolon is most commonly used to link (in a single sentence) two independent clauses that are closely related in thought. When a ...
s. Like in R, a variable can change type in a session. Like in C and R, PCASTL uses balanced
bracket A bracket is either of two tall fore- or back-facing punctuation marks commonly used to isolate a segment of text or data from its surroundings. Typically deployed in symmetric pairs, an individual bracket may be identified as a 'left' or 'r ...
s () to make
block Block or blocked may refer to: Arts, entertainment and media Broadcasting * Block programming, the result of a programming strategy in broadcasting * W242BX, a radio station licensed to Greenville, South Carolina, United States known as ''96.3 ...
s.
Operators Operator may refer to: Mathematics * A symbol indicating a mathematical operation * Logical operator or logical connective in mathematical logic * Operator (mathematics), mapping that acts on elements of a space to produce elements of another sp ...
found in PCASTL have the same
precedence Precedence may refer to: * Message precedence of military communications traffic * Order of precedence, the ceremonial hierarchy within a nation or state * Order of operations, in mathematics and computer programming * Precedence Entertainment, a ...
and
associativity In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement ...
as their counterparts in C. for loops are defined like in C. ++ and --
operators Operator may refer to: Mathematics * A symbol indicating a mathematical operation * Logical operator or logical connective in mathematical logic * Operator (mathematics), mapping that acts on elements of a space to produce elements of another sp ...
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 In a computer language, a reserved word (also known as a reserved identifier) is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". This is a syntactic definition, and a r ...
and the ++
operator Operator may refer to: Mathematics * A symbol indicating a mathematical operation * Logical operator or logical connective in mathematical logic * Operator (mathematics), mapping that acts on elements of a space to produce elements of another ...
: for (i = 1; i < 4; i++) print(i) Functions and
comments Comment may refer to: * Comment (linguistics) or rheme, that which is said about the topic (theme) of a sentence * Bernard Comment (born 1960), Swiss writer and publisher Computing * Comment (computer programming), explanatory text or informa ...
in PCASTL are defined like in R: # function definition (comment) a = function() # function call a()


parent and childset reserved words

Those
reserved word In a computer language, a reserved word (also known as a reserved identifier) is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". This is a syntactic definition, and a r ...
s can only be written lowercase and will not be recognized otherwise. The parent reserved word gives a
reference Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a '' name'' ...
to the parent node in the
syntax tree Syntax tree may refer to: * Abstract syntax tree, used in computer science * Concrete syntax tree, used in linguistics {{Disambig ...
of the code where the word is placed. In the following code, the parent node is the
operator Operator may refer to: Mathematics * A symbol indicating a mathematical operation * Logical operator or logical connective in mathematical logic * Operator (mathematics), mapping that acts on elements of a space to produce elements of another ...
=.

a = parent
The variable "a" will hold a
reference Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a '' name'' ...
to the = node. The following code shows how to get
references Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a '' name'' ...
to the two child nodes of the
operator Operator may refer to: Mathematics * A symbol indicating a mathematical operation * Logical operator or logical connective in mathematical logic * Operator (mathematics), mapping that acts on elements of a space to produce elements of another ...
= with the childset
reserved word In a computer language, a reserved word (also known as a reserved identifier) is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". This is a syntactic definition, and a r ...
.

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

a
a.childset parent
a.childset parent
a.childset parent.childset parent # and so on...
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.

a.childset = `function() print("hello")'
execute(a)
a()


See also

*
Abstract syntax tree In computer science, an abstract syntax tree (AST), or just syntax tree, is a tree representation of the abstract syntactic structure of text (often source code) written in a formal language. Each node of the tree denotes a construct occurring ...
*
Self-modifying code In computer science, self-modifying code (SMC) is code that alters its own instructions while it is executing – usually to reduce the instruction path length and improve performance or simply to reduce otherwise repetitively similar code ...


References


External links


PCASTL: by Parent and Childset Accessible Syntax Tree Language
{{DEFAULTSORT:Pcastl Free compilers and interpreters Procedural programming languages Articles with example code Programming languages created in 2008