Lang 27 Documentation

Overview

Lang 27 is a simple programming language designed for ease of use and readability. It supports basic syntax, data types, operators, control flow structures, functions, and built-in input/output functions.

GitHub Repository:

Lang 27 GitHub Repository


Features and Examples

1. Basic Syntax

Lang 27 allows variable declarations and function definitions using clear and structured syntax.

Example:

Variable Declarations

Variables in Lang 27 are declared using the following format:
## Variable declarations
num x = 10
str message = "Hello, Lang 27!"
dec pi = 3.14
chr letter = 'A'
bool isActive = true

Function Definitions

Functions are defined using the func keyword, followed by a name and parameters:

2. Data Types

Lang 27 supports five primitive data types: - num - Integer values (e.g., 10) - str - String values (e.g., "Hello") - dec - Decimal values (e.g., 3.14) - chr - Character values (e.g., 'A') - bool - Boolean values (true or false)

Example:

num count = 10
str message = "Hello, World!"
dec price = 19.99
chr grade = 'A'
bool isActive = true

3. Operators

Lang 27 supports the following operators:

Arithmetic Operators: +, -, *, /

Comparison Operators: ==, !=, >, <, >=, <=

Assignment Operator: =

Example:

num a = 5
num b = 3
drucken(a + b)  ## Output: 8
drucken(a > b)  ## Output: true

4. Control Flow

If-Else Statements

num score = 85
if (score >= 50) {
    drucken("Pass")
} el {
    drucken("Fail")
}

For Loop

for (num i = 1; i <= 5; i = i + 1) {
    drucken(i)
}

5. Built-in Functions

Lang 27 provides useful built-in functions.

  • drucken(value): Prints the value to the console.
  • eingabe(prompt, type): Takes user input with type conversion.
  • len(value): Returns the length of a string.
  • to_num(value): Converts a string to a number.

Example:

drucken("Enter your name:")
str userName = eingabe("", str)
drucken("Hello, " + userName)

6. Function Declaration

Functions are defined using the func keyword.

Example:

func add(num a, num b) {
    return a + b
}
drucken(add(10, 20))  ## Output: 30

7. User Input Handling

Lang 27 allows user input with type conversion.

Example:

num userAge = eingabe("Enter your age: ", num)
drucken("Your age is: " + userAge)

8. String Manipulation

Example:

str firstName = "John"
str lastName = "Doe"
drucken("Full name: " + firstName + " " + lastName)
drucken("Length of name: " + len(firstName))

9. Mathematical Operations

Example:

num x = 10
num y = 3
drucken("Sum: " + (x + y))
drucken("Product: " + (x * y))

10. Type Conversion

Example:

str numStr = "42"
num convertedNum = to_num(numStr)
drucken("Converted number: " + convertedNum)

11. Nested If Statements

Example:

num value = 10
if (value > 0) {
    if (value % 2 == 0) {
        drucken("Positive Even Number")
    } el {
        drucken("Positive Odd Number")
    }
} el {
    drucken("Non-positive Number")
}

12. Function with Loops

Example:

func factorial(num n) {
    num result = 1
    for (num i = 1; i <= n; i = i + 1) {
        result = result * i
    }
    return result
}
drucken("Factorial of 5: " + factorial(5))

Contributing

Contributions are welcome! Feel free to submit issues and pull requests via the GitHub Repository.

License

This project is open-source and available under the MIT License.