{{Short description|High-level programming language}} {{ infobox programming language | designer = Philippe Choquette | developer = Philippe Choquette | influenced_by = [[C (programming language)|C]], [[R (programming language)|R]] | latest_release_version = 3.5 | latest_release_date = {{Start date and age|2018|03|31}} | license = [[GNU Lesser General Public License]] | operating_system = [[Cross-platform]] | paradigm = [[Imperative programming|imperative]], [[Reflective programming|reflective]] | year = {{Start date and age|2008}} | website = {{URL|www.pcosmos.ca/pcastl/}} }} 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.<ref>{{cite web|access-date=2008-06-14|url=http://www.pcosmos.ca/|title=pcosmos.ca |publisher=Philippe Choquette }}</ref> The PCASTL is designed to ease the writing of [[self-modifying code]]. The language has [[reserved word]]s '''parent''' and '''childset''' to access the nodes of the [[Abstract syntax tree|syntax tree]] of the currently written code.<ref name="PCASTLmain">{{cite web|access-date=2008-06-14 | url=http://www.pcosmos.ca/pcastl/|title=PCASTL: by Parent and Childset Accessible Syntax Tree Language |publisher=Philippe Choquette }}</ref>
==Hello world== The "[[Hello world program]]" is quite simple: <pre><nowiki> "Hello, world!" </nowiki></pre> or <pre><nowiki> print("Hello, world!") </nowiki></pre> will do the same.
==Syntax== The syntax of PCASTL is derived from [[programming languages]] [[C (programming language)|C]] and [[R (programming language)|R]]. The source of [[R (programming language)|R]] version 2.5.1 has been studied to write the [[Formal grammar|grammar]] and the [[lexical analyzer|lexer]] used in the PCASTL interpreter.
===Influences=== Like in [[R (programming language)|R]], statements can, but do not have to, be separated by [[semicolon]]s.<ref>{{cite web|access-date=2008-06-14|url=https://cran.r-project.org/doc/manuals/R-intro.html|title=An Introduction to R |publisher=R Development Core Team }}</ref> Like in [[R (programming language)|R]], a [[variable (programming)|variable]] can change type in a [[Session (computer science)|session]]. Like in [[C (programming language)|C]] and [[R (programming language)|R]], PCASTL uses balanced [[bracket]]s ('''{''' and '''}''') to make [[block (programming)|block]]s.
[[Operator (programming)|Operators]] found in PCASTL have the same [[Order of operations|precedence]] and [[Operator associativity|associativity]] as their counterparts in [[C (programming language)|C]].<ref name="PCASTLmain" /><ref>{{cite book | last=Hanly | first=Jeri R. | author2=Elliot B. Koffman | title=Problem Solving & Program Design in C, Third Edition | publisher=[[Addison-Wesley]] | year=1999 | isbn=0-201-35748-8 | url-access=registration | url=https://archive.org/details/problemsolvingpr00hanl_1 }}</ref> '''for''' loops are defined like in [[C (programming language)|C]]. <code>++</code> and <code>--</code> [[Operator (programming)|operators]] are used like in [[C (programming language)|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 <code>++</code> [[Operator (programming)|operator]]: <syntaxhighlight lang="c"> for (i = 1; i < 4; i++) print(i) </syntaxhighlight>
[[Subroutine|Functions]] and [[Comment (computing)|comments]] in PCASTL are defined like in [[R (programming language)|R]]: <syntaxhighlight lang="r"> # function definition (comment) a = function() { print("Hello, world!") }
# function call a() </syntaxhighlight>
===parent and childset reserved words===
Those [[reserved word]]s can only be written lowercase and will not be recognized otherwise. The '''parent''' reserved word gives a [[Reference (computer science)|reference]] to the parent node in the [[Abstract syntax tree|syntax tree]] of the code where the word is placed. In the following code, the parent node is the [[Operator (programming)|operator]] <code>=</code>.
<pre><nowiki> a = parent </nowiki></pre>
The [[variable (programming)|variable]] "a" will hold a [[Reference (computer science)|reference]] to the <code>=</code> node. The following code shows how to get [[Reference (computer science)|references]] to the two child nodes of the [[Operator (programming)|operator]] <code>=</code> with the '''childset''' [[reserved word]]. <pre><nowiki> a.childset[0] a.childset[1] </nowiki></pre>
To display the value of "a", some ways are given in this example: <pre><nowiki> a a.childset[0].parent a.childset[1].parent a.childset[0].parent.childset[0].parent # and so on... </nowiki></pre>
In the following code: we assign a code segment to the right child of the <code>=</code> node, we execute the <code>=</code> node a second time and we call the newly defined function. <pre><nowiki> a.childset[1] = `function() print("hello")' execute(a) a() </nowiki></pre>
==See also== {{Portal|Free and open-source software}} *[[Abstract syntax tree]] *[[Self-modifying code]]
==References== {{Reflist}}
==External links== *[http://www.pcosmos.ca/pcastl/ PCASTL: by Parent and Childset Accessible Syntax Tree Language]
{{FOSS}}
{{DEFAULTSORT:Pcastl}} [[Category:Free and open source interpreters]] [[Category:Procedural programming languages]] [[Category:Articles with example code]] [[Category:Programming languages created in 2008]]