Syntax Basics
RGC's syntax aligns with Python but uses braces {} for blocks and # for comments.
Basic structure
# Entry function (Python style)
def main() {
x = 42 # variable binding, inferred as int
y: float = 3.14 # explicit type annotation
print("sum =", x + y) # output: sum = 45.14
}
Variable bindings
- Variables are mutable by default (Python habit, no
mutneeded). - Type annotations are supported:
x: int = 42. - Unannotated variables get their type inferred from the initializer.
def main() {
count = 1 # inferred as int
name = "RGC" # inferred as str
ratio: float = 0.5 # explicit annotation
}
Functions
Functions are defined with def and support type annotations and return types:
def add(a: int, b: int) -> int {
return a + b
}
def greet(name: str) {
print("Hello,", name)
}
Control flow
if / elif / else use brace blocks:
def classify(n: int) {
if n < 0 {
print("negative")
} elif n == 0 {
print("zero")
} else {
print("positive")
}
}
for ... in and while loops:
def main() {
for i in range(5) { # 0 1 2 3 4
print(i)
}
for i in range(2, 6) { # 2 3 4 5
print(i)
}
for i in range(10, 0, -2) { # 10 8 6 4 2
print(i)
}
n = 0
while n < 3 {
n = n + 1
}
}
range supports range(n) / range(start, end) / range(start, end, step); the end value is excluded, a negative step counts down, and a step of 0 yields no iterations.
Logical operators
Logical operators use Python-style words:
| Operation | Symbol |
|---|---|
| and | and |
| or | or |
| not | not |
| equal / not equal | == / != |
| comparison | < <= > >= |
| arithmetic | + - * / % // ** |
Comments
# line comment
/* block comment */