Good time to read, dear readers habrahabr.ru
For teaching programming offered hundreds of languages, including the management of graphic elements. Therefore, the proposal of a new language for learning requires additional justification.
Let me try to describe the advantages of the proposed programming language for programming (the working title is PL / 2) and for the programming of games (the working name for the PL / 2 script), and I suggest finding the shortcomings in the approach.
')
The main paradigms are as follows:
Assembly code to control the processor
Logical programming represented by Prolog, SQL
Functional programming
Imperative programming described by algorithms
Object programming consisting in the transmission and processing of signals
Currently, these techniques are combined in extensions of existing programming languages. An approach is proposed for combining paradigms in a single syntax that resolves conflicts between different approaches in advance, which will reduce the time spent on learning various syntaxes.
So, the key elements of the educational programming language.
Source text
The source text file consists of arbitrary text (comments, algorithm description), which may include [named] fragments in various programming languages ββ- PL / 2, sql, html, text, PL / 2 script.
the beginning of the insertion of the code is indicated by the
meta keyword (meta) in the first position of the line
the end of the insertion is indicated by the sequence
/ meta in the first position of the line
The PL / 2 syntax includes uniform indentation requirements, in particular, the program text is shifted at least 4 positions from the beginning of the line.
Program text structure
The size of the shift between the levels of nesting is 4 spaces. Operator continuation on the next line is shifted by at least 3 spaces relative to the operator level
The main level of the program is shifted by 4 spaces relative to the markup symbol of the source
meta file; accordingly, no single character of the program can have an indent of less than 4 spaces
Syntax
For different types of blocks, different types of brackets are assumed:
parentheses (...) are used to describe and pass parameters when calling methods
square brackets [...] are used to describe the dimension of arrays and specify an index when accessing an array element.
curly braces {...} are used to specify various elements of the program structure. For error localization, braces are supplied with additional characters.
{- ... -} - analogue of parentheses - used in the description of the body of the relational class
{# ... #} - used when describing the body of a function block
{$ ... $} - outer framing brackets when describing a structure class constant
{* ... *} - description of the body of the class or interface
{& ... &} - description of the method body
{@ ... @} - namespace body
{| ... |} - concurrent blocks
{% ...%} - controlled block
{= ... =} - class of responsibility
{...} - internal block in the method body
Operators
== =/= := ++ -- + - * / -/- ( , .. IDE) (? boolean ? value_true :: value_false ?) -
Imperative programming
The following syntax is proposed for structured programming:
Operators enclosed between brackets {& and &} are executed sequentially in the order specified in the program text.
To change the order of execution, use the loop and branch operators
fulfillment of the condition
if (){ ... }
block execution when the first condition is met and the else block when none of the conditions is met
decision{ if (<1>) ... if (<2>) ... else ... }
numeric value switch with indication of constant or enumeration member
switch (<>){ case <1>: ... case <2>: ... else ... }
In expressions, you can also use the ternary selection operator
Cycle operator
loop [explicit] [] { for <[] [ := ]>; from <>; while <, >; next < >; where < > ... continue; ... break [ ]; ... }
Here:
loop - loop start operator
explicit - the loop is executed at least once, the condition for leaving the loop before the first pass is not checked
for - list of loop variables and their initialization
while - the condition under which the loop continues to iterate
next - commands executed after iteration
from - the container from which the elements are selected when passing through the cycle
where is the condition for executing the loop body
continue - the operator of early transition to the next iteration
break - early exit operator from the current or specified cycle
Error processing
management of transactions and areas with the possibility of failure
transaction{ finalize { } catch { } { throw
Object oriented programming
new - create a new object
drop - delete an object
work with collections
select
:: = - getting information about the collection's named objects
insert
+ = - the inclusion of a new object in the collection
delete
- = - remove an object from the collection
update - multiple updates in the collection
management of the rights of object actions over objects of the specified class or its properties / methods
grant
+ = - assign object permission rights to a class or property
deny
+ = - assign prohibition rights to an object on a class or property
revoke - remove object rights to the class
Types of classes
Classes are divided into the following types:
- domain class - elementary runtime class
- The relation class is a relationship between the specified objects (similar to the Prolog clauses, a list of function parameters), methods and properties are missing, access occurs only to public members. The possibilities are similar to those returned from the relational database.
- structure class - a structure with open elements. To access an element of the current object, the word this is used. May contain methods for processing.
- system class is a system that can contain private and protected inherited elements.
- The process class is a process to which you can pass initialization values ββand get the resulting values. Corresponds to the service. Any method receives not only a pointer to itself ( this ), but also a pointer to the class or object ( sender ) that caused it. This allows you to check the authorization of the object accessing the method. Contains standard methods.
Not imperative programming
operators of work with lambda expressions and lists
- :: = - definition of expression disclosure
- |> - pipeline for all elements from the left collection, specified by the right expression
quantifiers of existence and universality on ordered lists
- &> Is a collection of all elements from the left collection that satisfy the right expression.
- !> - pipeline for all elements from the left collection that do not satisfy the specified right expression
- %> - collection from the first element from the left collection, satisfying the right expression (arithmetically - the remainder of division)
- ~> - all elements of the list, except the first, that satisfy the right condition
- $> - a collection of all the elements from the left list, except the last, which satisfies the given right expression
- ?> - collection from the last element from the left list that matches the specified right expression
eg,
head :: =
%> (\ true),
tail :: =
~> (\ true)
Assembler
The processor class is used, the arguments of which methods are the arguments of the assembler commands, and the properties are the registers of the processor core.
This approach allows the use of inheritance, as a transition to a new generation of the processor line, as well as using the full names of commands instead of short mnemonics and the possibility of equal description in help systems.
Hallo, world
hallo.pl2 program default.Default.Main() meta source="pl2" name="example2" using user.OS.IO;
PL / 2 script
The PL / 2 script language provides the ability to describe scripts and extend classes while describing a variable for programming games.
Instead of a functional variable, it is proposed to use a string that (as in Excel) starts with an equal sign.
In this case, the description of classes and objects is conveniently stored in XML, and the code used for active processing.
Class Description:
<?xml version="1.0" encoding="windows-1251"?> <pl2script> <type id="type.class.Scene" save="true"> <help id="class.Scene.help">pl2script/game/scene.htm</help> <system> <class id="class.Scene" domain="type" save="true"> <name> <ascii>Scene</ascii> <local></local> </name> <tip id="class.Scene.tip"> <ascii>Game class as a main class for a game</ascii> <local> </local> </tip> </class> <property id="class.Scene..." domain="string" save="true"> <name> <ascii>prop ...</ascii> <local>prop ...</local> </name> <tip id="class.Scene..tip"> <ascii>tip ...</ascii> <local> ...</local> </tip> </property> </system> </type> </pl2script>
Description of the object:
<?xml version="1.0" encoding="windows-1251"?> <pl2script> <scene id="game."> <name></name> <description> </description> <message> </message> <way id="game.universe" path="Universe/index" enabled="true"></way> <way id="game.solar" path="Solar/index" enabled="true"> </way> <way id="game.earth" path="Earth/index" enabled="true"></way> <way id="game.country" path="country/index" enabled="true"> </way> <way id="game.body" path="body/index" enabled="true"> </way> <way id="game.nature" path="nature/index" enabled="true"> </way> <way id="game.school" path="school/index" enabled="true"> </way> <way id="game.plant" path="plant/index" enabled="true"> </way> <way id="game.university" path="university/index" enabled="true"> </way> </scene> </pl2script>
I ask to speak about the problems possible when using this syntax
References:
habrahabr.ru/post/136272 What programming language should be the first when studying at school?
habrahabr.ru/post/176243 "National" programming languages
Project -
github.com/palexisru/pl2_rus/wikiThanks to
oeai for the link to the INSTEAD project and the Lua language