PCASTL

Last updated
PCASTL
Paradigm imperative, reflective
Designed by Philippe Choquette
Developer Philippe Choquette
First appeared2008;15 years ago (2008)
Stable release
3.5 / March 31, 2018;5 years ago (2018-03-31)
OS Cross-platform
License GNU Lesser General Public License
Website www.pcosmos.ca/pcastl/
Influenced by
C, R

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]

Contents

Hello world

The "Hello world program" is quite simple:

"Hello, world!" 

or

print("Hello, world!") 

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 ({ and }) to make blocks.

Operators found in PCASTL have the same precedence and associativity as their counterparts in C. [2] [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:

# function definition (comment) a = function() {    print("Hello, world!") }  # 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 =.

a = parent 

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.

a.childset[0] a.childset[1] 

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

a a.childset[0].parent a.childset[1].parent a.childset[0].parent.childset[0].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[1] = `function() print("hello")' execute(a) a() 

See also

Related Research Articles

Applesoft BASIC is a dialect of Microsoft BASIC, developed by Marc McDonald and Ric Weiland, supplied with the Apple II series of computers. It supersedes Integer BASIC and is the BASIC in ROM in all Apple II series computers after the original Apple II model. It is also referred to as FP BASIC because of the Apple DOS command used to invoke it, instead of INT for Integer BASIC.

C is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems, device drivers, protocol stacks, though decreasingly for application software. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.

Icon is a very high-level programming language based on the concept of "goal-directed execution" in which code returns a "success" along with valid values, or a "failure", indicating that there is no valid data to return. The success and failure of a given block of code is used to direct further processing, whereas conventional languages would typically use boolean logic written by the programmer to achieve the same ends. Because the logic for basic control structures is often implicit in Icon, common tasks can be completed with less explicit code.

<span class="mw-page-title-main">Pascal (programming language)</span> Programming language

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named in honour of the French mathematician, philosopher and physicist Blaise Pascal.

In a computer language, a reserved word 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 reserved word may have no user-defined meaning.

In computer science, pattern matching is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually has to be exact: "either it will or will not be a match." The patterns generally have the form of either sequences or tree structures. Uses of pattern matching include outputting the locations of a pattern within a token sequence, to output some component of the matched pattern, and to substitute the matching pattern with some other token sequence.

bc, for basic calculator, is "an arbitrary-precision calculator language" with syntax similar to the C programming language. bc is typically used as either a mathematical scripting language or as an interactive mathematical shell.

thinBasic is a BASIC-like computer programming language interpreter with a central core engine architecture surrounded by many specialized modules. Although originally designed mainly for computer automation, thanks to its modular structure it can be used for wide range of tasks.

The syntax of JavaScript is the set of rules that define a correctly structured JavaScript program.

A class in C++ is a user-defined type or data structure declared with keyword class that has data and functions as its members whose access is governed by the three access specifiers private, protected or public. By default access to members of a C++ class is private. The private members are not accessible outside the class; they can be accessed only through methods of the class. The public members form an interface to the class and are accessible outside the class. #line is used to determine the number of lines in given file.

In computer programming, homoiconicity is a property of some programming languages. A language is homoiconic if a program written in it can be manipulated as data using the language, and thus the program's internal representation can be inferred just by reading the program itself. This property is often summarized by saying that the language treats code as data.

The syntax of the Python programming language is the set of rules that defines how a Python program will be written and interpreted. The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages.

This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.

The syntax and semantics of PHP, a programming language, form a set of rules that define how a PHP program can be written and interpreted.

The Perl virtual machine is a stack-based process virtual machine implemented as an opcodes interpreter which runs previously compiled programs written in the Perl language. The opcodes interpreter is a part of the Perl interpreter, which also contains a compiler in one executable file, commonly /usr/bin/perl on various Unix-like systems or perl.exe on Microsoft Windows systems.

The structure of the Perl programming language encompasses both the syntactical rules of the language and the general ways in which programs are organized. Perl's design philosophy is expressed in the commonly cited motto "there's more than one way to do it". As a multi-paradigm, dynamically typed language, Perl allows a great degree of flexibility in program design. Perl also encourages modularization; this has been attributed to the component-based design structure of its Unix roots, and is responsible for the size of the CPAN archive, a community-maintained repository of more than 100,000 modules.

In computer programming, a function or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed.

Idris is a purely-functional programming language with dependent types, optional lazy evaluation, and features such as a totality checker. Idris may be used as a proof assistant, but it is designed to be a general-purpose programming language similar to Haskell.

Swift is a high-level general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. and the open-source community. First released in June 2014, Swift was developed as a replacement for Apple's earlier programming language Objective-C, as Objective-C had been largely unchanged since the early 1980s and lacked modern language features. Swift works with Apple's Cocoa and Cocoa Touch frameworks, and a key aspect of Swift's design was the ability to interoperate with the huge body of existing Objective-C code developed for Apple products over the previous decades. It was built with the open source LLVM compiler framework and has been included in Xcode since version 6, released in 2014. On Apple platforms, it uses the Objective-C runtime library, which allows C, Objective-C, C++ and Swift code to run within one program.

<span class="mw-page-title-main">Nim (programming language)</span> Programming language

Nim is a general-purpose, multi-paradigm, statically typed, compiled high-level systems programming language, designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant", supporting metaprogramming, functional, message passing, procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C, C++, Objective-C, and JavaScript, and supporting compiling to those same languages as intermediate representations.

References

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