Skip to content

oXo23/Qweil-programming-language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qweil Programming Language Documentation

Welcome to the Qweil programming language documentation! Qweil is designed to be a simple and intuitive language that compiles to Python, making it easy to learn and use. This document will guide you through the syntax and features of Qweil.

Table of Contents

  1. Logging
  2. Conditional Statements
  3. Loops
  4. Functions
  5. Classes
  6. Exception Handling
  7. Variable Assignment
  8. Global Variables
  9. Decorators
  10. Deleting Variables
  11. Quitting the Program
  12. Throwing Exceptions

Logging

Logging in Qweil is done using the log function. This is equivalent to the print function in Python.

Syntax

log("Hello, World!")

Example

log("Hello, World!")

Conditional Statements

Conditional statements in Qweil use the if keyword followed by the condition and the then keyword.

Syntax

if (condition) then # code to execute if condition is true end

Example

x = 10 if x > 5 then log("x is greater than 5") end

Loops

Qweil supports both for and while loops.

For Loop

Syntax

for (variable in range) do # code to execute end

Example

for i in range(5) do log(i) end

While Loop

Syntax

while (condition) do # code to execute end

Example

x = 0 while x < 5 do log(x) x = x + 1 end

Functions

Functions in Qweil are defined using the func keyword.

Syntax

func function_name(parameters) do # function body end

Example

func greet(name) do log("Hello, " + name) end

greet("Alice")

Classes

Classes in Qweil are defined using the class keyword.

Syntax

class ClassName do func __init__(self, parameters) do # constructor body end
func method_name(self, parameters) do
    # method body
end

end

Example

class Person do func __init__(self, name) do self.name = name end
func greet(self) do
    log("Hello, " + self.name)
end

end

person = Person("Alice") person.greet()

Exception Handling

Exception handling in Qweil is done using the try, except, and finally keywords.

Syntax

try # code that may raise an exception except (exception_type) do # code to handle the exception end finally do # code to execute regardless of an exception end

Example

try risky_operation() except Exception as e do log("An error occurred: " + str(e)) end finally do log("This will always execute") end

Variable Assignment

Variable assignment in Qweil is straightforward.

Syntax

variable_name = value

Example

x = 10 log(x)

Global Variables

Global variables in Qweil are declared using the global keyword.

Syntax

global variable_name

Example

global x x = 10 log(x)

Decorators

Decorators in Qweil are defined using the @ symbol.

Syntax

@decorator_name

Example

@staticmethod func my_method() do log("This is a static method") end

Deleting Variables

Variables in Qweil can be deleted using the del keyword.

Syntax

del variable_name

Example

x = 10 del x

Quitting the Program

The program can be terminated using the quit function.

Syntax

quit(exit_code)

Example

quit(0)

Throwing Exceptions

Exceptions in Qweil can be thrown using the throw keyword.

Syntax

throw exception_type

Example

throw ValueError("An error occurred")

Happy coding with Qweil!