P*

From HandWiki
P*
Logo of the P* Web Programmin Language project.png
Designed byAtle Solbakken
First appeared2013
Typing disciplineStatic, weak
OSCross-platform (multi-platform)
LicenseGPLv3
Filename extensions.pstar or no extension
Websitewww.p-star.org
Influenced by
C, PHP, Perl, C++

P* (pronounced "P-star") is a programming language meant to be useful in web development for creating dynamic HTML documents. The language provides syntax for templates and prepared SQL-statements. P* programs are scripts which are run by the P* interpreter.

Syntax

The syntax is inspired from other C-family languages. Program Blocks starts with the open curly bracket { and ends with the close curly bracket }.

Scenes and templates

The code of a P* program is placed into scenes [1], and the HTML markup is typically placed inside templates. A scene is a special type of function which does not take arguments. All programs must provide exactly one scene called 'main', which is the first to run by the interpreter.

A small P* web page, where the code for the program sits inside the scene called 'main' and the HTML markup is put inside a template, can look like this:

HTML_TEMPLATE body {
     <!DOCTYPE html>
     <html>
     <head><title>Hello world web page</title></head>
     <body>
     <p>{@text}</p>
     </body>
     </html>
 }
 SCENE main {
     string text = "Hello World!";
     #CONTENT_TYPE text/html;
     #HTML_TEMPLATE body;
 }

When scenes and templates in P* are called, the callee inherits all variables which is available from where the call is made. This is opposed to when functions are called, where only a set of parameters is passed.

Data types

P* provides eight basic types [2] for storing data in variables. All variables is required to have a type, but P* automatically converts between them.

In the following example program, one variable, int a, is assigned the value 2, and another variable, string b is assigned the text string "3". When the operator + is run, the left associativity of the operator will lead to an implicit conversion of the right argument to the same type as the left side (type int) before the addition is performed.

SCENE main {
     int a = 2;
     string b = "3";
     echo "The sum is " . (a + b) . "\n";
 }

Implementation

P* programs are run by the P* interpreter. A typical way to run scripts is to include a shebang on the first line of the scripts (like #!/usr/bin/wpl -f) and execute the scripts from the shell, or placing the scripts inside CGI-configured directories of a webserver. An interpreter module for the Apache web server is also available.