http://Ya-Lang.com . Designed and made by Pavel Senatorov, see Ya-Lang.com for emailing.
Ya is based on CeePlusPlus (C++) and gets most of C++ as is. Yet there is no compatibility with C++, C++ program is not a Ya program and cannot be compiled as is. Anyway it's
- imperative (not functional by design by functional programming somehow supported)
- object-oriented (i.e. with classes+methods)
- generic (i.e. with templated classes+functions)
Main news in comparison with C++:
- metaprogramming, named here as double compilation because parts of program being compiled are executed while compiling.
- extensible syntax - new statements possible.
- extensible lexics - new operators for expressions and new constants for new types possible.
- support for database queries - like operations in SQL.
Appeared at 2012.
Works only in Windows for now.
== Example: Hello World ==
@HelloWorld.Ya;
using <stdio.h>;
$int($char[][] args) main
printf("Hello, %s!\n", args.Length > 1 ? args[1] : "World");
return 0;
== Basics of Ya ==
=== Block structure is described by tabs at starts of lines ===
Tabs at start of line are counted and used for specifying code blocks <code>{...}</code>, like in [[Python]]. But blocks made in single line with <code>{</code> and <code>}</code> are also supported. Typical Ya program has near to no one <code>{</code> and <code>}</code>.
=== Modules, ala #define and no project file ===
- Named modules: <code>@FileName?;</code> at the start of each compiled file. Modules are always named starting by <code>@</code> and module name is module's file name. Example: <code>@C:/S/Ya/YaParser?.Ya;</code>
- Header files are not used. Instead it is the statement <code>using @module, @module;</code> so separate header and implementation for a module does not used, because <code>using @module;</code> gets interface of module into work but not implementation details.
- In Ya there are no project files. Each Ya project has main or starting source that is specified for compiler on command line to compile. Main source includes <code>using @module, @module;</code> so that all required modules will be included and compiled. As a result a separate project file is not required.
=== Double compilation aka [[Metaprogramming]] ===
- While compiler compiles, parts of the compiling program could be executed.
- It's required for extending Ya syntax, lexical tokens and to perform optimizations, with optimizer being written in the program being compiled.
- This feature is named [[metaprogramming]] in theory of languages.
=== Extensible syntax ===
- New statements maybe described. For example it's possible to add statement <code>foreach</code> for newly written type of a container.
- New nonterminals: Maybe it will be possible to add to language syntax even a new nonterminal and rules for using it.
=== Extensible lexical tokens ===
- Possibility to add new operators to expressions. Examples:
- For sortings it's required comparison result of lesser or equal or bigger and it's possible to add new operation, let's name it <code><=></code>, which makes such kind of comparison.
- Let's <code><-></code> will notify exchange of values of variables (swap). Usage: <code>$int i,j; i <-> j;</code>
- Possibility to make other new constants
- For example time is typically written like <code>10:53:17</code> - addition of a new kind of constant is described as [[regex|regular expression]] and the code for transforming of text of new constant into required type the programmer writes on Ya. Note that this code will be executed at compile time, not run time. So this feature requires what they name [[metaprogramming|double compilation]]. Making new constants not yet ready.
=== Support for databases and internal structures like databases ===
It will probably be done as library. It will be possible to write expression that works with a number of tables, which are sets (f.e. arrays, lists) of fielded type (of class), and perform
<code>join where sortby</code> of SQL. In C# it is named
[[Language Integrated Query]].
=== Multiple names for any entity is allowed ===
Variables, functions, types and template argument requirements all may be named by a number of names. No need to use
<code>#define</code> instead. Example:
<code>$int a b c = 100;</code> - here you can use this variable by name
<code>a</code> or
<code>b</code> or
<code>c</code>.
=== Description of types ===
- Any type name is started by <code>$</code> and type name must go after <code>$</code> without spaces - it's a single token.
- All additions to type like pointer <code>*</code> are written without spaces also.
- All types are considered classes, for example it is possible to inherit from <code>$int</code>.
- New types are described like here: <code>!any $constint = $int-; !any $PtrToInt? = $int*;</code>
- Keyword <code>class</code> is not used. Instead you just write <code>!any $myClass { body of structure-class }</code>
- Description of type properties, for example 'pointer to type', are all written after the type name, and all properties are specified by signs. Example: <code>$int+-*-</code> means in C++ <code>const unsigned int* const</code>, here <code>+</code> means <code>unsigned</code> and <code>-</code> means <code>const</code>.
- No references <code>&</code>, only pointers <code>*</code> are used. References in C++ is a side-effect feature and is of value only because no need to write <font class=cpp>*</font> to dereference a reference. But the same is with pointers in Ya, even more, see below.
- That makes type description much more short. But it's required to learn the type signs, because words like <code>const unsigned signed</code> all have gone.
- If you need to define a number of vars of the same type, for example <code>$int**</code>, then you write <code>$int** A, B, C;</code> instead of <code>int **A, **B, **C;</code>. Description becomes shorter, yet there is no way to define <code>int A, *B;</code> in 1 statement, 2 statements are required: <code>$int A; $int* B;</code>.
=== Many small changes in the base of C++ ===
- Work with pointers is simple, no need to dereference or getting address, all this is automatically inserted. Example: <code>$int** ptrptr; $int i = ptrptr;</code> - here in <code>i = ptrptr;</code> is automatic double dereferencing a pointer.
- Specification of new or old operations for some type is made simple, for example <code>$T* $T* a = $T* b;</code> specifies assignment for type <code>$T</code>. Both args and return type are specified as pointers - this is because there are no references and because working with pointers is simple, no need to dereference or getting address, all this is automatically inserted.
- Specification of requirements for template args are added, like a not included feature of C++ 2011. This specifications are named <code>!SomeName?</code>, for example <code>!any</code> in type definitions above means that specified type has no requirements. Example of requirements definition: <code>#template != { $* $* a = $* b; }</code> specifies that <code>!=</code> types must have assignment operation <code>$* $* a = $* b;</code>
- <code>for</code> statement: <code>for InitExprOrVarDef?; ConditionExpr?; IncExpr? { BodyOfLoop? }</code> - so 1.parenceses not used, 2.body of loop is always in {} - typically it means that body of loop is on next lines and is 1 tab right shifted. All other is the same as in C++. <code>if while do while switch</code> are all the same - everywhere no () and body of statement is block.
- <code>switch</code> statement example:
<source lang="c">
switch 10-5
- .3,7
printf("Wow! It's 0,1,2,3 or 7\n");
-
printf("Simple case!\n");
else
printf("default is written as default or else.\n"); }}
</source>
- each case starts without <code>case</code> and <code>:</code> after case values is not written. Case values can include many values and also ranges <code>value..value</code>, like in <code>0..3,7</code> - this case works if switched with 0,1,2,3 or 7. Also no need to write <code>break;</code> to break out of case - it is automatically included at the end of a case. But if it's required to continue on next case then <code>continue;</code> may be used - it jumps to the body of next case.
- <code>break;</code> - breaking from loops and switches is enchanced, it is possible to break from many loops+switches in 1 step. Example: <code>for ;; { for ;; { switch 7 { 0..3,7 { break for for switch; }}}}</code>
- Operator priorities in expressions: in Ya spaces around operation are counted and it's used for defining priorities. Example: <code>1+2 * 3;</code> - it's <code>(1+2) * 3;</code> because no spaces in <code>1+2</code> and 1 space in <code>2 *</code>
- <code>enum</code> is extended: they are not only <code>int</code> but of any type, the type is specified. Example:
<source lang="c">
!any $StringEnum
? enum $char[]
Str1 = "lala", Str2 = "bebe"
!any $ErraType
? enum $int+:8 // i.e. they are unsigned bytes
eFatal, eErr, eWarn, eMess,
</source>
CategoryProgrammingLanguage