Movatterモバイル変換


[0]ホーム

URL:


Jump to content
Rosetta Code
Search

Category:Ya

Help
From Rosetta Code
Language
Ya
Thisprogramming 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 onC++ and gets most ofC++ as is. Yet there is no compatibility withC++,C++ program is not aYa program and cannot be compiled as is.

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

Example: Hello World

@HelloWorld.Ya;using <stdio.h>;$int($char[][] args) mainprintf("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 inPython. But blocks made insingle 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 statementusing @module, @module; so separate header and implementation for a module does not used, becauseusing @module; gets interface of module into work but not implementation details.
  • In Ya there are no project files. Each Ya project hasmain orstarting source that is specified for compiler on command line to compile. Main source includesusing @module, @module; so that all required modules will be included and compiled. As a result a separate project file is not required.

Double compilation akaMetaprogramming

  • 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 namedmetaprogramming in theory of languages.

Extensible syntax

  • New statements maybe described. For example it's possible to add statementforeach 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 like10:53:17 - addition of a new kind of constant is described asregular 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 namedouble 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 performjoin where sortby of SQL. In C# it is namedLanguage 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 namea orb orc.

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*;
  • Keywordclass is not used. Instead you just write!any $myClass { body of structure-class }
  • Description of type properties, for example 'pointer to type', areall writtenafter the type name, and all properties are specified by signs. Example:$int+-*- means in C++const unsigned int* const, here+ meansunsigned and- meansconst.
  • 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 likeconst 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 ofint **A, **B, **C;. Description becomes shorter, yet there is no way to defineint 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 ini = 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 ofC++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:
switch10-50..3,7printf("Wow! It's 0,1,2,3 or 7\n");5printf("Simple case!\n");elseprintf("default is written as default or else.\n");

Each case starts withoutcase and: after case values is not written. Case values can include many values and also rangesvalue..value, like in0..3,7 - this case works for 0,1,2,3 or 7. Also no need to writebreak; 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 thencontinue; 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 in1+2 and 1 space in2 *
  • enum is extended: they are not onlyint but of any type, the type is specified. Example:
!any$StringEnumenum$char[]Str1="lala",Str2="bebe"!any$ErraTypeenum$int+:8// i.e. they are unsigned byteseFatal,eErr,eWarn,eMess,

Pages in category "Ya"

This category contains only the following page.

Retrieved from "https://rosettacode.org/wiki/Category:Ya?oldid=246336"
Categories:
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

[8]ページ先頭

©2009-2026 Movatter.jp