Skip to content

Syntax and semantics

Victor Siqueira edited this page Jan 13, 2018 · 6 revisions

EM CONSTRUÇÃO

Basic Concepts

Variables

The variables work with optional typing similar to TypeScript, but with the possibility to use the types available through C# language.

Declaration and Assignment

types of scope

del

You can use 'del' to remove the variable, constants and objects from memory when you want, this is a cool and flexible Python resource that some other languages haven't. It increase your control, but remember that you have garbage collector to help you.

Syntax:

del <variable | constant | object>

Sample:

int number = 10
println(number)

del number
println(number)

# Output
> 10
> The variable 'b' was not declared.

null

To set a variable value as null in some languages, you can do it using the keyword 'nil' (ruby) or 'none' (python), but it's ugly and not objective, because when you think to set a null value you think in 'null' keyword. So Kymera use the key 'null' like C# to it.

Syntax:

<variable | constant | object> = null

Sample: int number = 42 println(number)

number = null
println(number)

# Output
> 42
> null

Console Output

To print something on console you can use the 'Console' class methods, that is 'print' and 'println'. This is based on Java and C#. The 'Console' class can be implicit.

  • Console.print - Just print a text in your console.
  • Console.println - Print a text in your console and break line.

Syntaxe:

Console.print(<value_to_print>)
Console.println(<value_to_print>)

Sample:

Console.print("Hello ")
Console.print("Universe!")

# Output
> Hello Universe!

Console.println("Hello ")
Console.println("Universe!")

# Output
> Hello 
> Universe!

or

print("Hello ")
print("Universe!")

# Output
> Hello Universe!

println("Hello ")
println("Universe!")

# Output
> Hello 
> Universe!

Console User Input

readKey readLine readLines readOptions

Comments

Exist two types of comments:

  • One-line comment - Use # or // to comment just actual line.

Sample:

# Commented line
// Other commented line
  • Multi line comment - Use /* to start a block comment line and use */ to end the comment block.

Sample:

/*
* This
* is
* commented!
*/

Constants

In Kymera constants can be declared explicitly with the keyword const than most languages.

Syntaxe:

const PI = <value>

Sample:

const PI = 3.141592653589793

or implicit form using a word that start with uppercase like Ruby Lang.

Note: We recommend that all characters must be in the upper case.

Syntaxe:

<CONSTANT NAME WITH UPPERCASE> = <value>

Sample:

PI = 3.141592653589793

Arithmetic Operators

Assignment & Increment Operators

Loops

Conditionals

if-else Statement switch Statement

switch(<expression>) {
    case <>:
        <commands>
        break
    case <>:
        <commands>
        break
    case <>:
        <commands>
        break
    default:
        <commands>
        break
}

while Loop while() { }

do-while Loop do { } while())

for Loop

break and continue

Logical Operators

Conditional Operator

Basic Calculator

Methods

Method Parameters

Multiple Parameters

Optional & Named Arguments

Passing Arguments

Method Overloading

Recursion

Making a Pyramid

Classes & Objects

Introduction

Value & Reference Types

Class Example

Encapsulation

Constructors

Properties

Arrays & Strings

Arrays

Using Arrays in Loops

Multidimensional Arrays

Jagged Arrays

Array Properties & Methods

Working with Strings

More On Classes

Destructors

Static Members

Static Classes

this & readonly

Indexers

Operator Overloading

Inheritance & Polymorphism

Inheritance

Protected Members

Derived Class Constructor & Destructor

Polymorphism

Abstract Classes

Interfaces

Nested Classes

Namespaces

Structs, Enums, Exceptions & Files

Structs

Enums

Exception Handling

Working with Files

Generics

Generic Methods

Generic Classes

Collections

Blocos serão por chaves {} da mesma forma que o C/C++, Dart, Go, Java, C# e JS usam, pois o uso de begin e end são desnecessários.

--Variáveis: ---A declaração é opcional assim como no GoLang. a //igual ao var, mas é de forma implícita. var a //simplesmente declara a variável como qualquer tipo smallint a int a float a double a char a string a bool a struct a dic a // a{ 'b' : 1; 'c' : 2} tuple a // a() array a // a[] // a const A enum a *ponteiro **ponteiro_de_ponteiro global int a

--Estruturas de repetição:

for elemento in elementos { //procedimento }

for (int x; x<10; x++) { //procedimento }

while ( x < y ) { //procedimento }

do { //procedimento } while ( x < y )

until( x < y ) { yield //procedimento

}

--Comentários:

#comentário de unica linha

//comentário de unica linha

/* comentário de */multiplas linhas

--Funções: func correr (var a) { //faz algo return algo } .sucess { } .error { } .then { } .catch { } .finally { }

funcao () { //do anything }

--Tratamento de erros try{ } execept { } finally { }

--Fluxo

if (condição) { } else { }

if (condicao 1) { } elif { }

switch (valor) { case 1: //faça x //break não é necessário case 2, 3: default: }

unless (condicao) { }

label a goto a

--Orientação a objetos: class Animal { constructor(var a, var b) { this.a = a this.b = b }

func voar () { } }

class Cachorro extends Animal, Outro { }

class Gato implements Animal, Outro { super(a) //permite sobrescrita de métoco }

gato = Gato(var a, var b) //instanciação

static class Veiculo { }

abstract class Veiculo {

}

--Documentação: doc ('texto documentado') //receber um texto simples, caso precise de muitas linhas, passe como parâmetro um arquivo txt.

--Modificadores de acesso: ---em class, os atributos são privados e métodos são privados por padrão. funções em geral são públicas. ---public: blabla ---private: blabla ---protected: blabla

--Métodos padrão

map () lambda () int(), str(), double(), float(), ... find_one() find_all() exist() empty()

--Operadores aritimético

^ / %

--Operadores lógico

<=

= === or // || and // && xor nor // !|| nand // !&& not // !

--Operadores de atribuição:

funções: -pass

Clone this wiki locally