commit 9904b35d973b31746d69f081a1ccaac02a31dcc2 Author: Rafal Kupiec Date: Tue Jul 17 07:39:44 2018 +0200 Update page 'P# 1.0 Draft Specification' diff --git a/P%23-1.0-Draft-Specification.md b/P%23-1.0-Draft-Specification.md new file mode 100644 index 0000000..077ba14 --- /dev/null +++ b/P%23-1.0-Draft-Specification.md @@ -0,0 +1,76 @@ +## 1. Introduction +The P# language specification is the definitive source for P# syntax and usage. This specification contains detailed information about all aspects of the language. + +As the definition of P# evolved, the goals used in its design are as follows: +* P# is intended to be a simple, modern, general-purpose, object-oriented scripting language. +* The language, and implementations thereof, should provide support for software engineering +principles such as strong type checking, detection of attempts to use uninitialized variables, and automatic garbage collection. +* The language is intended for use in developing web sites and and scripts< suitable for deployment in any, including embedded environments. +* P# is intended to be suitable also for writing scripts for embedded systems. +* Source code portability is very important, especially for those programmers already familiar with PHP and/or C++. + +## 2. Scope +This specification describes the form and establishes the interpretation of programs written in the P# scripting language. It describes: +• The representation of P# programs; +• The syntax and constraints of the P# language; +• The semantic rules for interpreting P# programs; + +## 3. Lexical structure +A P# script consists of one or more source files. A source file is an ordered sequence of UTF-8 characters, what means that any UTF-8 encoded natural language (i.e: Japanese, Chinese, Arabic, etc.) can be used for writing scripts. Source files typically have a one-to-one correspondence with files in a file system. + +### 3.1. Comments +Two forms of comments are supported: delimited comments and single-line comments. A delimited comment begins with the characters /* and ends with the characters */. Delimited comments can occupy a portion of a line, a single line, or multiple lines. A single-line comment begins with the character # or characters // and extends to the end of the line. +Comments do not nest. The character sequences /* and */ have no special meaning within a single-line comment, and the character sequences #, // and /* have no special meaning within a delimited comment. +Example: + + # This is a single line comment + // This is another single line comment + /* This is a + multi-line comment block */ + +### 3.2. White space +White space is defined as any character with Unicode class Zs (which includes the space character) as well as the horizontal tab character, the vertical tab character, and the form feed character. White space in P# is used to separate tokens in P# source file. It is used to improve the readability of the source code. The amount of space put between tokens is irrelevant for the P# interpreter. It is based on the preferences and the style of a programmer. Two statements can be put into one line, as well as one statement into several lines. Source code should be readable for humans and makes no difference to the Interpreter. + +### 3.3. Tokens +There are several kinds of tokens: identifiers, keywords, literals, operators, and punctuators. White space and comments are not tokens, though they act as separators for tokens. + +#### 3.3.1 Literals +A literal is any notation for representing a value within the PHP source code. Technically, a literal is assigned a value at compile time, while a variable is assigned at runtime. P# supports: + * boolean literal (can be true or false), + * integer literal (can be decimal and hexadecimal), + * real literal (used to write values of float type), + * character literal (represents a single character), + * string literal (zero or more characters enclosed in single or double quotes), + * NULL literal (represents a null value) + +#### 3.3.2 Operators and punctators +An operator is a symbol used to perform an action on some value + ++ - * / % ++ -- += += -= *= /= .= %= +== != >< > < >= <= +&& || ! & ^ ^^ | +~ . << >> , :: ( +) [ ] { } -> : +? + +#### 3.3.3 Keywords +A keyword is a reserved word in the P# language. Keywords are used to perform a specific task in a computer program; for example, print a value, do repetitive tasks, or perform logical operations. A programmer cannot use a keyword as an ordinary variable. + +Available keywords: as, break, case, catch, class, clone, const, continue, default, do, else, elseif, extends, final, for, foreach, if, implements, interface, instanceof, namespace, new, private, protected, public, static, switch, throw, try, using, virtual, while + +Next we have other language constructs: define() empty(), exit(), eval(), include(), include_once(), isset(), list(), require(), require_once(), return(), print(), unset() + +#### 3.3.4 Semicolon +A semicolon is used to mark the end of a statement in P# language. It is mandatory. + +#### 3.3.5 P# Variables +A variable is an identifier, which holds a value. In programming we say that we assign a value to a variable. Technically speaking, a variable is a reference to a computer memory, where the value is stored. In P# language, a variable can hold a string, a number, or various objects like a function or a class. Variables can be assigned different values over time. Variables in P# consist of the $ character, called a sigil, and a label. A label can be created from alphanumeric characters and an underscore _ character. A variable cannot begin with a number. + +#### 3.3.6 P# Constants +A constant is an identifier for a value which cannot change during the execution of the script. Constants are created with the define() function. Constants differ from variables; we cannot assign a different value to an existing constant. + +## 4. Basic concept +All the P# code is surrounded by two delimiters, <% and %>. Everything behind these two delimiters is considered as text and output to stdout. Thanks to that P# code can be easily placed into HTML code. + +### 4.1 \ No newline at end of file