ProtoLang.net

Reference: End Group

☰ Hide Sidebar
TOKEN END GROUP
ALIAS )

The End Group Delimiter marks the closing of a group. It pairs with the Group delimiter to enclose expressions and function parameters.

Syntax

The short syntax structure uses the ( ) symbols:

( EXPRESSION )

The long syntax structure uses the words GROUP and END GROUP:

GROUP EXPRESSION END GROUP

Purpose

End Group serves as the closing delimiter that pairs with Group to:

  • Complete grouped arithmetic expressions
  • Close function parameter lists in definitions and calls
  • Define the end point of nested expressions

End Group in Arithmetic Expressions

Example: Closing Simple Expression

NEW INT x = ( 5 + 3 ) * 2
PRINTLN x // Displays "16"

Example: Multiple Grouped Expressions

NEW INT a = 10
NEW INT b = 5
NEW INT c = ( a + b ) * ( a - b )
PRINTLN c // Displays "75"
// Evaluation: (10 + 5) * (10 - 5) = 15 * 5 = 75

Example: Nested Groups

NEW INT result = ( ( 10 + 5 ) * 2 ) - 3
PRINTLN result // Displays "27"
// Each opening ( must have a matching closing )

End Group in Function Definitions

Example: Function with No Parameters

FUNCTION sayHello ( )
    PRINTLN "Hello!"
END FUNCTION
// The ) closes the empty parameter list

Example: Function with Parameters

FUNCTION add ( INT a , INT b )
    NEW INT sum = a + b
    RETURN sum
END FUNCTION
// The ) closes the parameter list after INT b

Example: Function with Multiple Parameters

FUNCTION calculateTotal ( FLOAT price , FLOAT tax , FLOAT discount )
    NEW FLOAT total = ( price + tax ) - discount
    RETURN total
END FUNCTION
// The ) closes the parameter list

End Group in Function Calls

Example: Calling Function with No Arguments

FUNCTION getValue ( )
    RETURN 42
END FUNCTION

NEW INT x = getValue ( )
// The ) closes the empty argument list

Example: Calling Function with Arguments

FUNCTION multiply ( INT x , INT y )
    RETURN x * y
END FUNCTION

NEW INT result = multiply ( 6 , 7 )
PRINTLN result // Displays "42"
// The ) closes the argument list after 7

Example: Nested Function Calls

FUNCTION double ( INT n )
    RETURN n * 2
END FUNCTION

FUNCTION triple ( INT n )
    RETURN n * 3
END FUNCTION

NEW INT result = double ( triple ( 5 ) )
PRINTLN result // Displays "30"
// Inner ) closes triple(5), outer ) closes double(...)

End Group in Conditionals

Example: Grouped Comparisons

NEW INT age = 25
NEW BOOL isAdult = ( age >= 18 )
PRINTLN isAdult // Displays "TRUE"

Example: Complex Logical Expression

NEW INT score = 85
NEW INT attendance = 90
IF ( score >= 80 ) && ( attendance >= 85 )
    PRINTLN "Pass with honors"
END IF
// Two ) symbols close the two grouped comparisons

Balancing Groups

Every Group opening must have a matching End Group closing.

Example: Proper Balancing

NEW INT x = ( 5 + 3 )
// 1 opening ( matches 1 closing )

NEW INT y = ( ( 10 + 5 ) * 2 )
// 2 opening ( match 2 closing )

NEW INT z = ( x + y ) * ( x - y )
// Each pair is properly balanced

Example: Deeply Nested Groups

NEW INT value = ( ( ( 5 + 3 ) * 2 ) - 1 )
PRINTLN value // Displays "15"
// 3 opening ( match 3 closing ) in reverse order

End Group in Loops

Example: Loop Condition with Groups

NEW INT i = 1
WHILE ( i <= 5 ) && ( i != 3 )
    PRINTLN i
    SET i = i + 1
END WHILE
// Two ) close the two grouped conditions

Practical Applications

Example: Formula with Multiple Groups

NEW FLOAT length = 10.0
NEW FLOAT width = 5.0
NEW FLOAT height = 3.0
NEW FLOAT volume = ( length * width ) * height
PRINTLN "Volume: " .. volume // Displays "Volume: 150.0"

Example: Complex Calculation

NEW FLOAT principal = 1000.0
NEW FLOAT rate = 0.05
NEW INT years = 2
NEW FLOAT amount = principal * ( ( 1.0 + rate ) * ( 1.0 + rate ) )
PRINTLN "Amount: " .. amount

Important Notes

  • Every opening ( must have exactly one matching closing ).
  • Groups are closed in the reverse order they were opened (last opened, first closed).
  • The ) symbol is required to close function parameter lists and calls.
  • Missing or extra ) symbols cause syntax errors.
  • In short syntax, ) is used; in long syntax, END GROUP is used.

Common Errors

Error: Missing Closing Parenthesis

NEW INT x = ( 5 + 3
PRINTLN x // Syntax error! Missing )

// Correct:
NEW INT y = ( 5 + 3 )
PRINTLN y

Error: Extra Closing Parenthesis

NEW INT x = ( 5 + 3 ) )
PRINTLN x // Syntax error! Extra )

// Correct:
NEW INT y = ( 5 + 3 )
PRINTLN y

Error: Unbalanced Nested Groups

NEW INT x = ( ( 10 + 5 ) * 2
PRINTLN x // Syntax error! Missing closing )

// Correct:
NEW INT y = ( ( 10 + 5 ) * 2 )
PRINTLN y

Error: Wrong Closing Order

NEW INT x = ( 5 + ( 3 * 2 )
// Syntax error! Inner group closed but outer group not closed

// Correct:
NEW INT y = ( 5 + ( 3 * 2 ) )
PRINTLN y

Error: Missing in Function Call

FUNCTION getValue ( )
    RETURN 10
END FUNCTION

NEW INT x = getValue (
PRINTLN x // Syntax error! Missing closing )

// Correct:
NEW INT y = getValue ( )
PRINTLN y

Error: Missing in Function Definition

FUNCTION add ( INT a , INT b
    RETURN a + b
END FUNCTION
// Syntax error! Missing ) after parameter list

// Correct:
FUNCTION add ( INT a , INT b )
    RETURN a + b
END FUNCTION