Skip to content

Latest commit

 

History

History
225 lines (185 loc) · 4.34 KB

docs.md

File metadata and controls

225 lines (185 loc) · 4.34 KB

Ncodi Programming Language Documentation

Table of Contents

  1. Getting Started
  2. Variables
  3. Types
  4. Operators
  5. Conditionals
  6. Loops
  7. Functions

Getting Started

Installation

Windows Installation

  1. Download the file from here
  2. Update your path:
    • From the Start search bar, enter 'env' and select "Edit environment variables for your account"
    • Under User variables, check if there is an entry called Path
    • If the entry exists, append the full path to desiredNcodiFolder\ using ; as a separator from existing values
    • If the entry doesn't exist, create a new user variable named Path with the full path to desiredNcodiFolder\ as its value

Linux Installation

Coming soon...

Hello World

To print something to the console, use the ekteb() function:

ekteb("Hello, Tunisia!")

Variables

Variables store data for later use. Think of them as containers with a name and a value.

var x = "Hello again"
ekteb(x)

Constant variables (const) cannot be changed after declaration:

const x = "No Name"
x = "Ncodi"  // This will result in an error

Types

Ncodi supports several data types:

Int

Integers are whole numbers, positive or negative:

var num1 = 458
var num2 = 15
ekteb(num1 + num2)

Decimal

Decimals are numbers with a floating point:

var dec = 4.25
ekteb(dec)

String

Strings are textual data enclosed in quotation marks:

var s = "Code in your own words"
var x = "51"  // This is a string, not an integer
ekteb(s)

Bool

Boolean values can be either s7i7 (true) or ghalet (false):

var res = s7i7
var nope = ghalet
ekteb(res)

Type Declaration

You can specify the type of a variable when declaring it:

var num:int = 1564
var dec:decimal = 1.5
var really:bool = ghalet
var esmi:string = "Aziz Amari"

Operators

Arithmetic

  • Addition: +
  • Subtraction: -
  • Multiplication: *
  • Division: /
  • Euclidean Division: //
  • Modulo: %
  • Exponentiation: **

Comparison

  • Greater than: >
  • Greater than or equal to: >=
  • Less than or equal to: <=
  • Equal to: ==
  • Not equal to: !=

Logical

  • AND: &&
  • OR: ||
  • NOT: !

Conditionals

Normal

var x:int = int(a9ra())
kan x % 2 == 0 {
    ekteb(string(x) + " is an even number")
} wela {
    ekteb(string(x) + " is an odd number")
}

Nested

var language = a9ra()
kan language == "ncodi" {
    ekteb("Great Language")
} wela kan language == "python" {
    ekteb("Mehh !")
} wela {
    ekteb("I don't know this language yet: " + language)
}

Loops

men ... ila loop

men num = 0 ila 10 {
    ekteb(num)
}

madem loop

madem (lang != "ncodi" && lang != "Ncodi") {
    ekteb("Wrong, think again")
    lang = a9ra()
}
ekteb("YES")

dir ... madem loop

var lang = "ncodi"
dir {
    ekteb(lang)
} madem lang != "ncodi"

Functions

Calling functions

ekteb("output")
ekteb(len("aziz"))

Built-in functions

  • ekteb(): Prints to the screen
  • a9ra(): Prompts for user input
  • sqrt(): Calculates square root
  • random(): Generates a random number
  • ord(): Converts a character to its ASCII code
  • chr(): Converts an ASCII code to a character

Defining functions

asne3 hey() {
    ekteb("Hello from ncodi servers")
}

asne3 greet(name:string, times:int) {
    men i = 0 ila times {
        ekteb("Hello " + name + " " + string(i))
    }
}

asne3 pow(n:int, p:int):int {
    raje3 n ** p
}

// Calling the functions
hey()
greet("Aziz Amari", 4)
var x = pow(2, 8)
ekteb(x)