Skip to content

Latest commit

 

History

History
870 lines (648 loc) · 15.3 KB

File metadata and controls

870 lines (648 loc) · 15.3 KB

Gen Z Lang - API Reference and Quick Guide

Version: 0.1.0 For: AI systems quickly referencing Gen Z Lang syntax and APIs


Quick Syntax Reference

Variables

rizz name = value          # Declare
name = new_value           # Assign

Output

yeet expression            # Print
fr fr expression          # Emphasized print

Input

rizz input = vibe check "prompt"
rizz input = lowkey ask "prompt"

Comments

ngl Single line comment
tea: Multi-line
comment :tea

Control Flow

# If-else
vibe? condition:
  statements
no vibe? condition:
  statements
dead:
  statements

# While loop
keep slaying while condition:
  statements
  dip          # break
  skip it      # continue

# For loop (range)
grind from i = start to end:
  statements

# For loop (iterator)
grind from item in iterable:
  statements

Functions

main character name(param1, param2):
  statements
  send it value

result = name(arg1, arg2)

Operators

# Arithmetic
+ - * / % ^

# Comparison
no cap          # ==
cap             # !=
lowkey <        # <
lowkey <=       # <=
highkey >       # >
highkey >=      # >=

# Logical
and or nah      # AND OR NOT

# Assignment
=

Literals

42              # Integer
3.14            # Float
"string"        # String
'string'        # String
bussin          # True
mid             # False

Built-in Functions Reference

Type Conversions

glow_up(value) → int

Converts value to integer.

rizz num = glow_up("42")      # 42
rizz rounded = glow_up(3.9)    # 3

Parameters:

  • value: String or number to convert

Returns: Integer value

Errors: ValueError if conversion fails


vibe_shift(value) → str

Converts value to string.

rizz text = vibe_shift(42)           # "42"
rizz bool_str = vibe_shift(bussin)   # "True"

Parameters:

  • value: Any value to convert

Returns: String representation


energy(value) → float

Converts value to floating-point number.

rizz decimal = energy("3.14")    # 3.14
rizz float_num = energy(42)      # 42.0

Parameters:

  • value: String or number to convert

Returns: Float value

Errors: ValueError if conversion fails


Utility Functions

ick(value) → int

Returns length of string or iterable.

rizz len = ick("hello")           # 5
rizz str_len = ick("Gen Z")       # 5

Parameters:

  • value: String or iterable

Returns: Length as integer

Errors: TypeError for non-iterable types


slay_time() → int

Returns current Unix timestamp.

rizz now = slay_time()            # e.g., 1703001234
rizz timestamp = slay_time()

Parameters: None

Returns: Current timestamp in seconds since epoch


random_vibe() → float

Returns random number between 0.0 and 1.0.

rizz rand = random_vibe()         # e.g., 0.7834521
rizz probability = random_vibe()

Parameters: None

Returns: Random float in range [0.0, 1.0)


Complete Language Grammar

program        → statement* EOF

statement      → varDecl | assignment | printStmt
               | ifStmt | whileStmt | forStmt
               | funcDef | returnStmt
               | breakStmt | continueStmt | exprStmt

varDecl        → "rizz" IDENTIFIER "=" expression NEWLINE
assignment     → IDENTIFIER "=" expression NEWLINE
printStmt      → ("yeet" | "fr" "fr") expression NEWLINE

ifStmt"vibe?" expression ":" block
                 ("no" "vibe?" expression ":" block)*
                 ("dead" ":" block)?

whileStmt"keep" "slaying" "while" expression ":" block
forStmt"grind" "from" IDENTIFIER ("=" expression "to" expression | "in" expression) ":" block

funcDef"main" "character" IDENTIFIER "(" params? ")" ":" block
returnStmt"send" "it" expression? NEWLINE
breakStmt"dip" NEWLINE
continueStmt"skip" "it" NEWLINE
exprStmtexpression NEWLINE

blockINDENT statement+ DEDENT
paramsIDENTIFIER ("," IDENTIFIER)*
argumentsexpression ("," expression)*

expressionlogical
logicalcomparison (("and" | "or") comparison)*
comparisonterm (compOp term)*
compOp"no" "cap" | "cap" | "lowkey" ("<" | "<=") | "highkey" (">" | ">=")
termfactor (("+" | "-") factor)*
factorunary (("*" | "/" | "%") unary)*
unary          → ("-" | "nah")? power
powerprimary ("^" primary)*
primaryNUMBER | STRING | "bussin" | "mid"
               | IDENTIFIER ("(" arguments? ")")?
               | ("vibe" "check" | "lowkey" "ask") expression
               | "(" expression ")"

Operator Precedence Table

Level Operators Associativity Example
1 (lowest) or Left a or b or c
2 and Left a and b and c
3 no cap, cap, lowkey <, lowkey <=, highkey >, highkey >= Left a no cap b
4 +, - Left a + b - c
5 *, /, % Left a * b / c
6 nah, - (unary) Right nah a, -a
7 (highest) ^ Right 2 ^ 3 ^ 2 = 512

Common Patterns

1. Counter Loop

grind from i = 0 to 9:
  yeet i

2. While with Condition

rizz count = 0
keep slaying while count lowkey < 10:
  yeet count
  count = count + 1

3. User Input with Validation

rizz valid = mid
keep slaying while nah valid:
  rizz input = vibe check "Enter number: "
  rizz num = glow_up(input)
  vibe? num highkey > 0:
    valid = bussin
  dead:
    yeet "Must be positive!"

4. Function with Default Return

main character process(value):
  vibe? value lowkey < 0:
    send it mid
  send it bussin

5. Recursive Function

main character factorial(n):
  vibe? n lowkey <= 1:
    send it 1
  send it n * factorial(n - 1)

6. Closure/Counter

main character make_counter():
  rizz count = 0
  main character increment():
    count = count + 1
    send it count
  send it increment

rizz counter = make_counter()
yeet counter()  # 1
yeet counter()  # 2

7. Higher-Order Function

main character apply(func, value):
  send it func(value)

main character double(x):
  send it x * 2

yeet apply(double, 5)  # 10

8. State Machine

main character create_toggle():
  rizz state = mid
  main character toggle():
    vibe? state:
      state = mid
    dead:
      state = bussin
    send it state
  send it toggle

rizz switch = create_toggle()
yeet switch()  # True
yeet switch()  # False

9. Filtering Pattern

main character filter_positive(size):
  rizz result_count = 0
  grind from i = 0 to size - 1:
    vibe? i highkey > 0:
      yeet i
      result_count = result_count + 1
  send it result_count

10. String Building

rizz message = "Hello"
message = message + ", "
message = message + "World"
message = message + "!"
yeet message  # "Hello, World!"

Error Handling Patterns

Check Before Use

main character safe_divide(a, b):
  vibe? b no cap 0:
    yeet "Error: Division by zero"
    send it 0
  send it a / b

Validation

main character validate_age(age):
  vibe? age lowkey < 0:
    send it mid
  vibe? age highkey > 150:
    send it mid
  send it bussin

Guard Clauses

main character process_data(data):
  vibe? data no cap 0:
    send it mid
  vibe? data lowkey < 0:
    send it mid

  ngl Main logic here
  send it bussin

Type Checking Patterns

Check Type via Conversion

main character is_number(value):
  ngl Try to convert - if it fails, not a number
  rizz num = glow_up(value)
  vibe? num no cap num:  # If conversion succeeded
    send it bussin
  send it mid

Multiple Type Handling

main character stringify(value):
  ngl Convert any type to string
  send it vibe_shift(value)

Data Structure Patterns (Simulated)

Array-like with Functions

main character create_array():
  rizz v0 = 0
  rizz v1 = 0
  rizz v2 = 0
  rizz size = 0

  main character get(i):
    vibe? i no cap 0:
      send it v0
    no vibe? i no cap 1:
      send it v1
    no vibe? i no cap 2:
      send it v2
    send it 0

  main character set(i, val):
    vibe? i no cap 0:
      v0 = val
    no vibe? i no cap 1:
      v1 = val
    no vibe? i no cap 2:
      v2 = val

  main character api(method):
    vibe? method no cap "get":
      send it get
    no vibe? method no cap "set":
      send it set
    send it mid

  send it api

rizz arr = create_array()
rizz set_func = arr("set")
rizz get_func = arr("get")
set_func(0, 42)
yeet get_func(0)  # 42

Dictionary-like with Functions

main character create_dict():
  rizz key0 = ""
  rizz val0 = 0
  rizz key1 = ""
  rizz val1 = 0

  main character put(k, v):
    vibe? key0 no cap "":
      key0 = k
      val0 = v
    no vibe? key1 no cap "":
      key1 = k
      val1 = v

  main character get(k):
    vibe? key0 no cap k:
      send it val0
    no vibe? key1 no cap k:
      send it val1
    send it 0

  main character api(method):
    vibe? method no cap "put":
      send it put
    no vibe? method no cap "get":
      send it get
    send it mid

  send it api

Algorithm Templates

Binary Search

main character binary_search(target, low, high):
  keep slaying while low lowkey <= high:
    rizz mid = (low + high) / 2

    vibe? mid no cap target:
      send it mid
    no vibe? mid lowkey < target:
      low = mid + 1
    dead:
      high = mid - 1

  send it -1

Bubble Sort

main character bubble_sort(size):
  grind from i = 0 to size - 1:
    grind from j = 0 to size - i - 2:
      ngl Compare and swap
      yeet "Sorting..."

Fibonacci

main character fibonacci(n):
  vibe? n lowkey <= 1:
    send it n
  send it fibonacci(n - 1) + fibonacci(n - 2)

Greatest Common Divisor

main character gcd(a, b):
  keep slaying while b cap 0:
    rizz temp = b
    b = a % b
    a = temp
  send it a

Power (Recursive)

main character power(base, exp):
  vibe? exp no cap 0:
    send it 1
  vibe? exp no cap 1:
    send it base
  rizz half = power(base, exp / 2)
  vibe? exp % 2 no cap 0:
    send it half * half
  send it base * half * half

Testing Patterns

Assert Helper

main character assert(condition, message):
  vibe? nah condition:
    yeet "ASSERT FAILED: "
    yeet message
  dead:
    yeet "PASS: "
    yeet message

Test Suite

main character run_tests():
  yeet "=== Running Tests ==="

  ngl Test 1
  rizz result1 = my_function(5)
  assert(result1 no cap 10, "my_function(5) should equal 10")

  ngl Test 2
  rizz result2 = my_function(0)
  assert(result2 no cap 0, "my_function(0) should equal 0")

  yeet "Tests complete"

CLI Usage

Basic Execution

genz program.genz

With Python Directly

python3 -c "
from genzlang.lexer import Lexer
from genzlang.parser import Parser
from genzlang.interpreter import Interpreter

source = '''
rizz x = 10
yeet x
'''

lexer = Lexer(source)
tokens = lexer.tokenize()
parser = Parser(tokens)
ast = parser.parse()
interpreter = Interpreter()
interpreter.interpret(ast)
"

File Structure Conventions

Single-File Program

ngl Program description at top

ngl Helper functions
main character helper1():
  statements

main character helper2():
  statements

ngl Main program logic
rizz data = init()
process(data)
output(result)

Multi-Purpose Script

ngl Utility library

ngl Configuration
rizz CONFIG_VALUE = 100

ngl Public API functions
main character public_function1():
  statements

main character public_function2():
  statements

ngl Private helper functions
main character _private_helper():
  statements

ngl Main execution
main character main():
  ngl Program entry point
  statements

ngl Run main if executed directly
main()

Performance Tips

1. Avoid Repeated Function Calls

ngl Bad
grind from i = 0 to 100:
  yeet expensive_function()

ngl Good
rizz result = expensive_function()
grind from i = 0 to 100:
  yeet result

2. Use Iteration Instead of Recursion for Large N

ngl Bad for large n (stack overflow)
main character factorial_recursive(n):
  vibe? n lowkey <= 1:
    send it 1
  send it n * factorial_recursive(n - 1)

ngl Good for large n
main character factorial_iterative(n):
  rizz result = 1
  grind from i = 2 to n:
    result = result * i
  send it result

3. Early Return

main character find_value(target, size):
  grind from i = 0 to size - 1:
    vibe? i no cap target:
      send it i  # Return immediately
  send it -1

4. Short-Circuit Logic

ngl Expensive check only runs if cheap check passes
vibe? cheap_condition() and expensive_check():
  statements

Common Gotchas

1. Integer Division

Division always returns float:

rizz result = 5 / 2  # 2.5, not 2

2. Variable Scope

Variables must be declared before use:

main character test():
  rizz local = 10

yeet local  # ERROR: undefined variable

3. Function Closure

Functions capture variables from enclosing scope:

rizz x = 10

main character get_x():
  send it x  # Captures x from outer scope

x = 20
yeet get_x()  # 20, not 10

4. Operator Precedence

rizz result = 2 + 3 * 4   # 14, not 20
rizz result = 2 ^ 3 ^ 2   # 512, not 64 (right-associative)

5. Truthiness

vibe? 0:        # False
vibe? "":       # False
vibe? bussin:   # True
vibe? "hello":  # True
vibe? 1:        # True

Complete Keyword List

Keyword Type Usage
and Operator Logical AND
bussin Literal True
cap Operator Not equal (!=)
dead Control Else
dip Control Break
fr Output Part of "fr fr"
grind Control For loop
from Control Part of "grind from"
highkey Operator Greater than prefix
in Control Iterator
it Control Part of "send it", "skip it"
keep Control Part of "keep slaying while"
lowkey Operator Less than prefix
main Declaration Part of "main character"
mid Literal False
nah Operator NOT
ngl Comment Single-line comment
no Operator/Control Part of "no cap", "no vibe?"
or Operator Logical OR
rizz Declaration Variable declaration
send Control Part of "send it" (return)
skip Control Part of "skip it" (continue)
slaying Control Part of "keep slaying while"
tea Comment Multi-line comment delimiters
to Control Range loop
vibe Input/Control Part of "vibe check", "vibe?"
while Control While loop
yeet Output Print

Reserved for Future Use

These keywords may be added in future versions:

  • class / squad_type - Classes
  • import / cop - Modules
  • try / catch it - Exceptions
  • async / wait for it - Async/await
  • with / vibe with - Context managers
  • match / check vibes - Pattern matching
  • lambda / quick - Anonymous functions

This API reference provides complete, quick-access documentation for AI systems building software in Gen Z Lang. All syntax, functions, patterns, and gotchas are documented for easy reference.