From Rosetta Code
(Redirected from Ya)
This programming language may be used to instruct a computer to perform a task.
Official website
Execution method: Compiled (machine code)
Garbage collected: No
Parameter passing methods: By reference, By value
Type safety: Safe, Unsafe
Type strength: Strong
Type compatibility: Nominative, Structural
Type expression: Explicit
Type checking: Dynamic, Static
Lang tag(s): Ya
See Also:

Listed below are all of the tasks on Rosetta Code which have been solved using Ya.

Ya (pronounced /jˈʌ/) is based on 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.

Ya adds to C++ extensible syntax, extensible lexical tokens, possibility to execute parts of compiling program during it's compilation (metaprogramming), support for SQL-like operations for processing databases and database-like internal data, and many small improvements over C++.

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 start of lines

Tabs at start of line are counted and used for specifying code blocks {...}, like in Python. But blocks made in single line with { and } are also supported. Typical Ya program has near to no one { and }.

Modules, ala #define and no project file

  • Named modules: @FileName; at the start of each compiled file. Modules are always named starting by @ and module name is module's file name. Example: @C:/S/Ya/YaParser.Ya;
  • Header files are not used. Instead it is the statement using @module, @module; so separate header and implementation for a module does not used, because using @module; 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 using @module, @module; 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 foreach 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 operator, let's name it <=>, which makes such kind of comparison.
    • Let's <-> will notify exchange of values of variables (swap). Usage: $int i,j; i <-> j;
  • Possibility to make other new constants
    • For example time is typically written like 10:53:17 - addition of a new kind of constant is described as 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 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 join where sortby of SQL. In C# it is named Language Integrated Query.

Multiple names for any entity

Variables, functions, types and template argument requirements all may be named by a number of names. No need to use #define instead. Example: $int a b c = 100; - here you can use this variable by name a or b or c.

Description of types

  • Any type name is started by $ and type name must go after $ without spaces - it's a single token.
  • All additions to type like pointer * are written without spaces also.
  • All types are considered classes, for example it is possible to inherit from $int.
  • New types are described like here: !any $constint = $int-; !any $PtrToInt = $int*;
  • Keyword class is not used. Instead you just write !any $myClass { body of structure-class }
  • Description of type properties, for example 'pointer to type', are all written after the type name, and all properties are specified by signs. Example: $int+-*- means in C++ const unsigned int* const, here + means unsigned and - means const.
  • No references &, only pointers * are used. References in C++ is a side-effect feature and is of value only because no need to write * 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 keywords like const unsigned signed all have gone.
  • If you need to define a number of vars of the same type, for example $int**, then you write $int** A, B, C; instead of int **A, **B, **C;. Description becomes shorter, yet there is no way to define int A, *B; in 1 statement, 2 statements are required: $int A; $int* B;.

Many small improvements in the base of C++

  • Work with pointers is simple, no need to dereference or getting address, all this is automatically inserted. Example: $int** ptrptr; $int i = ptrptr; - here in i = ptrptr; is automatic double dereferencing a pointer.
  • Specification of new or old operators for some type is made simple, for example $T* $T* a = $T* b; specifies assignment for type $T. 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++11. This specifications are named !SomeName, for example !any in type definitions above means that specified type has no requirements. Example of requirements definition: #template != { $* $* a = $* b; } specifies that != types must have assignment operator $* $* a = $* b;
  • for statement: for InitExprOrVarDef; ConditionExpr; IncExpr { BodyOfLoop } - 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++. if while do while switch are all the same - everywhere no () and body of statement is block.
  • switch statement example:
switch 10-5
		printf("Wow! It's 0,1,2,3 or 7\n");
		printf("Simple case!\n");
		printf("default is written as default or else.\n");

Each case starts without case and : after case values is not written. Case values can include many values and also ranges value..value, like in 0..3,7 - this case works for 0,1,2,3 or 7. Also no need to write break; 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 continue; may be used - it jumps to the body of next case.

  • break; - breaking from loops and switches is enchanced, it is possible to break from many loops+switches in 1 step. Example: for ;; { for ;; { switch 7 { 0..3,7 { break for for switch; }}}}
  • Operator precedence in expressions: in Ya spaces around operator are counted and it's used for defining precedence. Example: 1+2 * 3; - it's (1+2) * 3; because no spaces in 1+2 and 1 space in 2 *
  • enum is extended: they are not only int but of any type, the type is specified. Example:
!any $StringEnum enum $char[]
	Str1 = "lala", Str2 = "bebe"
!any $ErraType enum $int+:8 // i.e. they are unsigned bytes
	eFatal, eErr, eWarn, eMess,

Pages in category "Ya"

This category contains only the following page.