The Group Delimiter is used to control the order of operations in expressions and to enclose function parameters. Groups use parentheses to explicitly define which operations should be evaluated first, overriding the default precedence rules. They are also required syntax when defining and calling functions.
The short syntax structure uses the ( ) symbols:
( EXPRESSION )The long syntax structure uses the words GROUP and END GROUP:
GROUP EXPRESSION END GROUPGroups serve two primary purposes in ProtoLang:
Groups override the default order of operations, ensuring that expressions inside parentheses are evaluated first.
NEW INT x = 5 + 3 * 2
PRINTLN x // Displays "11" (multiplication happens first)
NEW INT y = ( 5 + 3 ) * 2
PRINTLN y // Displays "16" (addition happens first due to parentheses)NEW INT a = 10
NEW INT b = 5
NEW INT c = 2
NEW INT result = ( a + b ) * c
PRINTLN result // Displays "30"NEW INT value = ( ( 10 + 5 ) * 2 ) - 3
PRINTLN value // Displays "27"
// Evaluation: (15 * 2) - 3 = 30 - 3 = 27NEW FLOAT celsius = 25.0
NEW FLOAT fahrenheit = ( celsius * 9.0 / 5.0 ) + 32.0
PRINTLN fahrenheit // Displays "77.0"Groups make complex logical conditions clear and explicit.
NEW INT age = 25
NEW INT minAge = 18
NEW INT maxAge = 65
NEW BOOL inRange = ( age >= minAge ) && ( age <= maxAge )
PRINTLN inRange // Displays "TRUE"NEW BOOL a = TRUE
NEW BOOL b = FALSE
NEW BOOL c = TRUE
NEW BOOL result = ( a || b ) && c
PRINTLN result // Displays "TRUE"When defining a Function, groups enclose the parameter list.
FUNCTION greet ( )
PRINTLN "Hello!"
END FUNCTION
greet ( )FUNCTION square ( INT n )
NEW INT result = n * n
RETURN result
END FUNCTION
NEW INT value = square ( 5 )
PRINTLN value // Displays "25"FUNCTION add ( INT a , INT b )
NEW INT sum = a + b
RETURN sum
END FUNCTION
NEW INT result = add ( 10 , 5 )
PRINTLN result // Displays "15"When calling a function, groups enclose the argument list.
FUNCTION multiply ( INT x , INT y )
NEW INT product = x * y
RETURN product
END FUNCTION
NEW INT answer = multiply ( 6 , 7 )
PRINTLN answer // Displays "42"FUNCTION double ( INT n )
RETURN n * 2
END FUNCTION
FUNCTION addTen ( INT n )
RETURN n + 10
END FUNCTION
NEW INT result = double ( addTen ( 5 ) )
PRINTLN result // Displays "30"
// Evaluation: addTen(5) = 15, then double(15) = 30Groups clarify complex conditions in If statements.
NEW INT score = 85
NEW INT attendance = 90
IF ( score >= 80 ) && ( attendance >= 85 )
PRINTLN "Pass with honors"
END IF
// Displays "Pass with honors"NEW BOOL isStudent = TRUE
NEW BOOL isSenior = FALSE
NEW BOOL hasCoupon = TRUE
IF ( isStudent || isSenior ) && hasCoupon
PRINTLN "Discount applied"
END IF
// Displays "Discount applied"NEW FLOAT width = 10.0
NEW FLOAT height = 5.0
NEW FLOAT area = width * height
NEW FLOAT perimeter = ( width + height ) * 2.0
PRINTLN "Area: " .. area // Displays "Area: 50.0"
PRINTLN "Perimeter: " .. perimeter // Displays "Perimeter: 30.0"NEW FLOAT price = 100.0
NEW FLOAT discountPercent = 20.0
NEW FLOAT discount = price * ( discountPercent / 100.0 )
NEW FLOAT finalPrice = price - discount
PRINTLN "Final price: $" .. finalPrice // Displays "Final price: $80.0"NEW INT a = 10
NEW INT b = 20
NEW INT c = 30
NEW INT average = ( a + b + c ) / 3
PRINTLN "Average: " .. average // Displays "Average: 20"NEW INT x = ( 5 + 3 * 2
PRINTLN x // Syntax error! Missing closing parenthesis
// Correct:
NEW INT y = ( 5 + 3 ) * 2
PRINTLN yNEW INT x = 5 + 3 ) * 2
PRINTLN x // Syntax error! Missing opening parenthesis
// Correct:
NEW INT y = ( 5 + 3 ) * 2
PRINTLN yFUNCTION getValue ( )
RETURN 42
END FUNCTION
NEW INT x = getValue // Syntax error! Missing parentheses
// Correct:
NEW INT y = getValue ( )NEW INT x = ( ( 10 + 5 ) * 2
PRINTLN x // Syntax error! Unbalanced parentheses
// Correct:
NEW INT y = ( ( 10 + 5 ) * 2 )
PRINTLN y