← Back to Categories

🏛️ System Programming Examples

Learn advanced Mewar features including Constants, Enums, Records, Pointers, Type Casting and Bitwise Operations.

1. Constant Variable

const kingdom to "Mewar"
say kingdom

set kingdom to "karan"
say kingdom

2. Enum Example

enum Color then
  RED
  GREEN
  BLUE
end

say Color.RED
say Color.GREEN
say Color.BLUE

3. Record Example

record Warrior then
  name
  power
  alive
end

set w to Warrior
set w.name to "Pratap"
set w.power to 100
set w.alive to true

say w.name
say w.power

4. Record Access

record Warrior then
  name
  power
  alive
end

set x to Warrior
set x.name to "karan"
set x.power to 200
set x.alive to "yes"

say x.name
say x.power
say x.alive

5. Pointer Creation

# 1️⃣ BASIC VARIABLE
set x to 10
say "Initial x = " + x

# 2️⃣ CREATE POINTER
set p to address x
say "Pointer p created to x"

6. Pointer Value

# 1️⃣ BASIC VARIABLE
set x to 10
say "Initial x = " + x

# 2️⃣ CREATE POINTER
set p to address x
say "Pointer p created to x"

# 3️⃣ READ THROUGH POINTER
say "Value via pointer p = " + value p

newline

# 4️⃣ MODIFY VIA POINTER
set value p to 50
say "After pointer write, x = " + x

newline

# 5️⃣ SECOND VARIABLE
set y to 100
say "Initial y = " + y

# 6️⃣ POINT POINTER TO ANOTHER VARIABLE
set p2 to address y
say "Pointer p2 created to y"

say "Value via pointer p2 = " + value p2

newline

# 7️⃣ POINTER WRITE WITH VARIABLE
set value p2 to x
say "After p2 write, y = " + y

newline

# 8️⃣ POINTER CHAIN (POINTER TO POINTER VALUE)
set z to 999
set p3 to address z

say "z = " + z
say "value p3 = " + value p3

set value p3 to value p
say "After chaining, z = " + z

newline

# 9️⃣ SHOW POINTER DETAILS
say "----- SHOW POINTER STATES -----"
show x
show y
show z
show p
show p2
show p3

newline

# 🔟 POINTER SAFETY TEST
say "----- INVALID POINTER TEST -----"
set fake to 5

test
  set value fake to 100
fail err then
  say "Pointer error handled: " + err
end

newline

# 1️⃣1️⃣ POINTER + FUNCTION
function set_to_200 with ptr then
  set value ptr to 200
end

call set_to_200 with p
say "After function pointer write, x = " + x

7. Pointer Update

#  BASIC VARIABLE
set x to 10
say "Initial x = " + x

#  CREATE POINTER
set p to address x
say "Pointer p created to x"

# MODIFY VIA POINTER
set value p to 50
say "After pointer write, x = " + x

8. Number Casting

set text to "50"

set num to number(text)

say num

9. String Casting

set value to 100

set text to string(value)

say text
show text

10. Increment Operator

set gold to 10

gold++

say gold

11. Decrement Operator

set gold to 10

gold--

say gold

12. Compound Assignment

set gold to 100

gold += 50

say gold

13. Bitwise AND

set result to 5 & 3

say result

14. Bitwise OR

set result to 5 | 3

say result

15. Bitwise XOR

set result to 5 ^ 3

say result

16. Left Shift

set result to 5 << 1

say result

17. Right Shift

set result to 8 >> 1

say result

18. System Programming Demo

const kingdom to "Mewar"

set gold to 100

gold += 50

say gold