diff --git a/.gitmodules b/.gitmodules index d2fa114..6321c1a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "libs/llvm-18.1.9-src"] path = libs/llvm-18.1.9-src url = https://github.com/kneorain/llvm-project +[submodule "libs/PEGTL"] + path = libs/PEGTL + url = https://github.com/taocpp/PEGTL diff --git a/helix.bat b/helix.bat index 2835d96..9d8d7f2 100755 --- a/helix.bat +++ b/helix.bat @@ -1,7 +1,27 @@ @echo off +setlocal -rem Build the helix project using xmake -xmake +rem Initialize an empty variable to collect the remaining arguments +set "ARGS=" -rem Run the helix project with all arguments passed to the batch file -build\debug\x64-msvc-windows\bin\helix %* \ No newline at end of file +rem Check if the first argument is '--' +if "%1" == "--" ( + rem Shift to remove the '--' + shift +) else ( + rem Build the Helix project using xmake + xmake +) + +rem Collect all the remaining arguments after '--' +:loop +if "%1"=="" goto endloop + set "ARGS=%ARGS% %1" + shift + goto loop + +:endloop +rem Now run the binary with the collected arguments, without passing '--' +build\debug\x64-msvc-windows\bin\helix %ARGS% + +endlocal diff --git a/language/.hlx b/language/.hlx new file mode 100644 index 0000000..792ee11 --- /dev/null +++ b/language/.hlx @@ -0,0 +1,514 @@ +// this is the language definition for helix +// this is higher level then ebnf and is used to define the syntax of helix +// this is a sudo code language that defines the syntax and ast structure of helix + +ffi "c++" enum tokens { // tokens in the c++ is defined in the token namespace - token::TOKEN_NAME + KEYWORD_IF, KEYWORD_ELSE, KEYWORD_UNLESS, KEYWORD_MACRO, KEYWORD_DEFINE, KEYWORD_FUNCTION, + KEYWORD_OPERATOR, KEYWORD_INLINE, KEYWORD_RETURN, KEYWORD_ENCLOSING, KEYWORD_ASYNC, KEYWORD_SPAWN, + KEYWORD_STATIC, KEYWORD_AWAIT, KEYWORD_THREAD, KEYWORD_FOR, KEYWORD_WHILE, KEYWORD_BREAK, + KEYWORD_CONTINUE, KEYWORD_CASE, KEYWORD_MATCH, KEYWORD_SWITCH, KEYWORD_DEFAULT, KEYWORD_ENUM, + KEYWORD_TYPE, KEYWORD_CLASS, KEYWORD_UNION, KEYWORD_STRUCT, KEYWORD_ABSTRACT, KEYWORD_INTERFACE, + KEYWORD_IS, KEYWORD_TRY, KEYWORD_PANIC, KEYWORD_CATCH, KEYWORD_FINALLY, KEYWORD_LET, + KEYWORD_PRIVATE, KEYWORD_AUTO, KEYWORD_CONST, KEYWORD_GLOBAL, KEYWORD_FROM, KEYWORD_FFI, + KEYWORD_IMPORT, KEYWORD_YIELD, KEYWORD_AS, KEYWORD_DERIVES, KEYWORD_MODULE, KEYWORD_UNSAFE, + DELIMITER_TAB, DELIMITER_NEWLINE, DELIMITER_SPACE, LITERAL_TRUE, LITERAL_FALSE, LITERAL_INTEGER, + LITERAL_COMPLIER_DIRECTIVE, LITERAL_FLOATING_POINT, LITERAL_STRING, LITERAL_CHAR, LITERAL_NULL, + OPERATOR_ADD, OPERATOR_SUB, OPERATOR_MUL, OPERATOR_DIV, OPERATOR_MOD, OPERATOR_MAT, + OPERATOR_BITWISE_AND, OPERATOR_BITWISE_OR, OPERATOR_BITWISE_XOR, OPERATOR_BITWISE_NOT, + OPERATOR_ASSIGN, OPERATOR_LOGICAL_NOT, OPERATOR_POW, OPERATOR_ABS, OPERATOR_BITWISE_L_SHIFT, + OPERATOR_BITWISE_NAND, OPERATOR_BITWISE_R_SHIFT, OPERATOR_BITWISE_NOR, OPERATOR_EQUAL, + OPERATOR_NOT_EQUAL, OPERATOR_GREATER_THAN_EQUALS, OPERATOR_INC, OPERATOR_DEC, + OPERATOR_LESS_THAN_EQUALS, OPERATOR_ADD_ASSIGN, OPERATOR_SUB_ASSIGN, OPERATOR_MUL_ASSIGN, + OPERATOR_BITWISE_AND_ASSIGN, OPERATOR_BITWISE_OR_ASSIGN, OPERATOR_BITWISE_NOR_ASSIGN, + OPERATOR_BITWISE_XOR_ASSIGN, OPERATOR_BITWISE_NOT_ASSIGN, OPERATOR_DIV_ASSIGN, OPERATOR_MOD_ASSIGN, + OPERATOR_MAT_ASSIGN, OPERATOR_LOGICAL_AND, OPERATOR_LOGICAL_NAND, OPERATOR_LOGICAL_OR, + OPERATOR_LOGICAL_NOR, OPERATOR_LOGICAL_XOR, OPERATOR_RANGE, OPERATOR_ARROW, OPERATOR_NOT_ASSIGN, + OPERATOR_SCOPE, OPERATOR_REF_EQUAL, OPERATOR_POWER_ASSIGN, OPERATOR_AND_ASSIGN, OPERATOR_NAND_ASSIGN, + OPERATOR_OR_ASSIGN, OPERATOR_NOR_ASSIGN, OPERATOR_XOR_ASSIGN, OPERATOR_BITWISE_NAND_ASSIGN, + OPERATOR_BITWISE_L_SHIFT_ASSIGN, OPERATOR_BITWISE_R_SHIFT_ASSIGN, OPERATOR_RANGE_INCLUSIVE, IDENTIFIER, + WHITESPACE, OTHERS, EOF_TOKEN, PRIMITIVE_VOID, PRIMITIVE_BOOL, PRIMITIVE_BYTE, PRIMITIVE_CHAR, + PRIMITIVE_POINTER, PRIMITIVE_I8, PRIMITIVE_U8, PRIMITIVE_I16, PRIMITIVE_U16, PRIMITIVE_I32, + PRIMITIVE_U32, PRIMITIVE_F32, PRIMITIVE_I64, PRIMITIVE_U64, PRIMITIVE_F64, PRIMITIVE_FLOAT, + PRIMITIVE_I128, PRIMITIVE_U128, PRIMITIVE_INT, PRIMITIVE_DECIMAL, PRIMITIVE_STRING, + PRIMITIVE_LIST, PRIMITIVE_TUPLE, PRIMITIVE_SET, PRIMITIVE_MAP, PRIMITIVE_ANY, PUNCTUATION_OPEN_PAREN, + PUNCTUATION_CLOSE_PAREN, PUNCTUATION_OPEN_BRACE, PUNCTUATION_CLOSE_BRACE, PUNCTUATION_OPEN_BRACKET, + PUNCTUATION_CLOSE_BRACKET, PUNCTUATION_OPEN_ANGLE, PUNCTUATION_CLOSE_ANGLE, PUNCTUATION_COMMA, + PUNCTUATION_SEMICOLON, PUNCTUATION_COLON, PUNCTUATION_QUESTION_MARK, PUNCTUATION_DOT, + PUNCTUATION_SINGLE_LINE_COMMENT, PUNCTUATION_MULTI_LINE_COMMENT, PUNCTUATION_ELLIPSIS, +}; + +let Identifier_T <- tokens::IDENTIFIER + +let Literal_T <- tokens::LITERAL_TRUE | tokens::LITERAL_FALSE | tokens::LITERAL_INTEGER + | tokens::LITERAL_FLOATING_POINT | tokens::LITERAL_STRING | tokens::LITERAL_CHAR + | tokens::LITERAL_NULL + +let Operator_T <- tokens::OPERATOR_ADD | tokens::OPERATOR_SUB | tokens::OPERATOR_MUL + | tokens::OPERATOR_BITWISE_AND | tokens::OPERATOR_BITWISE_OR | tokens::OPERATOR_BITWISE_XOR + | tokens::OPERATOR_DIV | tokens::OPERATOR_MOD | tokens::OPERATOR_MAT + | tokens::OPERATOR_BITWISE_NOT | tokens::OPERATOR_ASSIGN | tokens::OPERATOR_LOGICAL_NOT + | tokens::OPERATOR_POW | tokens::OPERATOR_ABS | tokens::OPERATOR_BITWISE_L_SHIFT + | tokens::OPERATOR_BITWISE_NAND | tokens::OPERATOR_BITWISE_R_SHIFT | tokens::OPERATOR_BITWISE_NOR + | tokens::OPERATOR_EQUAL | tokens::OPERATOR_NOT_EQUAL | tokens::OPERATOR_GREATER_THAN_EQUALS + | tokens::OPERATOR_INC | tokens::OPERATOR_DEC | tokens::OPERATOR_LESS_THAN_EQUALS + | tokens::OPERATOR_ADD_ASSIGN | tokens::OPERATOR_SUB_ASSIGN | tokens::OPERATOR_MUL_ASSIGN + | tokens::OPERATOR_BITWISE_AND_ASSIGN | tokens::OPERATOR_BITWISE_OR_ASSIGN | tokens::OPERATOR_BITWISE_NOR_ASSIGN + | tokens::OPERATOR_BITWISE_XOR_ASSIGN | tokens::OPERATOR_BITWISE_NOT_ASSIGN | tokens::OPERATOR_DIV_ASSIGN + | tokens::OPERATOR_MOD_ASSIGN | tokens::OPERATOR_MAT_ASSIGN | tokens::OPERATOR_LOGICAL_AND + | tokens::OPERATOR_LOGICAL_NAND | tokens::OPERATOR_LOGICAL_OR | tokens::OPERATOR_LOGICAL_NOR + | tokens::OPERATOR_LOGICAL_XOR | tokens::OPERATOR_RANGE | tokens::OPERATOR_ARROW + | tokens::OPERATOR_NOT_ASSIGN | tokens::OPERATOR_SCOPE | tokens::OPERATOR_REF_EQUAL + | tokens::OPERATOR_POWER_ASSIGN | tokens::OPERATOR_AND_ASSIGN | tokens::OPERATOR_NAND_ASSIGN + | tokens::OPERATOR_OR_ASSIGN | tokens::OPERATOR_NOR_ASSIGN | tokens::OPERATOR_XOR_ASSIGN + | tokens::OPERATOR_BITWISE_NAND_ASSIGN | tokens::OPERATOR_BITWISE_L_SHIFT_ASSIGN | tokens::OPERATOR_BITWISE_R_SHIFT_ASSIGN + | tokens::OPERATOR_RANGE_INCLUSIVE | tokens::PUNCTUATION_ELLIPSIS | tokens::PUNCTUATION_OPEN_ANGLE + | tokens::PUNCTUATION_CLOSE_ANGLE + +let Primitive_T <- tokens::PRIMITIVE_VOID | tokens::PRIMITIVE_BOOL | tokens::PRIMITIVE_BYTE | tokens::PRIMITIVE_CHAR + | tokens::PRIMITIVE_POINTER | tokens::PRIMITIVE_I8 | tokens::PRIMITIVE_U8 | tokens::PRIMITIVE_I16 + | tokens::PRIMITIVE_U16 | tokens::PRIMITIVE_I32 | tokens::PRIMITIVE_U32 | tokens::PRIMITIVE_F32 + | tokens::PRIMITIVE_I64 | tokens::PRIMITIVE_U64 | tokens::PRIMITIVE_F64 | tokens::PRIMITIVE_FLOAT + | tokens::PRIMITIVE_I128 | tokens::PRIMITIVE_U128 | tokens::PRIMITIVE_INT | tokens::PRIMITIVE_DECIMAL + | tokens::PRIMITIVE_STRING | tokens::PRIMITIVE_LIST | tokens::PRIMITIVE_TUPLE | tokens::PRIMITIVE_SET + | tokens::PRIMITIVE_MAP + +let TypeQualifier_T <- tokens::KEYWORD_CONST | tokens::KEYWORD_UNSAFE | tokens::KEYWORD_INLINE | tokens::KEYWORD_STATIC + | tokens::KEYWORD_EVAL | (tokens::KEYWORD_CONST? + tokens::KEYWORD_EVAL) + +let StorageSpecifier_T <- tokens::KEYWORD_GLOBAL | tokens::KEYWORD_STATIC | tokens::KEYWORD_UNSAFE | tokens::KEYWORD_FFI + +let VisibilitySpecifier_T <- tokens::KEYWORD_PUBLIC | tokens::KEYWORD_PRIVATE | tokens::KEYWORD_PROTECTED + +let FunctionSpecifier_T <- tokens::KEYWORD_INLINE | tokens::KEYWORD_ABSTRACT | tokens::KEYWORD_CONST | tokens::KEYWORD_OVERRIDE + | tokens::KEYWORD_EVAL | (tokens::KEYWORD_CONST? + tokens::KEYWORD_EVAL) + +let FunctionQualifier_T <- tokens::KEYWORD_ABSTRACT | tokens::KEYWORD_DEFAULT | tokens::KEYWORD_DELETE | tokens::KEYWORD_OVERRIDE + | tokens::KEYWORD_CONST + +// ----------------------------------------- Expressions ---------------------------------------- // + +class LiteralExpression: + := Literal_T$1 + value = $1 + +class BinaryExpression: + := (class Expression)$1 + Operator_T$2 + (class Expression)$3 + left = $1 + operator = $2 + right = $3 + +class UnaryExpression: + := Operator_T$1 + (class Expression)$2 + operator = $1 + operand = $2 + +class IdentifierExpression: + := Identifier_T$1 + name = $1 + +class NamedArgument: + := (class IdentifierExpression)$1 + tokens::PUNCTUATION_ASSIGN + (class Expression)$2 + name = $1 + value = $2 + +class PositionalArgumentExpression: + := (class Expression)$1 + value = $1 + +class ArgumentExpression: + := (class PositionalArgumentExpression)$1 | (class NamedArgument)$1 + value = $1 + arg_t = 'positional' else 'keyword' + +class ArgumentListExpression: + := tokens::PUNCTUATION_OPEN_PAREN + (class ArgumentExpression)$1 + ((tokens::PUNCTUATION_COMMA + (class ArgumentExpression)$1)*)? + tokens::PUNCTUATION_CLOSE_PAREN + arguments[] = $1 + +class GenericPositionalArgumentExpression: + := (class Expression)$1 + value = $1 + +class GenericNamedArgumentExpression: + := (class IdentifierExpression)$1 + tokens::PUNCTUATION_ASSIGN + (class Expression)$2 + name = $1 + value = $2 + +class GenericArgumentExpression: + := (class GenericPositionalArgumentExpression)$1 | (class GenericNamedArgumentExpression)$1 + value = $1 + arg_t = 'positional' else 'keyword' + +class GenericInvocationExpression: + := tokens::PUNCTUATION_OPEN_ANGLE + (class GenericArgumentExpression)$1 + ((tokens::PUNCTUATION_COMMA + (class GenericArgumentExpression)$1)*)? + tokens::PUNCTUATION_CLOSE_ANGLE + arguments[] = $1 + +class ScopeAccessExpression: + := (class IdentifierExpression)$1 + (class GenericInvocationExpression?)$2 + ((tokens::OPERATOR_SCOPE + (class IdentifierExpression)$1 + (class GenericInvocationExpression?)$2)*)? + names[] = $1 + generics[] = $2 + +class DotAccessExpression: + := (class Expression)$1 + (class GenericInvocationExpression?)$2 + ((tokens::PUNCTUATION_DOT + (class Expression)$1 + (class GenericInvocationExpression?)$2)*)? + paths[] = $1 + generics[] = $2 + +class ArrayAccessExpression: + := (class Expression)$1 + tokens::PUNCTUATION_OPEN_BRACKET + (class Expression)$2 + tokens::PUNCTUATION_CLOSE_BRACKET + array = $1 + index = $2 + +class MemberAccessExpression: + := (class DotAccessExpression)$1 | (class ScopeAccessExpression)$1 + path = $1 + type = 'dot' else 'scope' + +class QualifiedPathExpression: + := ((class MemberAccessExpression)$1)* + paths[] = $1 + +class FunctionCallExpression: + := (class QualifiedPathExpression)$1 + (class GenericInvocationExpression?)$2 + (class ArgumentListExpression)$3 + function = $1 + arguments = $2 + +class ArrayLiteralExpression: + := tokens::PUNCTUATION_OPEN_BRACKET + ((class Expression)$1 + (tokens::PUNCTUATION_COMMA + (class Expression)$1)*)? + tokens::PUNCTUATION_CLOSE_BRACKET + elements[] = $1 + +class TupleLiteralExpression: + := tokens::PUNCTUATION_OPEN_PAREN + ((class Expression)$1 + (tokens::PUNCTUATION_COMMA + (class Expression)$1)*)? + tokens::PUNCTUATION_CLOSE_PAREN + elements[] = $1 + +class SetLiteralExpression: + := tokens::PUNCTUATION_OPEN_BRACE + ((class Expression)$1 + (tokens::PUNCTUATION_COMMA + (class Expression)$1)*)? + tokens::PUNCTUATION_CLOSE_BRACE + elements[] = $1 + +class MapPairExpression: + := (class Expression)$1 + tokens::PUNCTUATION_COLON + (class Expression)$1 + key = $1 + value = $2 + +class MapLiteralExpression: + := tokens::PUNCTUATION_OPEN_BRACE + ((class MapPairExpression)$1 + (tokens::PUNCTUATION_COMMA + (class MapPairExpression)$1)*)? + tokens::PUNCTUATION_CLOSE_BRACE + elements[] = $1 + +class LambdaExpression: + := tokens::KEYWORD_FUNCTION + (class ArgumentListExpression)$1 + tokens::OPERATOR_ARROW + (class Suite)$2 + arguments = $1 + body = $2 + type = 'suite' + +class PyTernaryExpression: + := (class Expression)$1 + tokens::KEYWORD_IF + (class Expression)$2 + tokens::KEYWORD_ELSE + (class Expression)$3 + condition = $2 + true = $1 + false = $3 + +class CTernaryExpression: + := (class Expression)$1 + tokens::PUNCTUATION_QUESTION_MARK + (class Expression)$2 + tokens::PUNCTUATION_COLON + (class Expression)$3 + condition = $1 + true = $2 + false = $3 + +class TernaryExpression: + := (class PyTernaryExpression)$1 | (class CTernaryExpression)$1 + condition = $1 + type = 'py' else 'c' + +class ParenthesizedExpression: + := tokens::PUNCTUATION_OPEN_PAREN + (class Expression)$1 + tokens::PUNCTUATION_CLOSE_PAREN + expression = $1 + +class CastExpression: + := (class Expression)$1 + tokens::KEYWORD_AS + (class Type)$2 + expression = $1 + value = $2 + +class InstanceOfExpression: + := ((class Expression)$1 + tokens::KEYWORD_HAS + (class Expression)$2) | ((class Expression)$1 + tokens::KEYWORD_DERIVES + (class Type)$2) + expression = $1 + value = $2 + type = 'has' | 'derives' + +class Expression: + := (class LiteralExpression)$1 | (class BinaryExpression)$1 | (class UnaryExpression)$1 | (class IdentifierExpression)$1 + | (class ArrayLiteralExpression)$1 | (class TupleLiteralExpression)$1 | (class SetLiteralExpression)$1 | (class MapLiteralExpression)$1 + | (class LambdaExpression)$1 | (class Block)$1 | (class Suite)$1 | (class TernaryExpression)$1 + | (class CastExpression)$1 | (class QualifiedPathExpression)$1 | (class ArrayAccessExpression)$1 | (class FunctionCallExpression)$1 + | (class ParenthesizedExpression)$1 + value = $1 + type = 'literal' | 'binary' | 'unary' | 'identifier' | 'array' | 'tuple' | 'set' | 'map' | 'lambda' | 'block' | 'suite' | 'ternary' | 'cast' | 'path' | 'access' | 'call' | 'parenthesized' + +// -------------------------------------------- Type -------------------------------------------- // + +class PtrType: + := ((tokens::OPERATOR_MUL | tokens::OPERATOR_BITWISE_AND) + ((class ScopeAccessExpression) | (class IdentifierExpression))$1) | (((class ScopeAccessExpression) | (class IdentifierExpression))$1 + (tokens::OPERATOR_MUL | tokens::OPERATOR_BITWISE_AND)) + value = $1 + value_t = 'scope' | 'identifier' + type = 'ptr' | 'ref' + + +class Type: + := Primitive_T$2 | ( + ((tokens::KEYWORD_UNSAFE | tokens::KEYWORD_CONST)$1)? + ((class PtrType)$2 | ((class ScopeAccessExpression) | (class IdentifierExpression))$2) + ) + (tokens::PUNCTUATION_QUESTION_MARK?)$3 + value = $2 + variant = $1 + nullable = $3 + type = 'prim' | 'ptr' | 'scope' | 'identifier' + +// ----------------------------------------- Statements ----------------------------------------- // + +class NamedVarSpecifier: + := (class VariableCreation | class VariableDeclaration)$1 + value = $1 + +class ForPyStatementCore: + := (class NamedVarSpecifier)$1 + ((tokens::PUNCTUATION_COMMA + (class NamedVarSpecifier)$1)*)? + tokens::KEYWORD_IN + (class Expression)$2 + identifiers[] = $1 + iterable = $2 + +class ForCStatementCore: + := ((class NamedVarSpecifier)$1 + ((tokens::PUNCTUATION_COMMA + (class NamedVarSpecifier)$1)*)?)? + tokens::PUNCTUATION_SEMICOLON + (class Expression?)$2 + tokens::PUNCTUATION_SEMICOLON + (class Expression?)$2 + identifiers[] = $1 + condition = $2 + increment = $3 + +class ForState: + := tokens::KEYWORD_FOR + ((tokens::PUNCTUATION_OPEN_PAREN + (class ForPyStatementCore | class ForCStatementCore)$1 + tokens::PUNCTUATION_CLOSE_PAREN) | (class ForPyStatementCore | class ForCStatementCore)$1) + (class Suite)$2 + core = $1 + body = $2 + type = 'py' | 'c' + +class WhileState: + := tokens::KEYWORD_WHILE + (class Expression)$1 + (class Suite)$2 + condition = $1 + body = $2 + +class ElseState: + := (tokens::KEYWORD_ELSE + tokens::KEYWORD_IF + (class Expression)$1 + (class Suite)$2) | (tokens::KEYWORD_ELSE + (class Suite)$1) + body = $1 + condition = $2 + type = 'else-if' | 'else' + +class IfState + := tokens::KEYWORD_IF + (class Expression)$1 + (class Suite)$2 + ((class ElseState)$1)* + condition = $1 + body = $2 + else = $3 + +class SwitchCaseState: + := tokens::KEYWORD_CASE + (class Expression)$1 + (class Suite)$2 + tokens::PUNCTUATION_SEMICOLON + condition = $1 + body = $2 + +class SwitchState: + := tokens::KEYWORD_SWITCH + (class Expression)$1 + tokens::PUNCTUATION_OPEN_BRACE + ((class SwitchCaseState)$1)* + tokens::PUNCTUATION_CLOSE_BRACE + condition = $1 + cases[] = $2 + +class YieldState: + := tokens::KEYWORD_YIELD + (class Expression)$1 + tokens::PUNCTUATION_SEMICOLON + value = $1 + +class AliasState: + := tokens::KEYWORD_AS + (class QualifiedPathExpression)$1 + path = $1 + +class SingleImportState: + := (class QualifiedPathExpression)$1 + (class AliasState)$2? + module = $1 + alias = $2 + +class MultiImportState: + := tokens::PUNCTUATION_OPEN_BRACE + ((class SingleImport)$1) + ((tokens::PUNCTUATION_COMMA + (class SingleImport)$1)*)? + tokens::PUNCTUATION_CLOSE_BRACE + imports[] = $1 + +class ImportState: + := tokens::KEYWORD_IMPORT + (class SingleImport)$1 + ((class MultiImportState)$2)? + tokens::PUNCTUATION_SEMICOLON + module = $1 + imports = $2 + +class ReturnState: + := tokens::KEYWORD_RETURN + (class Expression)$1 + tokens::PUNCTUATION_SEMICOLON + value = $1 + +class BreakState: + := tokens::KEYWORD_BREAK + tokens::PUNCTUATION_SEMICOLON + +class ContinueState: + := tokens::KEYWORD_CONTINUE + tokens::PUNCTUATION_SEMICOLON + +class ExprState: + := (class Expression)$1 + tokens::PUNCTUATION_SEMICOLON + expression = $1 + +class Statement: + := (class ImportState)$1 | (class ReturnState)$1 | (class BreakState)$1 + | (class ContinueState)$1 | (class ExprState)$1 | (class IfState)$1 + | (class SwitchState)$1 | (class WhileState)$1 | (class ForState)$1 + | (class YieldState)$1 | (class Suite)$1 + value = $1 + type = 'import' | 'return' | 'break' | 'continue' | 'expression' | 'if' | 'switch' | 'while' | 'for' | 'yield' | 'suite' + +// ----------------------------------------- Declarations --------------------------------------- // + +class VariableDeclaration: + := TypeQualifier_T$1 + tokens::KEYWORD_LET + (class IdentifierExpression)$2 + (class TypedCore)$3 + tokens::PUNCTUATION_SEMICOLON + qualifier = $1 + name = $2 + type = $3 + +class FFIDeclaration: + := ((VisibilitySpecifier_T?)$1 + (FunctionSpecifier_T?)$2) + tokens::KEYWORD_FFI + tokens::LITERAL_STRING$3 + (class FunctionDeclaration)$4 + visibility = ['public', 'private', 'protected']$1 + specifier = ['inline', 'abstract', 'const', 'override', 'eval']$2 + ffi = $3 + function = $4 + +class GenericBound: + := tokens::KEYWORD_IF + (class InstanceOfExpression)$1 + (tokens::PUNCTUATION_COMMA + ((class InstanceOfExpression)$1)*)? + bounds[] = $1 + +class ConstGenericParameter: + := tokens::KEYWORD_CONST + (class IdentifierExpression)$1 + (class TypedCore)$2 + name = $1 + value = $2 + +class GenericParameter: + := (class ConstGenericParameter)$1 | (class IdentifierExpression)$1 + name = $1 + type = 'const' else 'identifier' + +class GenericParameterList: + := tokens::PUNCTUATION_OPEN_ANGLE + ((class GenericParameter)$1 + (tokens::PUNCTUATION_COMMA + (class GenericParameter)$1)*)? + tokens::PUNCTUATION_CLOSE_ANGLE + parameters[] = $1 + +class GenericDeclaration: + := tokens::KEYWORD_REQUIRES + (class GenericParameterList)$1 + (class GenericBound?)$2 + parameters = $1 + bounds = $2 + +class VariableCreation: + := TypeQualifier_T$1 + (class IdentifierExpression)$2 + (class TypedCore)$3 + qualifier = $1 + name = $2 + value = $3 + +class ArgumentsDeclaration: + := tokens::PUNCTUATION_OPEN_PAREN + ((class VariableCreation)$1 + (tokens::PUNCTUATION_COMMA + (class VariableCreation)$1)*)? + tokens::PUNCTUATION_CLOSE_PAREN + arguments[] = $1 + +class FunctionDeclaration: + := ((VisibilitySpecifier_T?)$1 + (FunctionSpecifier_T?)$2) + tokens::KEYWORD_FUNCTION + + (class QualifiedPathExpression)$3 + (class ArgumentsDeclaration)$4 + tokens::OPERATOR_ARROW + + (class Type)$5 + (class GenericDeclaration?)$6 + (class Suite)$7 + visibility = ['public', 'private', 'protected']$1 + specifier = ['inline', 'abstract', 'const', 'override', 'eval']$2 + name = $3 + arguments = $4 + return_type = $5 + generics = $6 + body = $7 + +class EnumValueDeclaration: + := (class IdentifierExpression)$1 + (tokens::OPERATOR_ASSIGN + (class Expression)$2)? + name = $1 + value = $2 + +class EnumDeclaration: + := ((VisibilitySpecifier_T?)$1 + (FunctionSpecifier_T?)$2) + tokens::KEYWORD_ENUM + (class IdentifierExpression)$3 + tokens::PUNCTUATION_OPEN_BRACE + + ((class EnumValueDeclaration)$4 + (tokens::PUNCTUATION_COMMA + (class EnumValueDeclaration)$4)*)? + tokens::PUNCTUATION_CLOSE_BRACE + visibility = ['public', 'private', 'protected']$1 + specifier = ['inline', 'abstract', 'const', 'override', 'eval']$2 + name = $3 + values[] = $4 + +class TypeDeclaration: + := (VisibilitySpecifier_T?)$1 + tokens::KEYWORD_TYPE + (class IdentifierExpression)$3 + (class GenericDeclaration?)$4 + tokens::OPERATOR_ASSIGN + (class Expression)$5 + tokens::PUNCTUATION_SEMICOLON + visibility = ['public', 'private', 'protected']$1 + name = $3 + generics = $4 + value = $5 + +class StructDeclaration: + := ((VisibilitySpecifier_T?)$1 + (FunctionSpecifier_T?)$2) + tokens::KEYWORD_STRUCT + (class IdentifierExpression)$3 + (class GenericDeclaration?)$4 + (class Suite)$5 + visibility = ['public', 'private', 'protected']$1 + specifier = ['inline', 'abstract', 'const', 'override', 'eval']$2 + name = $3 + generics = $4 + body = $5 + +class ClassDeclaration: + := ((VisibilitySpecifier_T?)$1 + (FunctionSpecifier_T?)$2) + tokens::KEYWORD_CLASS + (class IdentifierExpression)$3 + (class GenericDeclaration?)$4 + (class Suite)$5 + visibility = ['public', 'private', 'protected']$1 + specifier = ['inline', 'abstract', 'const', 'override', 'eval']$2 + name = $3 + generics = $4 + body = $5 + +class AbstractDeclaration: + := (VisibilitySpecifier_T?)$1 + tokens::KEYWORD_ABSTRACT + (class IdentifierExpression)$3 + (class GenericDeclaration?)$4 + (class Suite)$5 + visibility = ['public', 'private', 'protected']$1 + name = $3 + generics = $4 + body = $5 + +class InterfaceDeclaration: + := (VisibilitySpecifier_T?)$1 + tokens::KEYWORD_INTERFACE + (class IdentifierExpression)$3 + (class GenericDeclaration?)$4 + (class Suite)$5 + visibility = ['public', 'private', 'protected']$1 + name = $3 + generics = $4 + body = $5 + +class UnionDeclaration: + := (VisibilitySpecifier_T?)$1 + tokens::KEYWORD_UNION + (class IdentifierExpression)$3 + (class GenericDeclaration?)$4 + (class Suite)$5 + visibility = ['public', 'private', 'protected']$1 + name = $3 + generics = $4 + body = $5 + +class Declarations: + := (class VariableDeclaration)$1 | (class FunctionDeclaration)$1 | (class EnumDeclaration)$1 | (class TypeDeclaration)$1 + | (class StructDeclaration)$1 | (class ClassDeclaration)$1 | (class AbstractDeclaration)$1 | (class InterfaceDeclaration)$1 + | (class UnionDeclaration)$1 | (class FFIDeclaration)$1 + value = $1 + type = 'variable' | 'function' | 'enum' | 'type' | 'struct' | 'class' | 'abstract' | 'interface' | 'union' | 'ffi' + +// ----------------------------------------- Annotations ---------------------------------------- // + +class CompilerDirective: + := tokens::LITERAL_COMPLIER_DIRECTIVE$1 + value = $1 + +class Comment: + := tokens::PUNCTUATION_SINGLE_LINE_COMMENT$1 | tokens::PUNCTUATION_MULTI_LINE_COMMENT$1 + value = $1 + type = 'single' | 'multi' + +// -------------------------------------------- Suite ------------------------------------------- // + +class Block: + := tokens::PUNCTUATION_OPEN_BRACE + ((class Statement)$1)* + tokens::PUNCTUATION_CLOSE_BRACE + statements[] = $1 + +class InlineBlock: + := tokens::PUNCTUATION_COLON + (class Statement)$1 + statement = $1 + +class Suite: + := (class Block)$1 | (class InlineBlock)$1 | tokens::PUNCTUATION_SEMICOLON + statements[] = $1 + type = 'block' | 'inline' | 'empty' + +class TypedCore: + := tokens::PUNCTUATION_COLON + (class Type)$1 (tokens::OPERATOR_ASSIGN + (class Expression)$2)? + type = $1 + value = $2 + +// -------------------------------------------- Root -------------------------------------------- // + +class Root: + := ((class Declarations)$1 | (class Statement)$1 | (class Suite)$1 | (class CompilerDirective)$1 | (class Comment)$1 | (class Expression)$1)* + value = $1 + type = 'declarations' | 'statement' | 'suite' | 'directive' | 'comment' diff --git a/language/all_keyword_usage.hlx b/language/all_keyword_usage.hlx index 41f3a28..b4e8d99 100644 --- a/language/all_keyword_usage.hlx +++ b/language/all_keyword_usage.hlx @@ -85,11 +85,69 @@ const for i in 0:10 { } +class Point { + let static n_points = 0; + + static const fn get_n_points() -> int { + return Point::n_points; + } + + + static fn add_point() { + Point::n_points += 1; + } +} + + +// HARD ERROR +inline const async panic fn div_by_0_hard_a(a: int, b: int = 0) -> int { // force try catch handling + return a / b; +} + +// HARD ERROR - Not forced to handle +fn div_by_0_hard_b(a: int, b: int = 0) -> int { + return a / b; +} + +// Error as value +fn div_by_0_soft(a: int, b: int = 0) -> Result { + if b == 0 { + return DivByZeroError(); + } + + return a / b; +} + +fn main() { + // SOFT ERROR + let const a = div_by_0_soft(10, 0); + + if a.is_err() { + print("DivByZeroError"); + } else { + let a = a.unwrap(); + } + + // HARD ERROR + try { + let b = div_by_0_hard_a(10, 0); + } catch (err: DivByZeroError) { + print("DivByZeroError"); + } + + // or + + let b = try div_by_0_hard_a(10, 0) catch (err: DivByZeroError) 10 catch (err: BaseError) 9; + + let c = div_by_0_hard_b(10, 0); // not forced to handle but you can if you want +} + + -/// 11 +/// 11 while true { break; } @@ -136,7 +194,7 @@ return ( )(a, b); )(a, b); - + let foo: tuple = (1, 2, 3, 4, 4, 5, 6) let foo: (u8) = (6) // says error that not let foo: u8 = 6 @@ -179,7 +237,7 @@ f64 > 64 bytes let a:u32 = 10; a.add(1) -in cpp +in cpp std::uint_32 add (std::uint_32 a, std::uint_32 b) { return a + b; @@ -208,6 +266,9 @@ module idk_something_else { let inst = Foo(); inst.add(); + + + try { errorable_fn_returns_result() } catch (err:Err) { }; } @@ -215,6 +276,8 @@ module idk_something_else { + + // ffi "py" import os; ffi "py" import time; ffi "py" import // math; fn main() { let A: float = 0.0; let B: // float = 0.0; while true { let z: list = [0.0]*1760; let @@ -250,5 +313,3 @@ import "get_fooled/foo.hlix" as foo; pub import get_fooled::foo::{SomenamespaceInFOO} as thing; - - diff --git a/language/helix.ebnf b/language/helix.ebnf index 098efa7..07ebda8 100644 --- a/language/helix.ebnf +++ b/language/helix.ebnf @@ -1,15 +1,15 @@ /* Main Program Structure */ -Program ::= (ImportStatement | PreprocessorDirective | Declaration | FunctionDefinition | Statement)* +Program ::= (ImportState | PreprocessorDirective | Declaration | FunctionDefinition | Statement)* /* Modules and Imports */ Module ::= 'module' QualifiedNamespaceID Suite // module ... { :: ... }.. -ImportStatement ::= 'import' QualifiedNamespaceID ('::' '{' (QualifiedNamespaceID (',' QualifiedNamespaceID)*) '}')? ('as' QualifiedNamespaceID)? ';' +ImportState ::= 'import' QualifiedNamespaceID ('::' '{' (QualifiedNamespaceID (',' QualifiedNamespaceID)*) '}')? ('as' QualifiedNamespaceID)? ';' -FFIImportStatement ::= 'ffi' String ImportStatement +FFIImportState ::= 'ffi' String ImportState /* Preprocessor Directives */ @@ -29,17 +29,17 @@ PyStyleForLoop ::= AnySeparatedID (':' Type)? 'in' Expression WhileLoop ::= 'while' Expression Suite -IfStatement ::= ('if' | 'unless') Expression Suite +IfState ::= ('if' | 'unless') Expression Suite -ElseIfStatement ::= 'else' ('if' | 'unless') Expression Suite +ElseIfState ::= 'else' ('if' | 'unless') Expression Suite -ElseStatement ::= 'else' Suite +ElseState ::= 'else' Suite -ContinueStatement ::= 'continue' ';' +ContinueState ::= 'continue' ';' -BreakStatement ::= 'break' ';' +BreakState ::= 'break' ';' -SwitchStatement ::= 'switch' '{' (CaseStatement | DefaultCaseStatement)* '}' +SwitchState ::= 'switch' '{' (CaseStatement | DefaultCaseStatement)* '}' CaseStatement ::= 'case' Expression Suite @@ -181,7 +181,7 @@ Assignment ::= AnySeparatedID '=' Expression ';' Statement ::= VariableDeclaration | Assignment | Expression ';' | ControlFlowStatement | ReturnExpression | YieldExpression | BlockStatement -ControlFlowStatement ::= ForLoop | WhileLoop | IfStatement | UnlessStatement | ElseIfStatement | ElseStatement | ContinueStatement | BreakStatement | SwitchStatement | MatchExpression +ControlFlowStatement ::= ForLoop | WhileLoop | IfState | UnlessStatement | ElseIfState | ElseState | ContinueState | BreakState | SwitchState | MatchExpression BlockStatement ::= Suite diff --git a/language/helix/pkgs/std/linked_list.hlx b/language/helix/pkgs/std/linked_list.hlx new file mode 100644 index 0000000..e293e34 --- /dev/null +++ b/language/helix/pkgs/std/linked_list.hlx @@ -0,0 +1,113 @@ +//===----------------------------------------- Helix ------------------------------------------===// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // +// You are allowed to use, modify, redistribute, and create derivative works, even for commercial // +// purposes, provided that you give appropriate credit, and indicate if changes were made. // +// For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +//===------------------------------------------------------------------------------------------===// + +#[link-time] +import types::{Allocator}; +import alloc::{DefaultAllocator}; + +class IntNode { + let data: int; + let link: *IntNode? = &null; + + fn IntNode(self, data: int, link: *IntNode?) { + self.data = data; + self.link = link; + } + + fn getData(self) -> int { + return self.data; + } + + fn getLink(self) -> *IntNode? { + return self.link; + } + + fn setData(self, new_data: int) { + self.data = new_data; + } + + fn setLink(self, new_link: *IntNode?) { + self.link = new_link; + } + + fn addNodeAfter(self, new_data: int) -> *IntNode { + let link = IntNode(new_data, self.link); + self.link = &link; + return &link; + } +} + +fn listLength(head: *IntNode) -> int { + let count = 0; + let *current = head; + + while (*current).getLink() != &null { + count += 1; + current = current.getLink(); + } + + return count; +} + +fn listSearch(head: *IntNode, target: int) -> *IntNode { + let *current = head; + + while (*current).getLink() != &null { + if (*current).getData() == target { + return current; + } + current = current.getLink(); + } + + return &null; +} + +fn listRemoveNode(head: *IntNode, target: int) { + // remove and free + + let *current = head; + let *previous = &null; + + finally: + try: + // free memory after scope or error + Allocator::free(current); + catch: + // a SegmentationFaultError is diffrent from a SIGSEGV + // it is a safe way to handle segfaults as software errors + // and not hardware errors like SIGSEGV. + panic SegmentationFaultError("Failed to free memory"); + + while (*current).getLink() != &null { + if (*current).getData() == target { + (*previous).setLink((*current).getLink()); + return; + } + + previous = current; + current = current.getLink(); + } +} + +fn main() { + let head = IntNode(1, &null); + let *tail = &head; + + for i in 2..100 { + tail = tail.addNodeAfter(i); + } + + let length: int = listLength(&head); + let target: *IntNode? = listSearch(&head, 50); +} + + diff --git a/language/helix/pkgs/std/types.hlx b/language/helix/pkgs/std/types.hlx index f990a84..9ed780b 100644 --- a/language/helix/pkgs/std/types.hlx +++ b/language/helix/pkgs/std/types.hlx @@ -26,67 +26,76 @@ // //===------------------------------------------------------------------------------------------===// -abstract Allocator: +abstract Allocator { // allocates a block of memory of at least `size` bytes with the specified alignment. // returns a pointer to the allocated memory or a null pointer on failure. - fn alloc(self, size: usize, alignment: usize) -> *void: - ... + fn alloc(self, size: usize, alignment: usize) -> *void {} // deallocates a block of memory previously allocated by `alloc`. // the pointer `ptr` must point to the beginning of a block returned by `alloc`. - fn dealloc(self, ptr: *void, size: usize, alignment: usize): - ... + fn dealloc(self, ptr: *void, size: usize, alignment: usize) {} // reallocates a block of memory to a new size, with the specified alignment. // the pointer `ptr` must point to the beginning of a block returned by `alloc`. // returns a pointer to the newly allocated memory or a null pointer on failure. - fn realloc(self, ptr: *void, old_size: usize, new_size: usize, alignment: usize) -> *void: - ... + fn realloc(self, ptr: *void, old_size: usize, new_size: usize, alignment: usize) -> *void {} // optional: allocates a block of memory with default alignment (e.g., 8 or 16 bytes). - fn alloc_d(self, size: usize) -> *void: - if !self.can_alloc(size, 16): - panic SegmentationFault(f"alloc: cant allocate the specified:size}.") + fn alloc_d(self, size: usize) -> *void { + if !self.can_alloc(size, 16) { + panic SegmentationFault(f"alloc: cant allocate the specified:size}."); + } - return self.alloc(size, 16) // default to 16-byte alignment + return self.alloc(size, 16); // default to 16-byte alignment + } // optional: reallocates memory with default alignment. - fn realloc_d(self, ptr: *void, old_size: usize, new_size: usize) -> *void: - return self.realloc(ptr, old_size, new_size, 16) // default to 16-byte alignment + fn realloc_d(self, ptr: *void, old_size: usize, new_size: usize) -> *void { + return self.realloc(ptr, old_size, new_size, 16); // default to 16-byte alignment + } // optional: retrieves statistics about the allocator's memory usage. - fn get_stats(self) -> AllocatorStats: - return AllocatorStats::new() // return a default stats object + fn get_stats(self) -> AllocatorStats { + return AllocatorStats::new(); // return a default stats object + } // checks if the allocator can satisfy an allocation of a given size and alignment. // useful for checking if the allocator is capable before attempting an allocation. - fn can_alloc(self, size: usize, alignment: usize) -> bool: - return true // by default, assume the allocator can handle it + fn can_alloc(self, size: usize, alignment: usize) -> bool { + return true; // by default, assume the allocator can handle it + } +} -interface Interop: +interface Interop { // everything here works with tokens - eval fn import_to_helix(node: *ast::FFIImportNode) -> code_gen::CGObj: - finally: - delete node - delete node // double free + eval fn import_to_helix(node: *ast::FFIImportNode) -> code_gen::CGObj { + finally { + delete node; + delete node; // double free + } - let import_path = *node.value - - if *node._ffi != "py": - panic CompileError("invalid ffi standard") + let import_path = *node.value; + + if *node._ffi != "py" { + panic CompileError("invalid ffi standard"); + } // FusionX + } +} // structure to hold memory statistics (optional feature) -struct AllocatorStats: - let total_allocations: usize - let total_deallocations: usize - let currently_allocated: usize - let max_allocated: usize +struct AllocatorStats { + let total_allocations: usize; + let total_deallocations: usize; + let currently_allocated: usize; + let max_allocated: usize; - fn new() -> AllocatorStats: + fn new() -> AllocatorStats { return { - total_allocations = 0 - total_deallocations = 0 - currently_allocated = 0 + total_allocations = 0; + total_deallocations = 0; + currently_allocated = 0; } + } +} \ No newline at end of file diff --git a/libs/PEGTL b/libs/PEGTL new file mode 160000 index 0000000..d7b821b --- /dev/null +++ b/libs/PEGTL @@ -0,0 +1 @@ +Subproject commit d7b821b1e5ed6ab321625f50427c4ae0b78909d5 diff --git a/libs/neo-json/include/json.hh b/libs/neo-json/include/json.hh index f640a4b..521084f 100644 --- a/libs/neo-json/include/json.hh +++ b/libs/neo-json/include/json.hh @@ -128,6 +128,12 @@ inline namespace _json { return *this; } + template + Json &add(const T &val) { + _array.push_back(get(val)); + return *this; + } + Json §ion(const string &key) { if (_data.contains(key)) { if (auto *sub_json = std::get_if(&_data[key])) { @@ -138,6 +144,11 @@ inline namespace _json { return std::get(_data[key]); } + template + void section(const string &key, const T &val) { + _data[key] = get(val); + } + [[nodiscard]] constexpr string to_string(bool is_base = true) const { string result; @@ -201,8 +212,8 @@ inline namespace _json { } private: - string key; - string _val; + string key; + string _val; JsonVec_t _array; }; diff --git a/libs/neo-panic/enums/error_codes.def b/libs/neo-panic/enums/error_codes.def index 0dd4bb6..69825ed 100644 --- a/libs/neo-panic/enums/error_codes.def +++ b/libs/neo-panic/enums/error_codes.def @@ -43,9 +43,9 @@ const helix::CompTimeMap ERROR_MAP({ // Compile-time Errors MP(2.0001, Errors{"undefined variable '{}'", "declare the variable '{}' before using it.", error::ERR}), MP(2.1001, Errors{"file not found, '{}'", "", error::FATAL}), - MP(2.1002, Errors{"unterminated {}"}), + MP(2.1002, Errors{"unterminated {}", ""}), MP(2.1003, Errors{"failed to read file, '{}'", "maybe a unicode decoding error?", error::FATAL}), - MP(2.1004, Errors{"Expected a {}"}), + MP(2.1004, Errors{"Expected a {}", ""}), MP(2.0002, Errors{"unused variable '{}'", "remove the variable '{}' or use it in your code.", error::WARN}), MP(3.0001, Errors{"type mismatch: expected '{}', found '{}'", "ensure the types match: expected '{}', but found '{}'.", error::ERR}), MP(4.0001, Errors{"missing semicolon", "add a semicolon at the end of the statement.", error::ERR}), @@ -86,7 +86,7 @@ const helix::CompTimeMap ERROR_MAP({ MP(0.7002, Errors{"invalid global define", "ensure correct syntax and usage of the global define directive.", error::ERR}), MP(0.7003, Errors{"incorrect macro usage", "ensure the macro is defined and used correctly.", error::ERR}), MP(0.7004, Errors{"disallowed abi option, abi should only be a string.", "use one of allowed abi options [{}]", error::ERR}), - MP(0.7005, Errors{"missing required abi identifier"}), + MP(0.7005, Errors{"missing required abi identifier", ""}), MP(0.7006, Errors{"invalid symbol `#`", "if you meant to invoke a macro or compiler directive. use `#[...]` no spaces in between.", error::FATAL}), MP(0.7007, Errors{"attributes are not supported in this version of helix", "remove usage", error::FATAL}), MP(0.7008, Errors{"shorthand scope declaration is not allowed for 'module'", "", error::ERR}), diff --git a/libs/neo-panic/include/error.hh b/libs/neo-panic/include/error.hh index 6330077..2b6cfef 100644 --- a/libs/neo-panic/include/error.hh +++ b/libs/neo-panic/include/error.hh @@ -105,7 +105,7 @@ struct Errors { struct CodeError { token::Token *pof; //< point of failure - float err_code; + double err_code; bool mark_pof = true; string_vec fix_fmt_args; string_vec err_fmt_args; @@ -116,7 +116,7 @@ struct CodeError { struct CompilerError { - float err_code; + double err_code; string_vec fix_fmt_args; string_vec err_fmt_args; }; @@ -143,7 +143,7 @@ class Panic { static inline CodeError create_old_CodeError(token::Token *pof, - float err_code, + const double err_code, string_vec fix_fmt_args = {}, string_vec err_fmt_args = {}, fix_pair_vec opt_fixes = {}) { diff --git a/libs/neo-panic/source/error.cc b/libs/neo-panic/source/error.cc index 7e34fd2..1383c42 100644 --- a/libs/neo-panic/source/error.cc +++ b/libs/neo-panic/source/error.cc @@ -28,7 +28,6 @@ #include "neo-pprint/include/hxpprint.hh" #include "token/include/token.hh" - namespace std { static inline void lstrip(std::string &str) { str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](unsigned char chr) { @@ -460,7 +459,7 @@ void Panic::show_error() { // Check if the current line is blank if (line_content.empty()) { - auto next_it = it + 1; + auto next_it = std::next(it); // safer alternative to it + 1 size_t blank_count = 1; // Count consecutive blank lines @@ -476,17 +475,20 @@ void Panic::show_error() { // Keep only one blank line if more than one consecutive blank lines if (blank_count > 1) { - it = lines.erase(it + 1, it + blank_count); + // Use `erase` and update the iterator + it = lines.erase(std::next(it), next_it); // safely erase using `next_it` + } else { + ++it; } + } else { + ++it; } - - it++; } // add the message formatted_error += A_W + final_err.level + ": " + final_err.msg + string(colors::reset) + "\n"; // fatal: missing semicolon - formatted_error += A_W + string(level_len-1, ' ') + "--> at " + + formatted_error += A_W + string(level_len - 1, ' ') + "--> at " + format_loc_info(final_err.file, final_err.line, final_err.col) + "\n"; string left_side; diff --git a/libs/neo-pprint/include/ansi_colors.hh b/libs/neo-pprint/include/ansi_colors.hh index daca4b8..8b375e1 100644 --- a/libs/neo-pprint/include/ansi_colors.hh +++ b/libs/neo-pprint/include/ansi_colors.hh @@ -18,9 +18,9 @@ #define COLORS_ALLOWED #ifdef COLORS_ALLOWED - #define CREATE_COLOR(COLOR, CODE) inline constexpr const char *COLOR = CODE; + #define CREATE_COLOR(COLOR, CODE) inline const char *COLOR = CODE; #else - #define CREATE_COLOR(COLOR, CODE) inline constexpr const char *COLOR = ""; + #define CREATE_COLOR(COLOR, CODE) inline const char *COLOR = ""; #endif namespace colors { @@ -105,7 +105,7 @@ inline namespace fg256 { CREATE_COLOR(grey3, "\x1b[38;5;234m"); CREATE_COLOR(grey4, "\x1b[38;5;235m"); CREATE_COLOR(grey5, "\x1b[38;5;236m"); - inline const constexpr char *custom(int red, int green, int blue) { + inline const char *custom(int red, int green, int blue) { const int BASE = 0x10; const int COLOR = 0x24; std::string code = "\x1b[38;5;"; @@ -139,7 +139,7 @@ inline namespace bg256 { CREATE_COLOR(grey3, "\x1b[48;5;234m"); CREATE_COLOR(grey4, "\x1b[48;5;235m"); CREATE_COLOR(grey5, "\x1b[48;5;236m"); - inline const constexpr char *custom(int red, int green, int blue) { + inline const char *custom(int red, int green, int blue) { const int BASE = 0x10; const int COLOR = 0x24; std::string code = "\x1b[48;5;"; diff --git a/source/README b/source/README new file mode 100644 index 0000000..4ecab1c --- /dev/null +++ b/source/README @@ -0,0 +1,57 @@ +# Helix Programming Language - Source Directory + +Welcome to the source directory of the **Helix Programming Language**. This directory contains all the essential components that power the Helix compiler. Below is an overview of each subdirectory and its purpose within the project. + +## 1. Directory Structure Overview + +### [source/cli](cli) +This directory contains the source code for the **Command Line Interface (CLI)** of Helix. It handles user input and serves as the entry point for running the compiler from the command line. + +- `include`: Header files for CLI functionality. +- `source`: Implementation of the CLI logic. + +### [source/core](core) +This directory contains utility functions and classes used across the Helix project. **Note:** This module is planned to be removed in future updates as its functionality is being refactored or replaced. + +- `utils`: Common utility functions shared across the compiler. + +### [source/driver](driver) +The **driver** manages the compilation process by handling I/O and orchestrating the various stages of compilation. While originally planned as the compilation manager, it primarily focuses on handling I/O calls. + +- `include`: Header files for the driver. +- `lib`: Driver libraries. +- `source`: Core logic of the driver. + +### [source/generator](generator) +This directory holds the code for **code generation (codegen)** in Helix. It converts Helix AST into intermediate representations (CIR and LLVM-IR) and eventually into optimized machine code. + +- `CC-IR`: Code generation to Helix's custom CIR (Compiler Intermediate Representation). +- `LLVM-IR`: Code generation to LLVM-IR for backend compilation. +- `include`: Header files for the generator. + +### [source/include](include) +Contains the **public-facing API** for Helix. This interface allows external tools and libraries to interact with Helix's backend and compiler toolchain. + +- `api`: Public API headers for integration and extension. + +### [source/lexer](lexer) +The **lexer** converts source code into a stream of tokens, which serve as the building blocks for the parser. It defines how Helix understands its syntax. + +- `include`: Lexer-related header files. +- `source`: Tokenization logic implementation. + +### [source/parser](parser) +The **parser** transforms tokens into an Abstract Syntax Tree (AST) and Concrete Syntax Tree (CST). It also converts C++ AST symbols into Helix AST symbols using the Clang Frontend. + +- `ast`: AST-related code and visitors for node traversal. +- `cpp`: Integration with C++ AST. +- `cst`: CST generation. +- `preprocessor`: Handles preprocessor logic, such as macro expansion. + +### [source/token](token) +This directory defines the **token** types used by the lexer. Tokens represent the smallest units of meaning (such as keywords, operators, and literals) in Helix source code. + +- `enums`: Enumerations for token types. +- `types`: Definitions of token-related types. +- `include`: Token headers. +- `source`: Tokenization logic and token classes. diff --git a/source/core/utils/josnify.hh b/source/core/utils/josnify.hh index 5af5b93..2a8775e 100644 --- a/source/core/utils/josnify.hh +++ b/source/core/utils/josnify.hh @@ -299,9 +299,8 @@ class Jsonify { } Jsonify &create_sub(const std::string &sub_section_key) { - sub_json.push_back( - std::make_shared(std::string(sub_section_key), this->depth + 1)); - Jsonify &jsonify_ref = *sub_json.back().get(); + sub_json.push_back(std::make_shared(std::string(sub_section_key), this->depth + 1)); + Jsonify &jsonify_ref = *sub_json.back(); return jsonify_ref; } diff --git a/source/driver/lib/__win32_cwd.inc b/source/driver/lib/__win32_cwd.inc index 8a6ee75..130f191 100644 --- a/source/driver/lib/__win32_cwd.inc +++ b/source/driver/lib/__win32_cwd.inc @@ -1,18 +1,23 @@ #ifndef __WIN32_CWD_INC__ #define __WIN32_CWD_INC__ -const char *cwd_env = std::getenv("PWD"); -if (cwd_env != nullptr) { - return {cwd_env}; -} +// Use _dupenv_s for safer environment variable access +char* cwd_env = nullptr; +size_t len = 0; +errno_t err = _dupenv_s(&cwd_env, &len, "PWD"); -// fallback to using sys calls -std::array buffer{}; +if (err == 0 && cwd_env != nullptr) { + std::string cwd_str{cwd_env}; + free(cwd_env); // Free the memory allocated by _dupenv_s + return cwd_str; +} +// Fallback to using system calls +std::array buffer{}; DWORD length = GetCurrentDirectory(static_cast(buffer.size()), buffer.data()); if (length == 0) { - throw std::runtime_error("failed to get cwd, set the envrionment variable 'PWD': " + - std::to_string(GetLastError())); + throw std::runtime_error("Failed to get cwd, set the environment variable 'PWD': " + + std::to_string(GetLastError())); } -#endif // __WIN32_CWD_INC__ \ No newline at end of file +#endif // __WIN32_CWD_INC__ diff --git a/source/driver/source/get_cwd.cc b/source/driver/source/get_cwd.cc index 0b60b84..2cbe856 100644 --- a/source/driver/source/get_cwd.cc +++ b/source/driver/source/get_cwd.cc @@ -16,7 +16,11 @@ #include "driver/include/file_system.hh" #if defined(_WIN32) || defined(_WIN64) +# include +# include # include +# include +# include # define PATH_MAX MAX_PATH #else # include diff --git a/source/generator/helix/README b/source/generator/LLVM-IR/README similarity index 100% rename from source/generator/helix/README rename to source/generator/LLVM-IR/README diff --git a/source/generator/helix/include/transpiler.hh b/source/generator/LLVM-IR/include/transpiler.hh similarity index 100% rename from source/generator/helix/include/transpiler.hh rename to source/generator/LLVM-IR/include/transpiler.hh diff --git a/source/generator/include/cxx_emitter.hh b/source/generator/include/cxx_emitter.hh index dc130f2..caa2203 100644 --- a/source/generator/include/cxx_emitter.hh +++ b/source/generator/include/cxx_emitter.hh @@ -19,7 +19,7 @@ #define __CXX_EMITTER_HH__ #include "core/utils/josnify.hh" -#include "parser/ast/include/AST_visitor.hh" +#include "parser/ast/include/core/AST_visitor.hh" namespace codegen::cxx { enum class GenerateMode { diff --git a/source/helix.cc b/source/helix.cc index f0f4ec8..9432e1c 100644 --- a/source/helix.cc +++ b/source/helix.cc @@ -11,6 +11,22 @@ // //===------------------------------------------------------------------------------------------===// +// if DEBUG and is windows + +#include "parser/ast/include/config/AST_modifiers.hh" +#include "parser/ast/include/core/AST_nodes.hh" +#include "parser/ast/include/types/AST_jsonify_visitor.hh" +#include "parser/ast/include/types/AST_types.hh" +#include "token/include/generate.hh" +#define _SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING +#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING +#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS + +#ifdef MSVC +#pragma comment(linker, "/STACK:2000000000") // Set stack size to 2MB +#pragma comment(linker, "/HEAP:2000000000") // Set heap size to 2MB +#endif + #include #include #include @@ -18,14 +34,12 @@ #include "cli/include/cli.hh" #include "driver/include/file_system.hh" +#include "lexer/include/lexer.hh" #include "neo-panic/include/error.hh" #include "neo-pprint/include/hxpprint.hh" -#include "lexer/include/lexer.hh" #include "parser/ast/include/AST.hh" -#include "parser/ast/include/AST_jsonify_visitor.hh" #include "parser/cpp/fn_signatures.hh" #include "parser/preprocessor/include/preprocessor.hh" -#include "token/include/generate.hh" #include "token/include/token_list.hh" int compile(int argc, char **argv) { @@ -33,8 +47,6 @@ int compile(int argc, char **argv) { using namespace parser::lexer; using namespace parser::preprocessor; - printf(""); - // relative to current working dir in POSIX shell (cmd/bash) command_line::CLIArgs parsed_args(argc, argv, "0.0.1-alpha-0112"); check_exit(parsed_args); @@ -46,30 +58,18 @@ int compile(int argc, char **argv) { auto start = std::chrono::high_resolution_clock::now(); // read the file and tokenize its contents : stage 0 + print("tokenizing...", sysIO::endl('\r')); TokenList tokens = Lexer(file_system::read_file(parsed_args.file), parsed_args.file).tokenize(); std::vector pkg_paths = {"/Volumes/Container/Projects/Helix/helix-lang/helix/pkgs"}; // preprocess the tokens with optional module import paths : stage 1 + print("preprocessing...", sysIO::endl('\r')); Preprocessor(tokens, "main", pkg_paths).parse(); // preprocessor::import_tree->print_tree(preprocessor::import_tree->get_root()); // print the preprocessed tokens - auto end = std::chrono::high_resolution_clock::now(); - - if (parsed_args.emit_ast) { - // for testing only change to parse an entire program when done with ast - auto ast = parser::ast::get_Expression(tokens); - - ast->parse(); - - end = std::chrono::high_resolution_clock::now(); - auto visit = parser::ast::visitors::JsonifyVisitor(); - ast->accept(visit); - - print(visit.json); - } if (parsed_args.emit_tokens) { // print(tokens.to_json()); @@ -77,11 +77,70 @@ int compile(int argc, char **argv) { print_tokens(tokens); } + { // remove all comments form `tokens` + TokenList new_tokens; + + for (auto &token : tokens) { + if (token->token_kind() != token::PUNCTUATION_SINGLE_LINE_COMMENT && + token->token_kind() != token::PUNCTUATION_MULTI_LINE_COMMENT) { + new_tokens.push_back(token.current().get()); + } + } + + tokens = new_tokens; // FIXME: integrate this into the parser + } + + // generate ast from the given tokens : stage 2 + auto iter = tokens.begin(); + + print("parsing... ", sysIO::endl('\r')); + + parser::ast::NodeV<> ast; + parser::ast::ParseResult<> expr; + + while (iter.remaining_n() != 0) { + print("parsing.. ", sysIO::endl('\r')); + auto decl = parser::ast::node::Declaration(iter); + expr = decl.parse(); + + print("parsing. ", sysIO::endl('\r')); + if (!expr.has_value()) { + expr.error().panic(); + print(expr.error().what()); + + break; + } + + ast.emplace_back(expr.value()); + print("Parsing...", sysIO::endl('\r')); + } + + if (!expr.has_value()) { + print("aborting...", sysIO::endl('\r')); + } else { + print("parsed ", sysIO::endl('\r')); + } + + if (parsed_args.emit_ast) { + std::vector node_json; + + for (auto &node : ast) { + parser::ast::visitor::Jsonify json_visitor; + node->accept(json_visitor); + node_json.push_back(json_visitor.json); + } + + print(neo::json("ast").add("Decls", node_json).to_string()); + } + + auto end = std::chrono::high_resolution_clock::now(); std::chrono::duration diff = end - start; - // Print the time taken in nanoseconds and milliseconds - print("time taken: ", diff.count() * 1e+9, " ns"); - print(" ", diff.count() * 1000, " ms"); + if (parsed_args.verbose) { + // Print the time taken in nanoseconds and milliseconds + print("time taken: ", diff.count() * 1e+9, " ns"); + print(" ", diff.count() * 1000, " ms"); + } return 0; } @@ -90,11 +149,11 @@ int main(int argc, char **argv) { try { compile(argc, argv); } catch (error::Panic &) { - // if (error::HAS_ERRORED) { - // for (const auto& err : error::ERRORS) { - // print(err.to_json()); - // } - // } + if (error::HAS_ERRORED) { + for (const auto &err : error::ERRORS) { + print(err.to_json()); + } + } } } diff --git a/source/lexer/source/lexer.cc b/source/lexer/source/lexer.cc index d8cf8c4..8239a6f 100644 --- a/source/lexer/source/lexer.cc +++ b/source/lexer/source/lexer.cc @@ -16,8 +16,9 @@ #include #include -#include "neo-panic/include/error.hh" #include "lexer/include/cases.def" +#include "neo-panic/include/error.hh" +#include "neo-pprint/include/hxpprint.hh" namespace parser::lexer { using namespace token; @@ -26,7 +27,7 @@ Lexer::Lexer(std::string source, const std::string &filename) : tokens(filename) , source(std::move(source)) , file_name(filename) - , currentChar('\0') + , currentChar(this->source.length() > 0 ? this->source[0] : '\0') , cachePos(0) , currentPos(0) , line(1) @@ -88,10 +89,10 @@ inline Token Lexer::process_single_line_comment() { inline Token Lexer::process_multi_line_comment() { auto start = currentPos; - u32 comment_depth = 0; + u64 comment_depth = 0; - u32 start_line = line; - u32 start_col = column; + u64 start_line = line; + u64 start_col = column; while (!is_eof()) { switch (current()) { @@ -213,13 +214,13 @@ inline Token Lexer::parse_compiler_directive() { offset, source.substr(start + 2, (currentPos - start) - 3), file_name, - ""}; + "/* complier_directive */"}; throw error::Panic(error::CodeError{.pof = &tok, .err_code = 0.7007}); } inline Token Lexer::process_whitespace() { - auto result = Token{line, column, 1, offset, source.substr(currentPos, 1), file_name, "< >"}; + auto result = Token{line, column, 1, offset, source.substr(currentPos, 1), file_name, "/* */"}; bare_advance(); return result; } @@ -260,7 +261,7 @@ inline Token Lexer::parse_alpha_numeric() { offset, source.substr(start, currentPos - start), file_name, - ""}; + "_"}; } inline Token Lexer::parse_numeric() { @@ -304,7 +305,7 @@ inline Token Lexer::parse_numeric() { offset, source.substr(start, currentPos - start), file_name, - ""}; + "/* float */"}; throw error::Panic(error::create_old_CodeError(&bad_token, 0.0003)); } @@ -314,7 +315,7 @@ inline Token Lexer::parse_numeric() { offset, source.substr(start, currentPos - start), file_name, - ""}; + "/* float */"}; } return {line, column - (currentPos - start), @@ -322,7 +323,7 @@ inline Token Lexer::parse_numeric() { offset, source.substr(start, currentPos - start), file_name, - ""}; + "/* int */"}; } inline Token Lexer::parse_string() { @@ -365,10 +366,10 @@ inline Token Lexer::parse_string() { switch (quote) { case '"': - token_type = ""; + token_type = "/* string */"; break; case '\'': - token_type = ""; + token_type = "/* char */"; break; } @@ -382,7 +383,7 @@ inline Token Lexer::parse_string() { } inline Token Lexer::parse_operator() { - auto start = currentPos; + auto start = currentPos; bool end_loop = false; while (!end_loop && !is_eof()) { @@ -407,24 +408,49 @@ inline Token Lexer::parse_operator() { inline Token Lexer::parse_punctuation() { // gets here bacause of something like . | : Token result; - switch (peek_forward()) { - case '.': // .. - bare_advance(); - if (peek_forward() == '.') { //... - result = - Token{line, column, 3, offset, source.substr(currentPos - 1, 3), file_name}; - bare_advance(2); // advance by 3 before return + switch (source[currentPos]) { + case '.': // . + // can be: .., ..., ..= + if (peek_forward() == '.') { // .. + bare_advance(); + + if (peek_forward() == '.') { // ... + bare_advance(2); + result = Token{line, column - 2, 3, offset, "...", file_name}; + + return result; + } + + if (peek_forward() == '=') { // ..= + bare_advance(2); + result = Token{line, column - 2, 3, offset, "..=", file_name}; + + return result; + } + + bare_advance(); + result = Token{line, column - 1, 2, offset, "..", file_name}; return result; } - case ':': - result = Token{line, column, 2, offset, source.substr(currentPos, 2), file_name}; - bare_advance(2); - return result; - default: - result = Token{line, column, 1, offset, source.substr(currentPos, 1), file_name}; - bare_advance(); - return result; + break; + + case ':': // : or :: + if (peek_forward() == ':') { + bare_advance(2); + result = Token{line, column, 2, offset, "::", file_name}; + + return result; + } + break; + + default: { + break; + } } + + result = Token{line, column, 1, offset, source.substr(currentPos, 1), file_name}; + bare_advance(); + return result; } inline char Lexer::advance(u16 n) { diff --git a/source/parser/ast/include/AST.hh b/source/parser/ast/include/AST.hh index 86109d9..649ece1 100644 --- a/source/parser/ast/include/AST.hh +++ b/source/parser/ast/include/AST.hh @@ -9,46 +9,22 @@ // Copyright (c) 2024 (CC BY 4.0) // // // //====----------------------------------------------------------------------------------------====// -// // -// this file exports all the AST related files // -// // -//====----------------------------------------------------------------------------------------====// -// fyi: i aim to make the AST have the PERFECT readable and maintainable code i can ever write. // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __AST_HH__ -#define __AST_HH__ - -#include "parser/ast/include/AST_core.def" -#include "parser/ast/include/AST_classifier.hh" -#include "parser/ast/include/AST_context.hh" -#include "parser/ast/include/AST_interface.hh" -#include "parser/ast/include/AST_matcher.hh" -#include "parser/ast/include/AST_types.hh" -#include "parser/ast/include/AST_visitor.hh" -#include "parser/ast/include/nodes/AST_generate.hh" - -// TODO: Make this work again - -// #undef EXPR_VA_CLASS -// #undef STMT_VA_CLASS -// #undef DECL_VA_CLASS -// #undef ANNO_VA_CLASS -// #undef TYPE_VA_CLASS -// #undef MAKE_NODE_ENUM -// #undef MAKE_NODE_CLASS -// #undef MAKE_FORWARD_DECL -// #undef MAKE_VISITOR_FUNCTION +#ifndef __AST_H__ +#define __AST_H__ -// #undef GENERATE_NODES_ENUM -// #undef GENERATE_NODES_FORWARD_DECLS -// #undef GENERATE_NODES_CLASSES +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/config/AST_generate.hh" +#include "parser/ast/include/core/AST_classifier.hh" +#include "parser/ast/include/core/AST_context.hh" +#include "parser/ast/include/core/AST_matcher.hh" +#include "parser/ast/include/core/AST_nodes.hh" +#include "parser/ast/include/nodes/AST_Declarations.hh" +#include "parser/ast/include/nodes/AST_Expressions.hh" +#include "parser/ast/include/nodes/AST_Statements.hh" +#include "parser/ast/include/types/AST_jsonify_visitor.hh" +#include "parser/ast/include/types/AST_types.hh" +#include "parser/ast/include/types/AST_visitor.hh" -// #undef GENERICS -// #undef STATEMENTS -// #undef EXPRESSION -// #undef ANNOTATIONS -// #undef DECLARATIONS -#endif // __AST_HH__ +#endif // __AST_H__ \ No newline at end of file diff --git a/source/parser/ast/include/AST_interface.hh b/source/parser/ast/include/AST_interface.hh deleted file mode 100644 index 7d69dd4..0000000 --- a/source/parser/ast/include/AST_interface.hh +++ /dev/null @@ -1,76 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// This file defines the interface to the AST classes. // -// // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __AST_INTERFACE_H__ -#define __AST_INTERFACE_H__ - -#include "parser/ast/include/AST_core.def" -#include "parser/ast/include/AST_types.hh" -#include "token/include/token_list.hh" - -#define DEFINE_SUB_NODE(name) \ - class name : public Node { \ - public: \ - name(); \ - explicit name(token::TokenList &tokens); \ - \ - name(const name &) = default; \ - name &operator=(const name &) = default; \ - name(name &&) = default; \ - name &operator=(name &&) = default; \ - ~name() override = default; \ - \ - virtual ParseResult parse() override = 0; \ - virtual bool test() override = 0; \ - virtual void accept(Visitor &visitor) const override = 0; \ - [[nodiscard]] virtual nodes getNodeType() const override = 0; \ - \ - protected: \ - token::TokenList *tokens = nullptr; \ - }; \ - \ - NodeT get_##name(token::TokenList &tokens); - -__AST_BEGIN { -class Visitor; -enum class nodes; - -class Node { - public: - Node() = default; - explicit Node(token::TokenList &tokens) {} - virtual ~Node() = default; - virtual ParseResult parse() = 0; - virtual bool test() = 0; - virtual void accept(Visitor &visitor) const = 0; - [[nodiscard]] virtual nodes getNodeType() const = 0; - - Node(const Node &) = default; - Node &operator=(const Node &) = default; - Node(Node &&) = default; - Node &operator=(Node &&) = default; -}; - -DEFINE_SUB_NODE(Type); -DEFINE_SUB_NODE(Expression); -DEFINE_SUB_NODE(Statement); -DEFINE_SUB_NODE(Annotation); -DEFINE_SUB_NODE(Declaration); -} // namespace __AST_BEGIN - -#undef DEFINE_SUB_NODE - -#endif // __AST_INTERFACE_H__ \ No newline at end of file diff --git a/source/parser/ast/include/AST_jsonify_visitor.hh b/source/parser/ast/include/AST_jsonify_visitor.hh deleted file mode 100644 index 68cc7f8..0000000 --- a/source/parser/ast/include/AST_jsonify_visitor.hh +++ /dev/null @@ -1,41 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// This file defines the JsonifyVisitor class, which is used to convert the AST to JSON. // -// The JSON representation of the AST is used for debugging and testing purposes. // -// // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __AST_JSONIFY_VISITOR_H__ -#define __AST_JSONIFY_VISITOR_H__ - -#include "neo-json/include/json.hh" -#include "parser/ast/include/AST_visitor.hh" -#include "parser/ast/include/AST_core.def" - -__AST_BEGIN::visitors { - class JsonifyVisitor : public Visitor { - public: - JsonifyVisitor() = default; - virtual ~JsonifyVisitor() = default; - JsonifyVisitor(const JsonifyVisitor&) = default; - JsonifyVisitor& operator=(const JsonifyVisitor&) = default; - JsonifyVisitor(JsonifyVisitor&&) = default; - JsonifyVisitor& operator=(JsonifyVisitor&&) = default; - - neo::json json {"ast"}; - - GENERATE_VISITOR_FUNCTIONS; - }; -} - -#endif // __AST_JSONIFY_VISITOR_H__ \ No newline at end of file diff --git a/source/parser/ast/include/AST_nodes.def b/source/parser/ast/include/AST_nodes.def deleted file mode 100644 index 28f3d3e..0000000 --- a/source/parser/ast/include/AST_nodes.def +++ /dev/null @@ -1,94 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// this file exports all the AST nodes used by the parser // -// // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __AST_NODES_HH__ -#define __AST_NODES_HH__ - -#include "parser/ast/include/AST_interface.hh" -#include "parser/ast/include/nodes/AST_annotations.def" -#include "parser/ast/include/nodes/AST_declarations.def" -#include "parser/ast/include/nodes/AST_expressions.def" -#include "parser/ast/include/nodes/AST_generics.def" -#include "parser/ast/include/nodes/AST_statements.def" - -#define EXPR_VA_CLASS __AST_N::Expression -#define STMT_VA_CLASS __AST_N::Statement -#define DECL_VA_CLASS __AST_N::Declaration -#define ANNO_VA_CLASS __AST_N::Annotation -#define TYPE_VA_CLASS __AST_N::Type - -#define MAKE_NODE_ENUM(T, D, B) T, -#define MAKE_FORWARD_DECL(T, D, B) class T; -#define MAKE_VISITOR_FUNCTION(T, D, B) void visit(const __AST_N::node::T &) override; -#define MAKE_BASE_VISITOR_FUNCTION(T, D, B) virtual void visit(const __AST_N::node::T &) = 0; -#define MAKE_NODE_CLASS(T, D, B) \ - class T final : public D { \ - protected: \ - token::TokenList *tokens; \ - \ - public: \ - explicit T(token::TokenList &tokens) \ - : tokens(&tokens) {} \ - ~T() = default; \ - T(const T &) = delete; \ - T &operator=(const T &) = delete; \ - T(T &&) = default; \ - T &operator=(T &&) = delete; \ - \ - __AST_N::ParseResult parse() override; \ - bool test() override; \ - void accept(__AST_N::Visitor &visitor) const override; \ - nodes getNodeType() const override { return nodes::T; } \ - \ - B \ - }; - -#define GENERATE_NODES_ENUM \ - enum class nodes { \ - ANNOTATIONS(MAKE_NODE_ENUM, ANNO_VA_CLASS) GENERICS(MAKE_NODE_ENUM, TYPE_VA_CLASS) \ - DECLARATIONS(MAKE_NODE_ENUM, DECL_VA_CLASS) STATEMENTS(MAKE_NODE_ENUM, STMT_VA_CLASS) \ - EXPRESSION(MAKE_NODE_ENUM, EXPR_VA_CLASS) \ - } - -#define GENERATE_NODES_FORWARD_DECLS \ - ANNOTATIONS(MAKE_FORWARD_DECL, ANNO_VA_CLASS) \ - GENERICS(MAKE_FORWARD_DECL, TYPE_VA_CLASS) \ - DECLARATIONS(MAKE_FORWARD_DECL, DECL_VA_CLASS) \ - STATEMENTS(MAKE_FORWARD_DECL, STMT_VA_CLASS) \ - EXPRESSION(MAKE_FORWARD_DECL, EXPR_VA_CLASS) - -#define GENERATE_NODES_CLASSES \ - ANNOTATIONS(MAKE_NODE_CLASS, ANNO_VA_CLASS) \ - GENERICS(MAKE_NODE_CLASS, TYPE_VA_CLASS) \ - DECLARATIONS(MAKE_NODE_CLASS, DECL_VA_CLASS) \ - STATEMENTS(MAKE_NODE_CLASS, STMT_VA_CLASS) \ - EXPRESSION(MAKE_NODE_CLASS, EXPR_VA_CLASS) - -#define GENERATE_VISITOR_FUNCTIONS \ - ANNOTATIONS(MAKE_VISITOR_FUNCTION, ANNO_VA_CLASS) \ - GENERICS(MAKE_VISITOR_FUNCTION, TYPE_VA_CLASS) \ - DECLARATIONS(MAKE_VISITOR_FUNCTION, DECL_VA_CLASS) \ - STATEMENTS(MAKE_VISITOR_FUNCTION, STMT_VA_CLASS) \ - EXPRESSION(MAKE_VISITOR_FUNCTION, EXPR_VA_CLASS) - -#define GENERATE_BASE_VISITOR_FUNCTIONS \ - ANNOTATIONS(MAKE_BASE_VISITOR_FUNCTION, ANNO_VA_CLASS) \ - GENERICS(MAKE_BASE_VISITOR_FUNCTION, TYPE_VA_CLASS) \ - DECLARATIONS(MAKE_BASE_VISITOR_FUNCTION, DECL_VA_CLASS) \ - STATEMENTS(MAKE_BASE_VISITOR_FUNCTION, STMT_VA_CLASS) \ - EXPRESSION(MAKE_BASE_VISITOR_FUNCTION, EXPR_VA_CLASS) - -#endif // __AST_NODES_HH__ diff --git a/source/parser/ast/include/AST_types.hh b/source/parser/ast/include/AST_types.hh deleted file mode 100644 index 22575be..0000000 --- a/source/parser/ast/include/AST_types.hh +++ /dev/null @@ -1,89 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// This file contains the AST types used by the parser and lexer. // -// // -// The AST types are defined as follows: // -// - ParseResult is a pair of an integer and a T // -// - NodeT is a raw pointer to a T (where T is a AST node) // -// - NodeV is a vector of NodeT // -// - NodeVP is a unique pointer to a NodeV // -// - NodeR is a reference to a T // -// - NodeCR is a const reference to a T // -// - NodeVR is a reference to a NodeV // -// - NodeVCR is a const reference to a NodeV // -// - NodeVPR is a reference to a NodeVP // -// - make_node is a helper function to create a new node with perfect forwarding // -// // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __AST_TYPES_H__ -#define __AST_TYPES_H__ - -#include -#include - -#include "neo-types/include/hxint.hh" -#include "parser/ast/include/AST_core.def" - -__AST_BEGIN { -/// ParseResult is just an integer of the tokens consumed -using ParseResult = i32; - -class Node; - -/// NodeT is a unique pointer to a T (where T is a AST node) -template -using NodeT = T*; - -/// NodeV is a vector of NodeT -template -using NodeV = std::vector>; - -/// NodeVP is a unique pointer to a NodeV -template -using NodeVP = std::unique_ptr>; - -/// NodeR is a reference to a T -template -using NodeR = T &; - -/// NodeCR is a const reference to a T -template -using NodeCR = const T &; - -/// NodeVR is a reference to a NodeV -template -using NodeVR = NodeV &; - -/// NodeVCR is a const reference to a NodeV -template -using NodeVCR = const NodeV &; - -/// NodeVPR is a reference to a NodeVP -template -using NodeVPR = NodeVP &; - -/// make_node is a helper function to create a new node with perfect forwarding -/// @tparam T is the type of the node -/// @param args are the arguments to pass to the constructor of T -/// @return a unique pointer to the new node -template -inline constexpr NodeT make_node(Args &&...args) { - // return a heap-alloc unique pointer to the new node with - // perfect forwarding of the arguments allowing the caller - // to identify any errors in the arguments at compile time - return NodeT(std::forward(args)...); -} -} // namespace __AST_BEGIN - -#endif // __AST_TYPES_H__ \ No newline at end of file diff --git a/source/parser/ast/include/AST_visitor.hh b/source/parser/ast/include/AST_visitor.hh deleted file mode 100644 index 6734b3e..0000000 --- a/source/parser/ast/include/AST_visitor.hh +++ /dev/null @@ -1,65 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// This header defines the Visitor pattern for the Abstract Syntax Tree (AST) in Helix. // -// // -// The Visitor pattern is a way to separate the operations (like traversing or modifying nodes) // -// from the AST node classes themselves. It allows you to add new operations without having to // -// modify the AST node classes—keeping the code cleaner and more maintainable. // -// // -// Here's a quick example of how you might use it: // -// // -// ```cpp // -// class MyVisitor : public parser::ast::Visitor { // -// public: // -// void Visit(const node::BinaryOp &node) override { // -// // Handle node::BinaryOp // -// } // -// // -// void Visit(const node::IfStatement &node) override { // -// // Handle node::IfStatement // -// } // -// // -// // Add more Visit functions as needed // -// }; // -// // -// // Now, you can traverse the AST with your visitor: // -// MyVisitor Visitor; // -// ASTRootNode->Accept(Visitor); // -// ``` // -// // -// In this example, `MyVisitor` implements the `Visitor` interface. Each `Visit` method is // -// specialized for a different type of AST node, making it easy to handle each node type // -// separately. // -// // -// The `GENERATE_VISITOR_FUNCTIONS` macro helps reduce boilerplate by automatically declaring // -// the visitor functions for all the AST node types. This way, you can focus on what each // -// visitor needs to do without worrying about the repetitive setup. // -// // -//====----------------------------------------------------------------------------------------====// - -#ifndef __AST_VISITOR_H__ -#define __AST_VISITOR_H__ - -#include "parser/ast/include/nodes/AST_generate.hh" -#include "parser/ast/include/AST_core.def" - -__AST_BEGIN { - -class Visitor { - public: - GENERATE_BASE_VISITOR_FUNCTIONS; -}; - -} // namespace __AST_BEGIN - -#endif // __AST_VISITOR_H__ \ No newline at end of file diff --git a/source/parser/ast/include/case_types.def b/source/parser/ast/include/case_types.def deleted file mode 100644 index 6d5c3c2..0000000 --- a/source/parser/ast/include/case_types.def +++ /dev/null @@ -1,188 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// this file is used as a helper to define the cases for token types used by the parser // -// // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __CASE_TYPES_H__ -#define __CASE_TYPES_H__ - -#define IS_LITERAL \ - token::LITERAL_STRING : case token::LITERAL_TRUE: \ - case token::LITERAL_FALSE: \ - case token::LITERAL_INTEGER: \ - case token::LITERAL_COMPLIER_DIRECTIVE: \ - case token::LITERAL_FLOATING_POINT: \ - case token::LITERAL_CHAR: \ - case token::LITERAL_NULL - -#define IS_IDENTIFIER token::IDENTIFIER - -#define IS_KEYWORD \ - token::KEYWORD_IF : case token::KEYWORD_ELSE: \ - case token::KEYWORD_UNLESS: \ - case token::KEYWORD_SPAWN: \ - case token::KEYWORD_AWAIT: \ - case token::KEYWORD_THREAD: \ - case token::KEYWORD_MACRO: \ - case token::KEYWORD_DEFINE: \ - case token::KEYWORD_FUNCTION: \ - case token::KEYWORD_OPERATOR: \ - case token::KEYWORD_INLINE: \ - case token::KEYWORD_RETURN: \ - case token::KEYWORD_ENCLOSING: \ - case token::KEYWORD_ASYNC: \ - case token::KEYWORD_FOR: \ - case token::KEYWORD_WHILE: \ - case token::KEYWORD_BREAK: \ - case token::KEYWORD_CONTINUE: \ - case token::KEYWORD_CASE: \ - case token::KEYWORD_MATCH: \ - case token::KEYWORD_SWITCH: \ - case token::KEYWORD_DEFAULT: \ - case token::KEYWORD_ENUM: \ - case token::KEYWORD_TYPE: \ - case token::KEYWORD_CLASS: \ - case token::KEYWORD_UNION: \ - case token::KEYWORD_STRUCT: \ - case token::KEYWORD_ABSTRACT: \ - case token::KEYWORD_INTERFACE: \ - case token::KEYWORD_IS: \ - case token::KEYWORD_TRY: \ - case token::KEYWORD_PANIC: \ - case token::KEYWORD_CATCH: \ - case token::KEYWORD_FINALLY: \ - case token::KEYWORD_LET: \ - case token::KEYWORD_PRIVATE: \ - case token::KEYWORD_AUTO: \ - case token::KEYWORD_CONST: \ - case token::KEYWORD_GLOBAL: \ - case token::KEYWORD_FROM: \ - case token::KEYWORD_FFI: \ - case token::KEYWORD_IMPORT: \ - case token::KEYWORD_EXTERN: \ - case token::KEYWORD_YIELD: \ - case token::KEYWORD_AS: \ - case token::KEYWORD_DERIVES: \ - case token::KEYWORD_MODULE - -#define IS_DELIMITER \ - token::DELIMITER_TAB : case token::DELIMITER_NEWLINE: \ - case token::EOF_TOKEN: \ - case token::DELIMITER_SPACE: \ - case token::WHITESPACE - -#define IS_OPERATOR \ - token::OPERATOR_ADD : case token::OPERATOR_SUB: \ - case token::OPERATOR_MUL: \ - case token::OPERATOR_DIV: \ - case token::OPERATOR_MOD: \ - case token::OPERATOR_MAT: \ - case token::OPERATOR_BITWISE_AND: \ - case token::OPERATOR_BITWISE_OR: \ - case token::OPERATOR_BITWISE_XOR: \ - case token::OPERATOR_BITWISE_NOT: \ - case token::OPERATOR_ASSIGN: \ - case token::OPERATOR_LOGICAL_NOT: \ - case token::OPERATOR_POW: \ - case token::OPERATOR_ABS: \ - case token::OPERATOR_BITWISE_L_SHIFT: \ - case token::OPERATOR_BITWISE_NAND: \ - case token::OPERATOR_BITWISE_R_SHIFT: \ - case token::OPERATOR_BITWISE_NOR: \ - case token::OPERATOR_EQUAL: \ - case token::OPERATOR_NOT_EQUAL: \ - case token::OPERATOR_GREATER_THAN_EQUALS: \ - case token::OPERATOR_INC: \ - case token::OPERATOR_DEC: \ - case token::OPERATOR_LESS_THAN_EQUALS: \ - case token::OPERATOR_ADD_ASSIGN: \ - case token::OPERATOR_SUB_ASSIGN: \ - case token::OPERATOR_MUL_ASSIGN: \ - case token::OPERATOR_BITWISE_AND_ASSIGN: \ - case token::OPERATOR_BITWISE_OR_ASSIGN: \ - case token::OPERATOR_BITWISE_NOR_ASSIGN: \ - case token::OPERATOR_BITWISE_XOR_ASSIGN: \ - case token::OPERATOR_BITWISE_NOT_ASSIGN: \ - case token::OPERATOR_DIV_ASSIGN: \ - case token::OPERATOR_MOD_ASSIGN: \ - case token::OPERATOR_MAT_ASSIGN: \ - case token::OPERATOR_LOGICAL_AND: \ - case token::OPERATOR_LOGICAL_NAND: \ - case token::OPERATOR_LOGICAL_OR: \ - case token::OPERATOR_LOGICAL_NOR: \ - case token::OPERATOR_LOGICAL_XOR: \ - case token::OPERATOR_RANGE: \ - case token::OPERATOR_ARROW: \ - case token::OPERATOR_NOT_ASSIGN: \ - case token::OPERATOR_SCOPE: \ - case token::OPERATOR_REF_EQUAL: \ - case token::OPERATOR_POWER_ASSIGN: \ - case token::OPERATOR_AND_ASSIGN: \ - case token::OPERATOR_NAND_ASSIGN: \ - case token::OPERATOR_OR_ASSIGN: \ - case token::OPERATOR_NOR_ASSIGN: \ - case token::OPERATOR_XOR_ASSIGN: \ - case token::OPERATOR_BITWISE_NAND_ASSIGN: \ - case token::OPERATOR_BITWISE_L_SHIFT_ASSIGN: \ - case token::OPERATOR_BITWISE_R_SHIFT_ASSIGN: \ - case token::OTHERS: \ - case token::PUNCTUATION_OPEN_ANGLE: \ - case token::PUNCTUATION_CLOSE_ANGLE: \ - case token::OPERATOR_RANGE_INCLUSIVE - -#define IS_PUNCTUATION \ - token::PUNCTUATION_OPEN_PAREN : case token::PUNCTUATION_CLOSE_PAREN: \ - case token::PUNCTUATION_OPEN_BRACE: \ - case token::PUNCTUATION_CLOSE_BRACE: \ - case token::PUNCTUATION_OPEN_BRACKET: \ - case token::PUNCTUATION_CLOSE_BRACKET: \ - case token::PUNCTUATION_OPEN_ANGLE: \ - case token::PUNCTUATION_CLOSE_ANGLE: \ - case token::PUNCTUATION_COMMA: \ - case token::PUNCTUATION_SEMICOLON: \ - case token::PUNCTUATION_COLON: \ - case token::PUNCTUATION_QUESTION_MARK: \ - case token::PUNCTUATION_DOT: \ - case token::PUNCTUATION_SINGLE_LINE_COMMENT: \ - case token::PUNCTUATION_MULTI_LINE_COMMENT: \ - case token::PUNCTUATION_ELLIPSIS - -#define IS_PRIMITIVE \ - token::PRIMITIVE_VOID : case token::PRIMITIVE_BOOL: \ - case token::PRIMITIVE_BYTE: \ - case token::PRIMITIVE_CHAR: \ - case token::PRIMITIVE_POINTER: \ - case token::PRIMITIVE_I8: \ - case token::PRIMITIVE_U8: \ - case token::PRIMITIVE_I16: \ - case token::PRIMITIVE_U16: \ - case token::PRIMITIVE_I32: \ - case token::PRIMITIVE_U32: \ - case token::PRIMITIVE_F32: \ - case token::PRIMITIVE_I64: \ - case token::PRIMITIVE_U64: \ - case token::PRIMITIVE_F64: \ - case token::PRIMITIVE_FLOAT: \ - case token::PRIMITIVE_I128: \ - case token::PRIMITIVE_U128: \ - case token::PRIMITIVE_INT: \ - case token::PRIMITIVE_DECIMAL: \ - case token::PRIMITIVE_STRING: \ - case token::PRIMITIVE_LIST: \ - case token::PRIMITIVE_TUPLE: \ - case token::PRIMITIVE_SET: \ - case token::PRIMITIVE_MAP: \ - case token::PRIMITIVE_ANY - -#endif // __CASE_TYPES_H__ \ No newline at end of file diff --git a/source/parser/ast/include/AST_core.def b/source/parser/ast/include/config/AST_Annotations.def similarity index 77% rename from source/parser/ast/include/AST_core.def rename to source/parser/ast/include/config/AST_Annotations.def index 4fcbad4..85ce459 100644 --- a/source/parser/ast/include/AST_core.def +++ b/source/parser/ast/include/config/AST_Annotations.def @@ -10,13 +10,11 @@ // // //====----------------------------------------------------------------------------------------====// -#ifndef __AST_CORE_DEF__ -#define __AST_CORE_DEF__ +#ifndef __AST_ANNOTATIONS_DEF__ +#define __AST_ANNOTATIONS_DEF__ -#define PARSE_SIG(Tx) ParseResult Tx::parse() -#define TEST_SIG(Tx) bool Tx::test() -#define VISITOR_IMPL(Tx) void Tx::accept(Visitor &visitor) const { visitor.visit(*this); } -#define __AST_BEGIN namespace parser::ast -#define __AST_N parser::ast +#define ANNOT(MACRO) \ + MACRO(CompilerDirective) \ + MACRO(Comment) -#endif // __AST_CORE_DEF__ \ No newline at end of file +#endif // __AST_ANNOTATIONS_DEF__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/AST_declarations.def b/source/parser/ast/include/config/AST_Declarations.def similarity index 62% rename from source/parser/ast/include/nodes/AST_declarations.def rename to source/parser/ast/include/config/AST_Declarations.def index 9f19303..6773413 100644 --- a/source/parser/ast/include/nodes/AST_declarations.def +++ b/source/parser/ast/include/config/AST_Declarations.def @@ -9,21 +9,29 @@ // Copyright (c) 2024 (CC BY 4.0) // // // //====----------------------------------------------------------------------------------------====// -// // -// // -//===-----------------------------------------------------------------------------------------====// #ifndef __AST_DECLARATIONS_DEF__ #define __AST_DECLARATIONS_DEF__ -#define DECLARATIONS(GENERATE, DERIVE) \ - GENERATE(VariableDecl, DERIVE, \ - AccessSpecifier access; \ - NodeT assignment; \ - bool is_unsafe = false; \ - bool is_const = false; \ - bool is_eval = false; \ - ) \ - \ +#define DECLS(MACRO) \ + MACRO(RequiresParamDecl) \ + MACRO(RequiresParamList) \ + MACRO(EnumMemberDecl) \ + MACRO(UDTDeriveDecl) \ + MACRO(TypeBoundList) \ + MACRO(TypeBoundDecl) \ + MACRO(RequiresDecl) \ + MACRO(ModuleDecl) \ + MACRO(StructDecl) \ + MACRO(ConstDecl) \ + MACRO(ClassDecl) \ + MACRO(InterDecl) \ + MACRO(EnumDecl) \ + MACRO(TypeDecl) \ + MACRO(FuncDecl) \ + MACRO(VarDecl) \ + MACRO(FFIDecl) \ + MACRO(LetDecl) \ + MACRO(OpDecl) -#endif // __AST_DECLARATIONS_DEF__ \ No newline at end of file +#endif // __AST_DECLARATIONS_DEF__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/AST_generate.hh b/source/parser/ast/include/config/AST_Expressions.def similarity index 51% rename from source/parser/ast/include/nodes/AST_generate.hh rename to source/parser/ast/include/config/AST_Expressions.def index fd99ee7..e4fb703 100644 --- a/source/parser/ast/include/nodes/AST_generate.hh +++ b/source/parser/ast/include/config/AST_Expressions.def @@ -9,25 +9,37 @@ // Copyright (c) 2024 (CC BY 4.0) // // // //====----------------------------------------------------------------------------------------====// -// // -// Generates the AST nodes for the Helix Parser. // -// This file is used to generate the AST nodes for the Helix Parser. // -// // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __AST_GENERATE_H__ -#define __AST_GENERATE_H__ - -#include "parser/ast/include/AST_nodes.def" -#include "parser/ast/include/AST_core.def" -__AST_BEGIN { -GENERATE_NODES_ENUM; +#ifndef __AST_EXPRESSIONS_DEF__ +#define __AST_EXPRESSIONS_DEF__ -namespace node { - GENERATE_NODES_FORWARD_DECLS; - GENERATE_NODES_CLASSES; // NOLINT(cppcoreguidelines-pro-type-member-init) -} // namespace node -} // namespace __AST_BEGIN +#define EXPRS(MACRO) \ + MACRO(LiteralExpr) \ + MACRO(BinaryExpr) \ + MACRO(UnaryExpr) \ + MACRO(IdentExpr) \ + MACRO(NamedArgumentExpr) \ + MACRO(ArgumentExpr) \ + MACRO(ArgumentListExpr) \ + MACRO(GenericInvokeExpr) \ + MACRO(GenericInvokePathExpr) \ + MACRO(ScopePathExpr) \ + MACRO(DotPathExpr) \ + MACRO(ArrayAccessExpr) \ + MACRO(PathExpr) \ + MACRO(FunctionCallExpr) \ + MACRO(ArrayLiteralExpr) \ + MACRO(TupleLiteralExpr) \ + MACRO(SetLiteralExpr) \ + MACRO(MapPairExpr) \ + MACRO(MapLiteralExpr) \ + MACRO(ObjInitExpr) \ + MACRO(LambdaExpr) \ + MACRO(TernaryExpr) \ + MACRO(ParenthesizedExpr) \ + MACRO(CastExpr) \ + MACRO(InstOfExpr) \ + MACRO(AsyncThreading) \ + MACRO(Type) -#endif // __AST_GENERATE_H__ \ No newline at end of file +#endif // __AST_EXPRESSIONS_DEF__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/AST_annotations.def b/source/parser/ast/include/config/AST_Statements.def similarity index 52% rename from source/parser/ast/include/nodes/AST_annotations.def rename to source/parser/ast/include/config/AST_Statements.def index e3272ff..77c5e31 100644 --- a/source/parser/ast/include/nodes/AST_annotations.def +++ b/source/parser/ast/include/config/AST_Statements.def @@ -9,21 +9,36 @@ // Copyright (c) 2024 (CC BY 4.0) // // // //====----------------------------------------------------------------------------------------====// -// // -// // -//===-----------------------------------------------------------------------------------------====// -#ifndef __AST_ANNOTATIONS_DEF__ -#define __AST_ANNOTATIONS_DEF__ +#ifndef __AST_STATEMENTS_DEF__ +#define __AST_STATEMENTS_DEF__ -#define ANNOTATIONS(GENERATE, DERIVE) \ - GENERATE(Comment, DERIVE, \ - token::Token comment; \ - ) \ - \ - GENERATE(CompilerDirective, DERIVE, \ - token::Token directive; \ - NodeT<> arguments; \ - ) +#define STATES(MACRO) \ + MACRO(NamedVarSpecifier) \ + MACRO(NamedVarSpecifierList) \ + MACRO(ForPyStatementCore) \ + MACRO(ForCStatementCore) \ + MACRO(ForState) \ + MACRO(WhileState) \ + MACRO(ElseState) \ + MACRO(IfState) \ + MACRO(SwitchCaseState) \ + MACRO(SwitchState) \ + MACRO(YieldState) \ + MACRO(DeleteState) \ + MACRO(AliasState) \ + MACRO(SingleImportState) \ + MACRO(MultiImportState) \ + MACRO(ImportState) \ + MACRO(ReturnState) \ + MACRO(BreakState) \ + MACRO(BlockState) \ + MACRO(SuiteState) \ + MACRO(ContinueState) \ + MACRO(CatchState) \ + MACRO(FinallyState) \ + MACRO(TryState) \ + MACRO(PanicState) \ + MACRO(ExprState) -#endif // __AST_ANNOTATIONS_DEF__ \ No newline at end of file +#endif // __AST_STATEMENTS_DEF__ \ No newline at end of file diff --git a/source/parser/ast/include/config/AST_config.def b/source/parser/ast/include/config/AST_config.def new file mode 100644 index 0000000..cc6a41b --- /dev/null +++ b/source/parser/ast/include/config/AST_config.def @@ -0,0 +1,161 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // +// You are allowed to use, modify, redistribute, and create derivative works, even for // +// commercial purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// + +#ifndef __AST_CONFIG_DEF__ +#define __AST_CONFIG_DEF__ + +#define PARSE_SIG(Tx) ParseResult Tx::parse() +#define TEST_SIG(Tx) bool Tx::test() +#define VISITOR_IMPL(Tx) \ + void Tx::accept(Visitor &visitor) const { visitor.visit(*this); } +#define __AST_BEGIN namespace parser::ast +#define __AST_NODE_BEGIN namespace parser::ast::node +#define __AST_VISITOR_BEGIN namespace parser::ast::visitor +#define __AST_N parser::ast +#define __AST_NODE parser::ast::node +#define __AST_VISITOR parser::ast::visitor + +#define AST_NODE_IMPL(base, name, ...) \ + __AST_N::ParseResult<__AST_NODE::name> __AST_NODE::base::parse_##name(__VA_ARGS__) + +#define AST_BASE_IMPL(name, fn) __AST_N::ParseResult<> __AST_NODE::name::fn() + +#define AST_NODE_IMPL_VISITOR(visitor, name) \ + void __AST_VISITOR::visitor::visit(const __AST_NODE::name &node) + +#define BASE_CORE_METHODS(name) \ + public: \ + name() = delete; \ + ~name() override = default; \ + name(const name &) = default; \ + name &operator=(const name &) = default; \ + name(name &&) = default; \ + name &operator=(name &&) = default; \ + void accept(__AST_VISITOR::Visitor &visitor) const override { visitor.visit(*this); } \ + [[nodiscard]] nodes getNodeType() const override { return nodes::name; } \ + [[nodiscard]] std::string getNodeName() const override { return #name; } + +#define IS_PEEK(x) iter.peek().has_value() && iter.peek().value().get().token_kind() == (x) +#define RETURN_IF_ERROR(x) \ + if (!x.has_value()) { \ + return std::unexpected(x.error()); \ + } +#define IS_NOT_EMPTY \ + if (iter.remaining_n() == 0) { \ + return std::unexpected(PARSE_ERROR_MSG("expected a expression, but found nothing")); \ + } +#define NOT_IMPLEMENTED return std::unexpected(PARSE_ERROR_MSG("not implemented yet")); +#define EXPECT_TOK(x) \ + if (iter->token_kind() != (x)) { \ + return std::unexpected(PARSE_ERROR(iter.current().get(), \ + "expected a " #x " token, but found: " + \ + iter.current().get().token_kind_repr())); \ + } + +#define CURRENT_TOK iter.current().get() +#define PREVIOUS_TOK iter.peek_back().value().get() +#define NEXT_TOK iter.peek().value().get() +#define HAS_NEXT_TOK iter.peek().has_value() + +#ifdef DEBUG +#include "neo-pprint/include/ansi_colors.hh" +#define GET_DEBUG_INFO \ + std::string(colors::fg16::green) + std::string(__FILE__) + ":" + std::to_string(__LINE__) + \ + colors::reset + std::string(" - ") +#else +#define GET_DEBUG_INFO std::string("") +#endif + +#define PARSE_ERROR(tok, msg) ParseError(tok, GET_DEBUG_INFO + msg) +#define PARSE_ERROR_MSG(msg) ParseError(CURRENT_TOK, GET_DEBUG_INFO + msg) +#define IS_EXCEPTED_TOKEN(tok) \ + if (iter.remaining_n() == 0) { \ + return std::unexpected( \ + ParseError(PREVIOUS_TOK, \ + GET_DEBUG_INFO + "expected a " + \ + std::string(token::tokens_map.at(tok).value_or("unknown")) + \ + " token, but found nothing")); \ + } \ + if (CURRENT_TOK != tok) { \ + iter.advance(); \ + return std::unexpected(PARSE_ERROR( \ + PREVIOUS_TOK, \ + "expected a " + std::string(token::tokens_map.at(tok).value_or("unknown")) + \ + " token, but found: " + PREVIOUS_TOK.token_kind_repr())); \ + } + +#define IS_NOT_EXCEPTED_TOKEN(tok) \ + if (iter.remaining_n() == 0) { \ + return std::unexpected( \ + ParseError(PREVIOUS_TOK, GET_DEBUG_INFO + "did not expect this token here.")); \ + } \ + if (CURRENT_TOK == tok) { \ + iter.advance(); \ + return std::unexpected(PARSE_ERROR(PREVIOUS_TOK, "did not expect this token here.")); \ + } + +#define IS_IN_EXCEPTED_TOKENS(toks) \ + if (iter.remaining_n() == 0) { \ + auto tokens = toks; \ + std::string tokens_str; \ + for (auto &t : tokens) { \ + tokens_str += std::string(token::tokens_map.at(t).value_or("unknown")) + ", "; \ + } \ + return std::unexpected(PARSE_ERROR(PREVIOUS_TOK, \ + "expected one of the following tokens: " + tokens_str + \ + "but found nothing")); \ + } \ + if (!is_excepted(CURRENT_TOK, toks)) { \ + auto tokens = toks; \ + std::string tokens_str; \ + for (auto &t : tokens) { \ + tokens_str += std::string(token::tokens_map.at(t).value_or("unknown")) + ", "; \ + } \ + iter.advance(); \ + return std::unexpected( \ + PARSE_ERROR(PREVIOUS_TOK, \ + "expected one of the following tokens: " + tokens_str + \ + "but found: " + std::string(PREVIOUS_TOK.token_kind_repr()))); \ + } + +/* TODO: change the ';' add from prev tok to ++; */ + +#define CURRENT_TOKEN_IS(x) (iter.remaining_n() != 0 && CURRENT_TOK == x) +#define CURRENT_TOKEN_IS_NOT(x) (iter.remaining_n() != 0 && CURRENT_TOK != x) +#define IS_NULL_RESULT(x) if (x == nullptr || !x.has_value()) +#define IS_NOT_NULL_RESULT(x) if (x != nullptr && x.has_value()) + +#define AST_CLASS_BASE(name, MACRO) \ + template \ + using p_r = parser::ast::ParseResult; \ + \ + token::TokenList::TokenListIter &iter; /* NOLINT */ \ + std::vector> parse_stack; \ + \ + public: \ + name() = delete; \ + name(const name &) = default; \ + name &operator=(const name &) = delete; \ + name(name &&) = default; \ + name &operator=(name &&) = delete; \ + ~name() = default; \ + p_r<> parse(); \ + \ + explicit name(token::TokenList::TokenListIter &iter) \ + : iter(iter) + +// template +// p_r parse(Args &&...args) { /* NOLINT */ +// MACRO(GENERATE_IF_STATEMENTS); +// } + +#endif // __AST_CONFIG_DEF__ \ No newline at end of file diff --git a/source/parser/ast/source/annotations/AST_Comment.cc b/source/parser/ast/include/config/AST_generate.def similarity index 58% rename from source/parser/ast/source/annotations/AST_Comment.cc rename to source/parser/ast/include/config/AST_generate.def index 3e874cb..f93e2e2 100644 --- a/source/parser/ast/source/annotations/AST_Comment.cc +++ b/source/parser/ast/include/config/AST_generate.def @@ -10,24 +10,21 @@ // // //====----------------------------------------------------------------------------------------====// -#include "parser/ast/include/AST.hh" +#ifndef __AST_GENERATE_DEF__ +#define __AST_GENERATE_DEF__ -namespace parser::ast::node { -ParseResult Comment::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } +#define FORWARD_DECL(name) class name; +#define DECL_PARSE_FUNC(name) ParseResult parse_##name(); +#define NODE_ENUM(name) name, +#define VISIT_FUNC(name) virtual void visit(const __AST_NODE::name &) = 0; +#define VISIT_EXTEND(name) void visit(const __AST_NODE::name &node) override; - return 0; -} +#define GENERATE_MACRO_HELPER(MACRO) EXPRS(MACRO) STATES(MACRO) DECLS(MACRO) -bool Comment::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} +#define GENERATE_NODES_ENUM enum class nodes { GENERATE_MACRO_HELPER(NODE_ENUM) }; +#define GENERATE_NODES_FORWARD_DECLS GENERATE_MACRO_HELPER(FORWARD_DECL) +#define GENERATE_PARSE_FUNCS DECLS(DECL_PARSE_FUNC) +#define GENERATE_VISIT_FUNCS GENERATE_MACRO_HELPER(VISIT_FUNC) +#define GENERATE_VISIT_EXTENDS GENERATE_MACRO_HELPER(VISIT_EXTEND) -void Comment::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node +#endif // __AST_GENERATE_DEF__ \ No newline at end of file diff --git a/source/parser/ast/source/expressions/AST_BinaryOp.cc b/source/parser/ast/include/config/AST_generate.hh similarity index 68% rename from source/parser/ast/source/expressions/AST_BinaryOp.cc rename to source/parser/ast/include/config/AST_generate.hh index 9a1008e..0eb843a 100644 --- a/source/parser/ast/source/expressions/AST_BinaryOp.cc +++ b/source/parser/ast/include/config/AST_generate.hh @@ -10,24 +10,21 @@ // // //====----------------------------------------------------------------------------------------====// -#include "parser/ast/include/AST.hh" +#ifndef __AST_GENERATE_H__ +#define __AST_GENERATE_H__ -namespace parser::ast::node { -ParseResult BinaryOp::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/config/AST_generate.def" +#include "parser/ast/include/config/AST_Annotations.def" +#include "parser/ast/include/config/AST_Declarations.def" +#include "parser/ast/include/config/AST_Expressions.def" +#include "parser/ast/include/config/AST_Statements.def" - return 0; -} +__AST_NODE_BEGIN { + class Node; -bool BinaryOp::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; + GENERATE_NODES_ENUM; + GENERATE_NODES_FORWARD_DECLS; } -void BinaryOp::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node +#endif // __AST_GENERATE_H__ \ No newline at end of file diff --git a/source/parser/ast/include/config/AST_modifiers.hh b/source/parser/ast/include/config/AST_modifiers.hh new file mode 100644 index 0000000..ac52d4d --- /dev/null +++ b/source/parser/ast/include/config/AST_modifiers.hh @@ -0,0 +1,598 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // +// You are allowed to use, modify, redistribute, and create derivative works, even for // +// commercial purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// +// // +// @author @ze71111 // +// // +//===-----------------------------------------------------------------------------------------====// + +#ifndef __MODIFIERS_H__ +#define __MODIFIERS_H__ + +#include +#include +#include +#include + +#include "neo-json/include/json.hh" +#include "parser/ast/include/config/AST_config.def" +#include "token/include/token.hh" +#include "token/include/token_list.hh" + +// Specifier - the part before the signature +// Qualifier - the part after the signature + +bool is_excepted(const token::Token &tok, const std::unordered_set &tokens); + +__AST_BEGIN { + struct StorageSpecifier { + enum class Specifier : char { + Ffi, ///< 'ffi' + Static, ///< 'static' + }; + + static bool is_storage_specifier(const token::Token &tok) { + return tok == token::KEYWORD_FFI || tok == token::KEYWORD_STATIC; + } + + explicit StorageSpecifier(token::Token marker) + : marker(std::move(marker)) { + switch (marker.token_kind()) { + case token::KEYWORD_FFI: + type = Specifier::Ffi; + break; + case token::KEYWORD_STATIC: + type = Specifier::Static; + break; + default: + throw std::runtime_error("Invalid storage specifier"); + break; + } + } + + TO_NEO_JSON_IMPL { + neo::json json("StorageSpecifier"); + + json.add("type", (int)type).add("marker", marker); + + return json; + } + + token::Token marker; + Specifier type; + }; + + struct FFIQualifier { // excepted after the ffi keyword + enum class Qualifier : char { + Class, ///< 'class' + Interface, ///< 'interface' + Struct, ///< 'struct' + Enum, ///< 'enum' + Union, ///< 'union' + Type, ///< 'type' + }; + + static bool is_ffi_specifier(const token::Token &tok) { + return tok == token::KEYWORD_CLASS || tok == token::KEYWORD_INTERFACE || + tok == token::KEYWORD_STRUCT || tok == token::KEYWORD_ENUM || + tok == token::KEYWORD_UNION || tok == token::KEYWORD_TYPE; + } + + explicit FFIQualifier(token::Token marker) + : marker(std::move(marker)) { + switch (marker.token_kind()) { + case token::KEYWORD_CLASS: + type = Qualifier::Class; + break; + case token::KEYWORD_INTERFACE: + type = Qualifier::Interface; + break; + case token::KEYWORD_STRUCT: + type = Qualifier::Struct; + break; + case token::KEYWORD_ENUM: + type = Qualifier::Enum; + break; + case token::KEYWORD_UNION: + type = Qualifier::Union; + break; + case token::KEYWORD_TYPE: + type = Qualifier::Type; + break; + default: + throw std::runtime_error("Invalid ffi specifier"); + break; + } + } + + TO_NEO_JSON_IMPL { + neo::json json("FFIQualifier"); + + json.add("type", (int)type).add("marker", marker); + + return json; + } + + token::Token marker; + Qualifier type; + }; + + struct TypeSpecifier { + enum class Specifier : char { + Const, ///< 'const' + Yield, ///< 'yield' + Async, ///< 'async' + Module, ///< 'module' + Ffi, ///< 'ffi' + }; + + static bool is_type_qualifier(const token::Token &tok) { + return tok == token::KEYWORD_CONST || tok == token::KEYWORD_MODULE || + tok == token::KEYWORD_YIELD || tok == token::KEYWORD_ASYNC || + tok == token::KEYWORD_FFI; + } + + explicit TypeSpecifier(token::Token marker) + : marker(std::move(marker)) { + switch (marker.token_kind()) { + case token::KEYWORD_CONST: + type = Specifier::Const; + break; + case token::KEYWORD_MODULE: + type = Specifier::Module; + break; + case token::KEYWORD_YIELD: + type = Specifier::Yield; + break; + case token::KEYWORD_ASYNC: + type = Specifier::Async; + break; + case token::KEYWORD_FFI: + type = Specifier::Ffi; + break; + default: + throw std::runtime_error("Invalid type specifier"); + break; + } + } + + TO_NEO_JSON_IMPL { + neo::json json("TypeSpecifier"); + + json.add("type", (int)type).add("marker", marker); + + return json; + } + + token::Token marker; + Specifier type; + }; + + struct AccessSpecifier { + enum class Specifier : char { + Public, ///< 'pub' - default = exposed by linkage and visibility + Private, ///< 'priv' = not exposed by linkage and visibility + Protected, ///< 'prot' = not exposed by linkage but by visibility + Internal ///< 'intl' = exposed by linkage but not visibility + }; + + static bool is_access_specifier(const token::Token &tok) { + return tok == token::KEYWORD_PUBLIC || tok == token::KEYWORD_PRIVATE || + tok == token::KEYWORD_PROTECTED || tok == token::KEYWORD_INTERNAL; + } + + explicit AccessSpecifier(token::Token marker) + : marker(std::move(marker)) { + switch (marker.token_kind()) { + case token::KEYWORD_PUBLIC: + type = Specifier::Public; + break; + case token::KEYWORD_PRIVATE: + type = Specifier::Private; + break; + case token::KEYWORD_PROTECTED: + type = Specifier::Protected; + break; + case token::KEYWORD_INTERNAL: + type = Specifier::Internal; + break; + default: + throw std::runtime_error("Invalid access specifier"); + break; + } + } + + TO_NEO_JSON_IMPL { + neo::json json("AccessSpecifier"); + + json.add("type", (int)type).add("marker", marker); + + return json; + } + + token::Token marker; + Specifier type; + }; + + struct FunctionSpecifier { // the part before the function signature + enum class Specifier : char { + Inline, ///< 'inline' + Async, ///< 'async' + Static, ///< 'static' + Const, ///< 'const' - in functions this is 'const' but for classes its 'final' + Eval, ///< 'eval' - eval in the case of functions default to 'constinit' for + /// 'constexpr' or 'consteval' use 'const eval' + }; + + static bool is_function_specifier(const token::Token &tok) { + return tok == token::KEYWORD_INLINE || tok == token::KEYWORD_ASYNC || + tok == token::KEYWORD_STATIC || tok == token::KEYWORD_CONST || + tok == token::KEYWORD_EVAL; + } + + explicit FunctionSpecifier(token::Token marker) + : marker(std::move(marker)) { + switch (marker.token_kind()) { + case token::KEYWORD_INLINE: + type = Specifier::Inline; + break; + case token::KEYWORD_ASYNC: + type = Specifier::Async; + break; + case token::KEYWORD_STATIC: + type = Specifier::Static; + break; + case token::KEYWORD_CONST: + type = Specifier::Const; + break; + case token::KEYWORD_EVAL: + type = Specifier::Eval; + break; + default: + throw std::runtime_error("Invalid function specifier"); + break; + } + } + + TO_NEO_JSON_IMPL { + neo::json json("FunctionSpecifier"); + + json.add("type", (int)type).add("marker", marker); + + return json; + } + + token::Token marker; + Specifier type; + }; + + struct FunctionQualifier { + enum class Qualifier : char { // the part after the function signature + Default, ///< 'default' + Panic, ///< 'panic' + Delete, ///< 'delete' + Const, ///< 'const' + }; + + static bool is_function_qualifier(const token::Token &tok) { + return tok == token::KEYWORD_DEFAULT || tok == token::KEYWORD_PANIC || + tok == token::KEYWORD_DELETE || tok == token::KEYWORD_CONST; + } + + explicit FunctionQualifier(token::Token marker) + : marker(std::move(marker)) { + switch (marker.token_kind()) { + case token::KEYWORD_DEFAULT: + type = Qualifier::Default; + break; + case token::KEYWORD_PANIC: + type = Qualifier::Panic; + break; + case token::KEYWORD_DELETE: + type = Qualifier::Delete; + break; + case token::KEYWORD_CONST: + type = Qualifier::Const; + break; + default: + throw std::runtime_error("Invalid function qualifier"); + break; + } + } + + TO_NEO_JSON_IMPL { + neo::json json("FunctionQualifier"); + + json.add("type", (int)type).add("marker", marker); + + return json; + } + + token::Token marker; + Qualifier type; + }; + + struct ClassSpecifier { + enum class Specifier : char { + Static, ///< 'static' + Const, ///< 'const' - in functions this is 'const' but for classes its 'final' + }; + + static bool is_class_specifier(const token::Token &tok) { + return tok == token::KEYWORD_CONST || tok == token::KEYWORD_STATIC; + } + + explicit ClassSpecifier(token::Token marker) + : marker(std::move(marker)) { + switch (marker.token_kind()) { + case token::KEYWORD_CONST: + type = Specifier::Const; + break; + case token::KEYWORD_STATIC: + type = Specifier::Static; + break; + default: + throw std::runtime_error("Invalid class specifier"); + break; + } + } + + TO_NEO_JSON_IMPL { + neo::json json("ClassSpecifier"); + + json.add("type", (int)type).add("marker", marker); + + return json; + } + + token::Token marker; + Specifier type; + }; + + struct Modifiers { + public: + enum class ExpectedModifier : char { + StorageSpec, ///< 'ffi' | 'static' + FfiSpec, ///< 'class' | 'interface' | 'struct' | 'enum' | 'union' | 'type' + TypeSpec, ///< 'const' | 'module' | 'yield' | 'async' | 'ffi' + AccessSpec, ///< 'pub' | 'priv' | 'prot' | 'intl' + FuncSpec, ///< 'inline' | 'async' | 'static' | 'const' | 'eval' + FuncQual, ///< 'default' | 'panic' | 'delete' | 'const' + ClassSpec, ///< 'const' | 'static' + }; + + private: + std::vector expected_modifiers; + std::unordered_set allowed_modifiers; + std::unordered_map> modifiers_map = { + {ExpectedModifier::StorageSpec, {token::KEYWORD_FFI, token::KEYWORD_STATIC}}, + {ExpectedModifier::FfiSpec, + {token::KEYWORD_CLASS, + token::KEYWORD_INTERFACE, + token::KEYWORD_STRUCT, + token::KEYWORD_ENUM, + token::KEYWORD_UNION, + token::KEYWORD_TYPE}}, + {ExpectedModifier::TypeSpec, + {token::KEYWORD_CONST, + token::KEYWORD_MODULE, + token::KEYWORD_YIELD, + token::KEYWORD_ASYNC, + token::KEYWORD_FFI}}, + {ExpectedModifier::AccessSpec, + {token::KEYWORD_PUBLIC, + token::KEYWORD_PRIVATE, + token::KEYWORD_PROTECTED, + token::KEYWORD_INTERNAL}}, + {ExpectedModifier::FuncSpec, + {token::KEYWORD_INLINE, + token::KEYWORD_ASYNC, + token::KEYWORD_STATIC, + token::KEYWORD_CONST, + token::KEYWORD_EVAL}}, + {ExpectedModifier::FuncQual, + {token::KEYWORD_DEFAULT, + token::KEYWORD_PANIC, + token::KEYWORD_DELETE, + token::KEYWORD_CONST}}, + {ExpectedModifier::ClassSpec, {token::KEYWORD_CONST, token::KEYWORD_STATIC}}}; + + std::vector> + modifiers; + + public: + template + explicit Modifiers(Args &&...args) + : expected_modifiers{std::forward(args)...} { + for (const auto &modifier : expected_modifiers) { + const auto &tokens = modifiers_map[modifier]; + allowed_modifiers.insert(tokens.begin(), tokens.end()); + } + } + + // so if we set the modifiers to another Modifiers object + // we can copy the expected_modifiers and allowed_modifiers and verify if the other + // object has the modifiers we are looking for + + static bool is_modifier(const token::Token &tok, ExpectedModifier modifier) { + switch (modifier) { + case ExpectedModifier::StorageSpec: + return StorageSpecifier::is_storage_specifier(tok); + case ExpectedModifier::FfiSpec: + return FFIQualifier::is_ffi_specifier(tok); + case ExpectedModifier::TypeSpec: + return TypeSpecifier::is_type_qualifier(tok); + case ExpectedModifier::AccessSpec: + return AccessSpecifier::is_access_specifier(tok); + case ExpectedModifier::FuncSpec: + return FunctionSpecifier::is_function_specifier(tok); + case ExpectedModifier::FuncQual: + return FunctionQualifier::is_function_qualifier(tok); + case ExpectedModifier::ClassSpec: + return ClassSpecifier::is_class_specifier(tok); + default: + return false; + } + } + static bool is_modifier(const token::Token &tok) { + return StorageSpecifier::is_storage_specifier(tok) || + AccessSpecifier::is_access_specifier(tok) || + FunctionSpecifier::is_function_specifier(tok) || + ClassSpecifier::is_class_specifier(tok); + } + + [[nodiscard]] bool find_add(const token::Token ¤t_token) { + + if (allowed_modifiers.find(current_token.token_kind()) == allowed_modifiers.end()) { + return false; // not a modifier + } + + for (const auto &modifier_type : expected_modifiers) { + if (is_modifier(current_token, modifier_type)) { + switch (modifier_type) { + case ExpectedModifier::StorageSpec: + modifiers.emplace_back(StorageSpecifier(current_token)); + break; + case ExpectedModifier::FfiSpec: + modifiers.emplace_back(FFIQualifier(current_token)); + break; + case ExpectedModifier::TypeSpec: + modifiers.emplace_back(TypeSpecifier(current_token)); + break; + case ExpectedModifier::AccessSpec: + modifiers.emplace_back(AccessSpecifier(current_token)); + break; + case ExpectedModifier::FuncSpec: + modifiers.emplace_back(FunctionSpecifier(current_token)); + break; + case ExpectedModifier::FuncQual: + modifiers.emplace_back(FunctionQualifier(current_token)); + break; + case ExpectedModifier::ClassSpec: + modifiers.emplace_back(ClassSpecifier(current_token)); + break; + default: + return false; + } + + return true; + } + } + + return false; + } + + template + [[nodiscard]] std::vector get() { + std::vector result; + + for (const auto &modifier : modifiers) { + if (std::holds_alternative(modifier)) { + result.push_back(std::get(modifier)); + } + } + + return result; + } + + [[nodiscard]] bool empty() const { return modifiers.empty(); } + + void clear() { modifiers.clear(); } + + explicit operator bool() const { return !empty(); } + + [[nodiscard]] size_t size() const { return modifiers.size(); } + + template + [[nodiscard]] T first() { + if (modifiers.empty()) { + throw std::runtime_error("No modifiers found"); + } + + return std::get(modifiers.front()); + } + + template + [[nodiscard]] T last() { + if (modifiers.empty()) { + throw std::runtime_error("No modifiers found"); + } + + return std::get(modifiers.back()); + } + + template + [[nodiscard]] T pop_first() { + if (modifiers.empty()) { + throw std::runtime_error("No modifiers found"); + } + + T result = std::get(modifiers.front()); + modifiers.erase(modifiers.begin()); + return result; + } + + template + [[nodiscard]] T pop_last() { + if (modifiers.empty()) { + throw std::runtime_error("No modifiers found"); + } + + T result = std::get(modifiers.back()); + modifiers.pop_back(); + return result; + } + + template + void remove(long long index) { + if (index >= static_cast(modifiers.size())) { + throw std::runtime_error("Index out of bounds"); + } + + modifiers.erase(modifiers.begin() + index); + } + + TO_NEO_JSON_IMPL { + neo::json json("Modifiers"); + std::vector modifiers_json; + + for (const auto &modifier : modifiers) { + if (std::holds_alternative(modifier)) { + modifiers_json.push_back(std::get(modifier).to_json()); + } else if (std::holds_alternative(modifier)) { + modifiers_json.push_back(std::get(modifier).to_json()); + } else if (std::holds_alternative(modifier)) { + modifiers_json.push_back(std::get(modifier).to_json()); + } else if (std::holds_alternative(modifier)) { + modifiers_json.push_back(std::get(modifier).to_json()); + } else if (std::holds_alternative(modifier)) { + modifiers_json.push_back(std::get(modifier).to_json()); + } else if (std::holds_alternative(modifier)) { + modifiers_json.push_back(std::get(modifier).to_json()); + } else if (std::holds_alternative(modifier)) { + modifiers_json.push_back(std::get(modifier).to_json()); + } + } + + json.add("modifiers", modifiers_json); + return json; + } + }; +} + +#undef CHECK_N_SET +#endif // __MODIFIERS_H__ \ No newline at end of file diff --git a/source/parser/ast/include/config/case_types.def b/source/parser/ast/include/config/case_types.def new file mode 100644 index 0000000..f806c13 --- /dev/null +++ b/source/parser/ast/include/config/case_types.def @@ -0,0 +1,217 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // +// You are allowed to use, modify, redistribute, and create derivative works, even for // +// commercial purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// +// // +// this file is used as a helper to define the cases for token types used by the parser // +// // +//===-----------------------------------------------------------------------------------------====// + +#ifndef __CASE_TYPES_H__ +#define __CASE_TYPES_H__ + +#define IS_LITERAL \ + {token::LITERAL_STRING, \ + token::LITERAL_TRUE, \ + token::LITERAL_FALSE, \ + token::LITERAL_INTEGER, \ + token::LITERAL_COMPLIER_DIRECTIVE, \ + token::LITERAL_FLOATING_POINT, \ + token::LITERAL_CHAR, \ + token::LITERAL_NULL} + +#define IS_IDENTIFIER \ + { \ + token::IDENTIFIER, token::PRIMITIVE_VOID, token::PRIMITIVE_BOOL, \ + token::PRIMITIVE_BYTE, token::PRIMITIVE_CHAR, token::PRIMITIVE_I8, \ + token::PRIMITIVE_U8, token::PRIMITIVE_I16, token::PRIMITIVE_U16, \ + token::PRIMITIVE_I32, token::PRIMITIVE_U32, token::PRIMITIVE_F32, \ + token::PRIMITIVE_I64, token::PRIMITIVE_U64, token::PRIMITIVE_F64, \ + token::PRIMITIVE_I128, token::PRIMITIVE_U128, \ + } + +#define IS_KEYWORD \ + {token::KEYWORD_IF, token::KEYWORD_ELSE, token::KEYWORD_UNLESS, \ + token::KEYWORD_SPAWN, token::KEYWORD_AWAIT, token::KEYWORD_THREAD, \ + token::KEYWORD_MACRO, token::KEYWORD_DEFINE, token::KEYWORD_FUNCTION, \ + token::KEYWORD_OPERATOR, token::KEYWORD_INLINE, token::KEYWORD_RETURN, \ + token::KEYWORD_ENCLOSING, token::KEYWORD_ASYNC, token::KEYWORD_FOR, \ + token::KEYWORD_WHILE, token::KEYWORD_BREAK, token::KEYWORD_CONTINUE, \ + token::KEYWORD_CASE, token::KEYWORD_MATCH, token::KEYWORD_SWITCH, \ + token::KEYWORD_DEFAULT, token::KEYWORD_ENUM, token::KEYWORD_TYPE, \ + token::KEYWORD_CLASS, token::KEYWORD_UNION, token::KEYWORD_STRUCT, \ + token::KEYWORD_ABSTRACT, token::KEYWORD_INTERFACE, token::KEYWORD_IS, \ + token::KEYWORD_TRY, token::KEYWORD_PANIC, token::KEYWORD_CATCH, \ + token::KEYWORD_FINALLY, token::KEYWORD_LET, token::KEYWORD_PRIVATE, \ + token::KEYWORD_AUTO, token::KEYWORD_CONST, token::KEYWORD_GLOBAL, \ + token::KEYWORD_FROM, token::KEYWORD_FFI, token::KEYWORD_IMPORT, \ + token::KEYWORD_EXTERN, token::KEYWORD_YIELD, token::KEYWORD_AS, \ + token::KEYWORD_DERIVES, token::KEYWORD_MODULE} + +#define IS_DELIMITER \ + {token::DELIMITER_TAB, \ + token::DELIMITER_NEWLINE, \ + token::EOF_TOKEN, \ + token::DELIMITER_SPACE, \ + token::WHITESPACE} + +#define IS_UNARY_OPERATOR \ + {token::OPERATOR_ADD, \ + token::OPERATOR_SUB, \ + token::OPERATOR_BITWISE_NOT, \ + token::OPERATOR_LOGICAL_NOT, \ + token::OPERATOR_POW, \ + token::OPERATOR_ABS, \ + token::OPERATOR_INC, \ + token::OPERATOR_DEC, \ + token::OPERATOR_RANGE, \ + token::OPERATOR_MUL, \ + token::OPERATOR_MAT, \ + token::OPERATOR_BITWISE_AND, \ + token::OPERATOR_RANGE_INCLUSIVE} + +#define IS_OPERATOR \ + {token::OPERATOR_ADD, \ + token::OPERATOR_SUB, \ + token::OPERATOR_MUL, \ + token::OPERATOR_DIV, \ + token::OPERATOR_MOD, \ + token::OPERATOR_MAT, \ + token::OPERATOR_BITWISE_AND, \ + token::OPERATOR_BITWISE_OR, \ + token::OPERATOR_BITWISE_XOR, \ + token::OPERATOR_BITWISE_NOT, \ + token::OPERATOR_ASSIGN, \ + token::OPERATOR_LOGICAL_NOT, \ + token::OPERATOR_POW, \ + token::OPERATOR_ABS, \ + token::OPERATOR_BITWISE_L_SHIFT, \ + token::OPERATOR_BITWISE_NAND, \ + token::OPERATOR_BITWISE_R_SHIFT, \ + token::OPERATOR_BITWISE_NOR, \ + token::OPERATOR_EQUAL, \ + token::OPERATOR_NOT_EQUAL, \ + token::OPERATOR_GREATER_THAN_EQUALS, \ + token::OPERATOR_INC, \ + token::OPERATOR_DEC, \ + token::OPERATOR_LESS_THAN_EQUALS, \ + token::OPERATOR_ADD_ASSIGN, \ + token::OPERATOR_SUB_ASSIGN, \ + token::OPERATOR_MUL_ASSIGN, \ + token::OPERATOR_BITWISE_AND_ASSIGN, \ + token::OPERATOR_BITWISE_OR_ASSIGN, \ + token::OPERATOR_BITWISE_NOR_ASSIGN, \ + token::OPERATOR_BITWISE_XOR_ASSIGN, \ + token::OPERATOR_BITWISE_NOT_ASSIGN, \ + token::OPERATOR_DIV_ASSIGN, \ + token::OPERATOR_MOD_ASSIGN, \ + token::OPERATOR_MAT_ASSIGN, \ + token::OPERATOR_LOGICAL_AND, \ + token::OPERATOR_LOGICAL_NAND, \ + token::OPERATOR_LOGICAL_OR, \ + token::OPERATOR_LOGICAL_NOR, \ + token::OPERATOR_LOGICAL_XOR, \ + token::OPERATOR_RANGE, \ + token::OPERATOR_ARROW, \ + token::OPERATOR_NOT_ASSIGN, \ + token::OPERATOR_SCOPE, \ + token::OPERATOR_REF_EQUAL, \ + token::OPERATOR_POWER_ASSIGN, \ + token::OPERATOR_AND_ASSIGN, \ + token::OPERATOR_NAND_ASSIGN, \ + token::OPERATOR_OR_ASSIGN, \ + token::OPERATOR_NOR_ASSIGN, \ + token::OPERATOR_XOR_ASSIGN, \ + token::OPERATOR_BITWISE_NAND_ASSIGN, \ + token::OPERATOR_BITWISE_L_SHIFT_ASSIGN, \ + token::OPERATOR_BITWISE_R_SHIFT_ASSIGN, \ + token::OTHERS, \ + token::PUNCTUATION_OPEN_ANGLE, \ + token::PUNCTUATION_CLOSE_ANGLE, \ + token::OPERATOR_RANGE_INCLUSIVE} + +#define IS_BINARY_OPERATOR \ + {token::OPERATOR_ADD, \ + token::OPERATOR_SUB, \ + token::OPERATOR_MUL, \ + token::OPERATOR_DIV, \ + token::OPERATOR_MOD, \ + token::OPERATOR_MAT, \ + token::OPERATOR_BITWISE_AND, \ + token::OPERATOR_BITWISE_OR, \ + token::OPERATOR_BITWISE_XOR, \ + token::OPERATOR_ASSIGN, \ + token::OPERATOR_BITWISE_NOR_ASSIGN, \ + token::OPERATOR_POW, \ + token::OPERATOR_BITWISE_L_SHIFT, \ + token::OPERATOR_BITWISE_NOT_ASSIGN, \ + token::OPERATOR_BITWISE_R_SHIFT, \ + token::OPERATOR_EQUAL, \ + token::OPERATOR_MAT_ASSIGN, \ + token::OPERATOR_NOT_EQUAL, \ + token::OPERATOR_GREATER_THAN_EQUALS, \ + token::OPERATOR_LESS_THAN_EQUALS, \ + token::OPERATOR_ADD_ASSIGN, \ + token::OPERATOR_SUB_ASSIGN, \ + token::OPERATOR_MUL_ASSIGN, \ + token::OPERATOR_DIV_ASSIGN, \ + token::OPERATOR_MOD_ASSIGN, \ + token::OPERATOR_BITWISE_AND_ASSIGN, \ + token::OPERATOR_BITWISE_OR_ASSIGN, \ + token::OPERATOR_BITWISE_XOR_ASSIGN, \ + token::OPERATOR_LOGICAL_AND, \ + token::OPERATOR_LOGICAL_OR, \ + token::OPERATOR_LOGICAL_XOR, \ + token::OPERATOR_RANGE, \ + token::OPERATOR_ARROW, \ + token::OPERATOR_NOT_ASSIGN, \ + token::OPERATOR_REF_EQUAL, \ + token::OPERATOR_POWER_ASSIGN, \ + token::OPERATOR_AND_ASSIGN, \ + token::OPERATOR_NAND_ASSIGN, \ + token::OPERATOR_OR_ASSIGN, \ + token::OPERATOR_NOR_ASSIGN, \ + token::OPERATOR_XOR_ASSIGN, \ + token::OPERATOR_BITWISE_NAND_ASSIGN, \ + token::OPERATOR_BITWISE_L_SHIFT_ASSIGN, \ + token::OPERATOR_BITWISE_R_SHIFT_ASSIGN, \ + token::OTHERS, \ + token::PUNCTUATION_OPEN_ANGLE, \ + token::PUNCTUATION_CLOSE_ANGLE, \ + token::OPERATOR_RANGE_INCLUSIVE} + +#define IS_PUNCTUATION \ + {token::PUNCTUATION_OPEN_PAREN, \ + token::PUNCTUATION_CLOSE_PAREN, \ + token::PUNCTUATION_OPEN_BRACE, \ + token::PUNCTUATION_CLOSE_BRACE, \ + token::PUNCTUATION_OPEN_BRACKET, \ + token::PUNCTUATION_CLOSE_BRACKET, \ + token::PUNCTUATION_COMMA, \ + token::PUNCTUATION_SEMICOLON, \ + token::PUNCTUATION_COLON, \ + token::PUNCTUATION_QUESTION_MARK, \ + token::PUNCTUATION_DOT, \ + token::PUNCTUATION_SINGLE_LINE_COMMENT, \ + token::PUNCTUATION_MULTI_LINE_COMMENT, \ + token::PUNCTUATION_ELLIPSIS} + +#define IS_PRIMITIVE \ + {token::PRIMITIVE_VOID, token::PRIMITIVE_BOOL, token::PRIMITIVE_BYTE, \ + token::PRIMITIVE_CHAR, token::PRIMITIVE_POINTER, token::PRIMITIVE_I8, \ + token::PRIMITIVE_U8, token::PRIMITIVE_I16, token::PRIMITIVE_U16, \ + token::PRIMITIVE_I32, token::PRIMITIVE_U32, token::PRIMITIVE_F32, \ + token::PRIMITIVE_I64, token::PRIMITIVE_U64, token::PRIMITIVE_F64, \ + token::PRIMITIVE_FLOAT, token::PRIMITIVE_I128, token::PRIMITIVE_U128, \ + token::PRIMITIVE_INT, token::PRIMITIVE_DECIMAL, token::PRIMITIVE_STRING, \ + token::PRIMITIVE_LIST, token::PRIMITIVE_TUPLE, token::PRIMITIVE_SET, \ + token::PRIMITIVE_MAP, token::PRIMITIVE_ANY} + +#endif // __CASE_TYPES_H__ \ No newline at end of file diff --git a/source/parser/ast/include/AST_classifier.hh b/source/parser/ast/include/core/AST_classifier.hh similarity index 93% rename from source/parser/ast/include/AST_classifier.hh rename to source/parser/ast/include/core/AST_classifier.hh index 3555927..de11a77 100644 --- a/source/parser/ast/include/AST_classifier.hh +++ b/source/parser/ast/include/core/AST_classifier.hh @@ -16,10 +16,8 @@ #ifndef __AST_CLASSIFIER_H__ #define __AST_CLASSIFIER_H__ -#include "parser/ast/include/AST_core.def" +#include "parser/ast/include/config/AST_config.def" -__AST_BEGIN { +__AST_BEGIN {} -} - -#endif // __AST_CLASSIFIER_H__ \ No newline at end of file +#endif // __AST_CLASSIFIER_H__ \ No newline at end of file diff --git a/source/parser/ast/include/AST_context.hh b/source/parser/ast/include/core/AST_context.hh similarity index 93% rename from source/parser/ast/include/AST_context.hh rename to source/parser/ast/include/core/AST_context.hh index 2878e8c..ae10c2c 100644 --- a/source/parser/ast/include/AST_context.hh +++ b/source/parser/ast/include/core/AST_context.hh @@ -1,4 +1,3 @@ - //===------------------------------------------ C++ ------------------------------------------====// // // // Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // @@ -17,10 +16,8 @@ #ifndef __AST_CONTEXT_H__ #define __AST_CONTEXT_H__ -#include "parser/ast/include/AST_core.def" - -__AST_BEGIN { +#include "parser/ast/include/config/AST_config.def" -} +__AST_BEGIN {} -#endif // __AST_CONTEXT_H__ \ No newline at end of file +#endif // __AST_CONTEXT_H__ \ No newline at end of file diff --git a/source/parser/ast/include/AST_matcher.hh b/source/parser/ast/include/core/AST_matcher.hh similarity index 93% rename from source/parser/ast/include/AST_matcher.hh rename to source/parser/ast/include/core/AST_matcher.hh index 8ef98f9..81ee8de 100644 --- a/source/parser/ast/include/AST_matcher.hh +++ b/source/parser/ast/include/core/AST_matcher.hh @@ -16,10 +16,8 @@ #ifndef __AST_MATCHER_H__ #define __AST_MATCHER_H__ -#include "parser/ast/include/AST_core.def" +#include "parser/ast/include/config/AST_config.def" -__AST_BEGIN { +__AST_BEGIN {} -} - -#endif // __AST_MATCHER_H__ \ No newline at end of file +#endif // __AST_MATCHER_H__ \ No newline at end of file diff --git a/source/parser/ast/include/core/AST_nodes.hh b/source/parser/ast/include/core/AST_nodes.hh new file mode 100644 index 0000000..76cf665 --- /dev/null +++ b/source/parser/ast/include/core/AST_nodes.hh @@ -0,0 +1,359 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // +// You are allowed to use, modify, redistribute, and create derivative works, even for // +// commercial purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// +// // +// This file contains the AST nodes used by the parser and lexer. // +// All the code here is subject to change with refactoring. // +// // +//===-----------------------------------------------------------------------------------------====// + +#ifndef __AST_NODES_H__ +#define __AST_NODES_H__ + +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/config/AST_generate.def" +#include "parser/ast/include/config/AST_generate.hh" +#include "parser/ast/include/types/AST_types.hh" +#include "parser/ast/include/types/AST_visitor.hh" +#include "token/include/token_list.hh" + +#define null nullptr +#define GENERATE_IF_STATEMENTS(name) \ + if constexpr (std::is_same_v) { \ + return parse_##name(std::forward(args)...); \ + } + +__AST_NODE_BEGIN { + class Node { // base node + public: + Node() = default; + virtual ~Node() = default; + virtual void accept(__AST_VISITOR::Visitor &visitor) const = 0; + [[nodiscard]] virtual nodes getNodeType() const = 0; + [[nodiscard]] virtual std::string getNodeName() const = 0; + + Node(const Node &) = default; + Node &operator=(const Node &) = default; + Node(Node &&) = default; + Node &operator=(Node &&) = default; + }; + + /* + * Expression class + * + * This class is responsible for parsing the expression grammar. + * It is a recursive descent parser that uses the token list + * to parse the expression grammar. + * + * (its very bad quality but will be improved when written in helix) + * + * usage: + * Expression expr(tokens); + * NodeT<> node = expr.parse(); + * + * // or + * + * NodeT<...> node = expr.parse<...>(); + */ + class Expression { // THIS IS NOT A NODE + AST_CLASS_BASE(Expression, EXPRS){}; + + p_r<> parse_primary(); + template + p_r parse(Args &&...args) { /* NOLINT */ + if constexpr (std ::is_same_v) { + return parse_LiteralExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_BinaryExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_UnaryExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_IdentExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_NamedArgumentExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ArgumentExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ArgumentListExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_GenericInvokeExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_GenericInvokePathExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ScopePathExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_DotPathExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ArrayAccessExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_PathExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_FunctionCallExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ArrayLiteralExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_TupleLiteralExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_SetLiteralExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_MapPairExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_MapLiteralExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ObjInitExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_LambdaExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_TernaryExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ParenthesizedExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_CastExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_InstOfExpr(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_Type(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_AsyncThreading(std ::forward(args)...); + } + }; + + private: + p_r parse_NamedArgumentExpr(bool is_anonymous = false); + p_r parse_PathExpr(p_r<> simple_path = null); + p_r parse_UnaryExpr(p_r<> lhs = null); + p_r parse_BinaryExpr(p_r<> lhs, int min_precedence); + p_r parse_LiteralExpr(p_r<> str_concat = null); + p_r parse_ArgumentExpr(); + p_r parse_DotPathExpr(p_r<> lhs = null); + p_r parse_IdentExpr(); + p_r parse_ScopePathExpr(p_r<> lhs = null); + p_r parse_ArrayAccessExpr(p_r<> lhs = null); + p_r parse_ArgumentListExpr(); + p_r parse_GenericInvokeExpr(); + p_r parse_GenericInvokePathExpr(); + p_r parse_ArrayLiteralExpr(); + p_r parse_TupleLiteralExpr(p_r<> starting_element = null); + p_r parse_SetLiteralExpr(p_r<> starting_value); + p_r parse_MapPairExpr(); + p_r parse_MapLiteralExpr(p_r<> starting_value); + p_r parse_ObjInitExpr(bool skip_start_brace = false, p_r<> obj_path = null); + p_r parse_LambdaExpr(); + p_r parse_TernaryExpr(p_r<> lhs = null); + p_r parse_ParenthesizedExpr(p_r<> expr = null); + p_r parse_CastExpr(p_r<> lhs); + p_r parse_InstOfExpr(p_r<> lhs = null); + p_r parse_Type(); + p_r parse_AsyncThreading(); + p_r parse_FunctionCallExpr(p_r<> lhs = null); + }; + + /* + * Statement class + * + * This class is responsible for parsing the statement grammar. + * It is a recursive descent parser that uses the token list + * to parse the statement grammar. + * + * (its very bad quality but will be improved when written in helix) + * + * usage: + * Statement state(tokens); + * NodeT<> node = state.parse(); + * + * // or + * + * NodeT<...> node = state.parse<...>(); + */ + class Statement { // THIS IS NOT A NODE + AST_CLASS_BASE(Statement, STATES), expr_parser(iter) {}; + + template + p_r parse(Args &&...args) { /* NOLINT */ + if constexpr (std ::is_same_v) { + return parse_NamedVarSpecifier(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_NamedVarSpecifierList(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ForPyStatementCore(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ForCStatementCore(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ForState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_WhileState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ElseState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_IfState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_SwitchCaseState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_SwitchState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_YieldState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_DeleteState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_AliasState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_SingleImportState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_MultiImportState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ImportState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ReturnState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_BreakState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_BlockState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_SuiteState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ContinueState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_CatchState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_FinallyState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_TryState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_PanicState(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ExprState(std ::forward(args)...); + }; + }; + + private: + std::vector modifiers; + Expression expr_parser; + + p_r parse_NamedVarSpecifier(bool force_type = false); + p_r parse_NamedVarSpecifierList(bool force_types = false); + p_r parse_ForPyStatementCore(bool skip_start = false); + p_r parse_ForCStatementCore(bool skip_start = false); + p_r parse_ForState(); + p_r parse_WhileState(); + p_r parse_IfState(); + p_r parse_ElseState(); + p_r parse_SwitchState(); + p_r parse_SwitchCaseState(); + p_r parse_ImportState(); + p_r parse_SingleImportState(); + p_r parse_MultiImportState(); + p_r parse_AliasState(); + p_r parse_YieldState(); + p_r parse_DeleteState(); + p_r parse_ReturnState(); + p_r parse_BreakState(); + p_r parse_ContinueState(); + p_r parse_ExprState(); + p_r parse_BlockState(); + p_r parse_TryState(); + p_r parse_CatchState(); + p_r parse_FinallyState(); + p_r parse_PanicState(); + p_r parse_SuiteState(); + }; + + /* + * Declaration class + * + * This class is responsible for parsing the declaration grammar. + * It is a recursive descent parser that uses the token list + * to parse the declaration grammar. + * + * (its very bad quality but will be improved when written in helix) + * + * usage: + * Declaration decl(tokens); + * NodeT<> node = decl.parse(); + * + * // or + * + * NodeT<...> node = decl.parse<...>(); + */ + class Declaration { + AST_CLASS_BASE(Declaration, DECLS), state_parser(iter), expr_parser(iter) {}; + + template + p_r parse(Args &&...args) { /* NOLINT */ + if constexpr (std ::is_same_v) { + return parse_RequiresParamDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_RequiresParamList(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_EnumMemberDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_UDTDeriveDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_TypeBoundList(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_TypeBoundDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_RequiresDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_StructDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ConstDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ClassDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_InterDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_EnumDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_TypeDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_FuncDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_VarDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_FFIDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_LetDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_OpDecl(std ::forward(args)...); + } else if constexpr (std ::is_same_v) { + return parse_ModuleDecl(std ::forward(args)...); + } + } + + private: + Statement state_parser; + Expression expr_parser; + + p_r parse_RequiresParamDecl(); + p_r parse_RequiresParamList(); + p_r parse_EnumMemberDecl(); + p_r parse_UDTDeriveDecl(); + p_r parse_TypeBoundList(); + p_r parse_TypeBoundDecl(); + p_r parse_RequiresDecl(); + p_r parse_ModuleDecl(const std::shared_ptr& modifiers = nullptr); + p_r parse_StructDecl(const std::shared_ptr& modifiers = nullptr); + p_r parse_ConstDecl(); + p_r parse_ClassDecl(const std::shared_ptr& modifiers = nullptr); + p_r parse_InterDecl(const std::shared_ptr& modifiers = nullptr); + p_r parse_EnumDecl(const std::shared_ptr& modifiers = nullptr); + p_r parse_TypeDecl(const std::shared_ptr& modifiers = nullptr); + p_r parse_FuncDecl(const std::shared_ptr& modifiers = nullptr); + p_r parse_VarDecl(bool force_type = false, bool force_value = false); + p_r parse_FFIDecl(const std::shared_ptr& modifiers = nullptr); + p_r parse_LetDecl(const std::shared_ptr& modifiers = nullptr); + p_r parse_OpDecl(const std::shared_ptr& modifiers = nullptr); + }; +} // namespace __AST_BEGIN + +#undef null + +#endif // __AST_NODES_H__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/AST_Annotations.hh b/source/parser/ast/include/nodes/AST_Annotations.hh new file mode 100644 index 0000000..e69de29 diff --git a/source/parser/ast/include/nodes/AST_Declarations.hh b/source/parser/ast/include/nodes/AST_Declarations.hh new file mode 100644 index 0000000..7dfba53 --- /dev/null +++ b/source/parser/ast/include/nodes/AST_Declarations.hh @@ -0,0 +1,261 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // +// You are allowed to use, modify, redistribute, and create derivative works, even for // +// commercial purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// + +#ifndef __AST_DECLARATIONS_H__ +#define __AST_DECLARATIONS_H__ + +#include +#include + +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/config/AST_modifiers.hh" +#include "parser/ast/include/core/AST_nodes.hh" +#include "parser/ast/include/nodes/AST_Expressions.hh" +#include "parser/ast/include/types/AST_types.hh" + +__AST_NODE_BEGIN { + class RequiresParamDecl final : public Node { + BASE_CORE_METHODS(RequiresParamDecl); + + // RequiresParamDecl := 'const'? (S.NamedVarSpecifier) ('=' E)? + explicit RequiresParamDecl(bool /* unused */) {} + + NodeT var; + NodeT<> value; + bool is_const = false; + }; + + class RequiresParamList final : public Node { + BASE_CORE_METHODS(RequiresParamList); + + // RequiresParamList := (RequiresParamDecl (',' RequiresParamDecl)*)? + explicit RequiresParamList(NodeT first) { + (this->params).emplace_back(std::move(first)); + } + + NodeV params; + }; + + class EnumMemberDecl final : public Node { + BASE_CORE_METHODS(EnumMemberDecl); + + // EnumMemberDecl := E.IdentExpr ('=' E)? + explicit EnumMemberDecl(NodeT name) + : name(std::move(name)) {} + + NodeT name; + NodeT<> value; + }; + + class UDTDeriveDecl final : public Node { + BASE_CORE_METHODS(UDTDeriveDecl); + + // UDTDeriveDecl := 'derives' (VisDecl? E.Type (',' VisDecl? E.Type)*)? + explicit UDTDeriveDecl(std::pair, AccessSpecifier> first) { + (this->derives).emplace_back(std::move(first)); + } + + std::vector, AccessSpecifier>> derives; + }; + + class TypeBoundList final : public Node { + BASE_CORE_METHODS(TypeBoundList); + + // TypeBoundList := (TypeBoundDecl (',' TypeBoundDecl)*)? + explicit TypeBoundList(NodeT bound) { + (this->bounds).emplace_back(std::move(bound)); + } + + NodeV bounds; + }; + + class TypeBoundDecl final : public Node { + BASE_CORE_METHODS(TypeBoundDecl); + + // TypeBoundDecl := InstOfExpr + + NodeT bound; + }; + + class RequiresDecl final : public Node { + BASE_CORE_METHODS(RequiresDecl); + + // RequiresDecl := 'requires' '<' RequiresParamList '>' ('if' TypeBoundList)? + explicit RequiresDecl(NodeT params) + : params(std::move(params)) {} + + NodeT params; + NodeT bounds; + }; + + class StructDecl final : public Node { + BASE_CORE_METHODS(StructDecl); + + // StructDecl := 'const'? VisDecl? 'struct' E.IdentExpr UDTDeriveDecl? RequiresDecl? S.Suite + explicit StructDecl(bool /* unused */) {} + + NodeT name; + NodeT derives; + NodeT generics; + NodeT body; + + Modifiers modifiers = Modifiers(Modifiers::ExpectedModifier::ClassSpec, + Modifiers::ExpectedModifier::AccessSpec); + }; + + class ConstDecl final : public Node { + BASE_CORE_METHODS(ConstDecl); + + // ConstDecl := VisDecl? 'const' SharedModifiers VarDecl* ';' + + NodeV vars; + Modifiers modifiers = Modifiers(Modifiers::ExpectedModifier::FuncSpec); + }; + + class ClassDecl final : public Node { + BASE_CORE_METHODS(ClassDecl); + + // ClassDecl := 'const'? VisDecl? 'class' E.IdentExpr UDTDeriveDecl? RequiresDecl? + // S.Suite + + explicit ClassDecl(bool /* unused */) {} + + Modifiers modifiers = Modifiers(Modifiers::ExpectedModifier::ClassSpec, + Modifiers::ExpectedModifier::AccessSpec); + NodeT name; + NodeT derives; + NodeT generics; + NodeT body; + }; + + class InterDecl final : public Node { + BASE_CORE_METHODS(InterDecl); + + // InterDecl := 'const'? VisDecl? 'interface' E.IdentExpr UDTDeriveDecl? RequiresDecl? + // S.Suite + + explicit InterDecl(bool /* unused */) {} + + Modifiers modifiers = Modifiers(Modifiers::ExpectedModifier::ClassSpec, + Modifiers::ExpectedModifier::AccessSpec); + NodeT name; + NodeT derives; + NodeT generics; + NodeT body; + }; + + class EnumDecl final : public Node { + BASE_CORE_METHODS(EnumDecl); + + // EnumDecl := VisDecl? 'enum' ('derives' E.Type)? E.ObjInitExpr + explicit EnumDecl(bool /* unused */) {} + + Modifiers vis = Modifiers(Modifiers::ExpectedModifier::AccessSpec); + NodeT name; + NodeT derives; + NodeV members; + }; + + class TypeDecl final : public Node { + BASE_CORE_METHODS(TypeDecl); + + // TypeDecl := VisDecl? 'type' E.IdentExpr RequiresDecl? '=' E ';' + + Modifiers vis = Modifiers(Modifiers::ExpectedModifier::AccessSpec); + NodeT name; + NodeT generics; + NodeT<> value; + }; + + class FuncDecl final : public Node { + BASE_CORE_METHODS(FuncDecl); + + // FuncDecl := SharedModifiers? 'fn' E.PathExpr '(' VarDecl[true]* ')' RequiresDecl? ('->' + // E.TypeExpr)? (S.Suite | ';' | '=' ('default' | 'delete')) + + explicit FuncDecl(bool /* unused */) {} + + Modifiers modifiers = Modifiers(Modifiers::ExpectedModifier::FuncSpec, + Modifiers::ExpectedModifier::AccessSpec); + Modifiers qualifiers = Modifiers(Modifiers::ExpectedModifier::FuncQual); + + NodeT name; + NodeV params; + NodeT generics; + NodeT returns; + NodeT body; + }; + + class VarDecl final : public Node { + BASE_CORE_METHODS(VarDecl); + + // VarDecl := S.NamedVarSpecifier ('=' E)? ~ also pass in a bool to force type need + explicit VarDecl(NodeT var, NodeT<> value = nullptr) + : var(std::move(var)) + , value(std::move(value)) {} + + NodeT var; + NodeT<> value; + }; + + class FFIDecl final : public Node { + BASE_CORE_METHODS(FFIDecl); + + // FFIDecl := VisDecl? 'ffi' L.StringLiteral D + + Modifiers vis = Modifiers(Modifiers::ExpectedModifier::AccessSpec); + NodeT name; + NodeT<> value; + }; + + class LetDecl final : public Node { + BASE_CORE_METHODS(LetDecl); + + // LetDecl := VisDecl? 'let' SharedModifiers VarDecl* ';' + explicit LetDecl(bool /* unused */) {} + + Modifiers modifiers = Modifiers(Modifiers::ExpectedModifier::FuncSpec); + Modifiers vis = Modifiers(Modifiers::ExpectedModifier::AccessSpec); + NodeV vars; + }; + + class OpDecl final : public Node { + BASE_CORE_METHODS(OpDecl); + + // OpDecl := SharedModifiers? 'op' T FuncDecl[no_SharedModifiers=true] + + Modifiers modifiers = Modifiers(Modifiers::ExpectedModifier::FuncSpec, + Modifiers::ExpectedModifier::AccessSpec); + token::Token op; + NodeT func; + }; + + class ModuleDecl final : public Node { + BASE_CORE_METHODS(ModuleDecl); + + // ModuleDecl := 'inline'? 'module' E.PathExpr S.Suite + explicit ModuleDecl(NodeT name, + NodeT body, + bool inline_module = false) + + : body(std::move(body)) + , name(std::move(name)) + , inline_module(inline_module) {} + + NodeT body; + NodeT name; + bool inline_module = false; + }; + +} // namespace __AST_NODE_BEGIN + +#endif // __AST_DECLARATIONS_H__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/AST_Expressions.hh b/source/parser/ast/include/nodes/AST_Expressions.hh new file mode 100644 index 0000000..9f7ef3a --- /dev/null +++ b/source/parser/ast/include/nodes/AST_Expressions.hh @@ -0,0 +1,368 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // +// You are allowed to use, modify, redistribute, and create derivative works, even for // +// commercial purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// + +#ifndef __AST_EXPRESSIONS_H__ +#define __AST_EXPRESSIONS_H__ + +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/config/AST_modifiers.hh" +#include "parser/ast/include/core/AST_nodes.hh" +#include "parser/ast/include/types/AST_types.hh" + +__AST_NODE_BEGIN { + class LiteralExpr final : public Node { // := LITERAL + BASE_CORE_METHODS(LiteralExpr); + + enum class LiteralType { + Integer, + Float, + String, + Char, + Boolean, + Null, + }; + + LiteralExpr(token::Token value, LiteralType type) + : value(std::move(value)) + , type(type) {} + + token::Token value; + LiteralType type; + }; + + class BinaryExpr final : public Node { // := E op E + BASE_CORE_METHODS(BinaryExpr); + + BinaryExpr(NodeT<> lhs, NodeT<> rhs, token::Token op) + : lhs(std::move(lhs)) + , op(std::move(op)) + , rhs(std::move(rhs)) {} + + NodeT<> lhs; + token::Token op; + NodeT<> rhs; + }; + + class UnaryExpr final : public Node { // := op E + BASE_CORE_METHODS(UnaryExpr); + + enum class PosType { PreFix, PostFix }; + + UnaryExpr(NodeT<> opd, token::Token op, PosType type) + : opd(std::move(opd)) + , op(std::move(op)) + , type(type) {} + + NodeT<> opd; + token::Token op; + PosType type = PosType::PreFix; + }; + + class IdentExpr final : public Node { // := T + BASE_CORE_METHODS(IdentExpr); + + explicit IdentExpr(token::Token name, bool is_reserved_primitive = false) + : name(std::move(name)) + , is_reserved_primitive(is_reserved_primitive) {} + + token::Token name; + bool is_reserved_primitive = false; + }; + + class NamedArgumentExpr final : public Node { // := IdentExpr '=' E + BASE_CORE_METHODS(NamedArgumentExpr); + + NamedArgumentExpr(NodeT name, NodeT<> value) + : name(std::move(name)) + , value(std::move(value)) {} + + NodeT name; + NodeT<> value; + }; + + class ArgumentExpr final : public Node { // := PositionalArgumentExpr | NamedArgumentExpr + BASE_CORE_METHODS(ArgumentExpr); + + explicit ArgumentExpr(NodeT<> value) + : value(std::move(value)) + , type(ArgumentType::Positional){}; + + enum class ArgumentType { + Positional, + Keyword, + }; + + NodeT<> value; + ArgumentType type; + }; + + class ArgumentListExpr final : public Node { // := '(' ArgumentExpr (',' ArgumentExpr)* ')' + BASE_CORE_METHODS(ArgumentListExpr); + + explicit ArgumentListExpr(NodeT<> args) { + if (args != nullptr) { + (this->args).emplace_back(std::move(args)); + } + } + + NodeV<> args; + }; + + class GenericInvokeExpr final + : public Node { // := '<' Type ((',' Type)*)? '>' + BASE_CORE_METHODS(GenericInvokeExpr); + + explicit GenericInvokeExpr(NodeT<> args) { + if (args != nullptr) { + (this->args).emplace_back(std::move(args)); + } + } + + NodeV<> args; + }; + + class GenericInvokePathExpr final : public Node { // := E GenericInvokeExpr + BASE_CORE_METHODS(GenericInvokePathExpr); + + GenericInvokePathExpr(NodeT<> path, NodeT<> generic); + + NodeT<> path; + NodeT<> generic; + }; + + class ScopePathExpr final : public Node { // := E '::' E + BASE_CORE_METHODS(ScopePathExpr); + + ScopePathExpr(NodeT<> lhs, NodeT<> rhs) + : lhs(std::move(lhs)) + , rhs(std::move(rhs)) {} + + NodeT<> lhs; + NodeT<> rhs; + }; + + class DotPathExpr final : public Node { // := E '.' E + BASE_CORE_METHODS(DotPathExpr); + + DotPathExpr(NodeT<> lhs, NodeT<> rhs) + : lhs(std::move(lhs)) + , rhs(std::move(rhs)) {} + + NodeT<> lhs; + NodeT<> rhs; + }; + + class ArrayAccessExpr final : public Node { // := E '[' E ']' + BASE_CORE_METHODS(ArrayAccessExpr); + + ArrayAccessExpr(NodeT<> lhs, NodeT<> rhs) + : lhs(std::move(lhs)) + , rhs(std::move(rhs)) {} + + NodeT<> lhs; + NodeT<> rhs; + }; + + class PathExpr final : public Node { // := ScopePathExpr | DotPathExpr + BASE_CORE_METHODS(PathExpr); + + explicit PathExpr(NodeT<> path) + : path(std::move(path)) + , type(PathType::Identifier) {} + + enum class PathType { + Scope, + Dot, + Identifier, + }; + + NodeT<> path; + PathType type; + }; + + class FunctionCallExpr final : public Node { // := PathExpr GenericInvokeExpr? ArgumentListExpr + BASE_CORE_METHODS(FunctionCallExpr); + + FunctionCallExpr(NodeT path, + NodeT args, + NodeT generic = nullptr) + : path(std::move(path)) + , args(std::move(args)) + , generic(std::move(generic)) {} + + NodeT path; + NodeT args; + NodeT generic; + }; + + class ArrayLiteralExpr final : public Node { // := '[' E (',' E)* ']' + BASE_CORE_METHODS(ArrayLiteralExpr); + + explicit ArrayLiteralExpr(NodeT<> value) { values.emplace_back(std::move(value)); } + + NodeV<> values; + }; + + class TupleLiteralExpr final : public Node { // := '(' E (',' E)* ')' + BASE_CORE_METHODS(TupleLiteralExpr); + + explicit TupleLiteralExpr(NodeT<> value) { values.emplace_back(std::move(value)); } + + NodeV<> values; + }; + + class SetLiteralExpr final : public Node { // := '{' E (',' E)* '}' + BASE_CORE_METHODS(SetLiteralExpr); + + explicit SetLiteralExpr(NodeT<> value) { values.emplace_back(std::move(value)); } + + NodeV<> values; + }; + + class MapPairExpr final : public Node { // := E ':' E + BASE_CORE_METHODS(MapPairExpr); + + MapPairExpr(NodeT<> key, NodeT<> value) + : key(std::move(key)) + , value(std::move(value)) {} + + NodeT<> key; + NodeT<> value; + }; + + class MapLiteralExpr final : public Node { + BASE_CORE_METHODS(MapLiteralExpr); + + explicit MapLiteralExpr(NodeT value) { values.emplace_back(std::move(value)); } + + NodeV values; + }; + + class ObjInitExpr final + : public Node { // := '{' (NamedArgumentExpr (',' NamedArgumentExpr)*)? '}' + BASE_CORE_METHODS(ObjInitExpr); + + explicit ObjInitExpr(NodeT args) { + this->kwargs.emplace_back(std::move(args)); + } + + NodeV kwargs; + NodeT<> path; + }; + + class LambdaExpr final : public Node { // TODO + BASE_CORE_METHODS(LambdaExpr); + + explicit LambdaExpr(token::Token marker) + : marker(std::move(marker)) {} + + NodeV<> args; + NodeT<> body; + NodeT<> ret; + token::Token marker; + }; + + class TernaryExpr final : public Node { // := (E '?' E ':' E) | (E 'if' E 'else' E) + BASE_CORE_METHODS(TernaryExpr); + + TernaryExpr(NodeT<> condition, NodeT<> if_true, NodeT<> if_false) + : condition(std::move(condition)) + , if_true(std::move(if_true)) + , if_false(std::move(if_false)) {} + + NodeT<> condition; + NodeT<> if_true; + NodeT<> if_false; + }; + + class ParenthesizedExpr final : public Node { // := '(' E ')' + BASE_CORE_METHODS(ParenthesizedExpr); + + explicit ParenthesizedExpr(NodeT<> value) + : value(std::move(value)) {} + + NodeT<> value; + }; + + class CastExpr final : public Node { // := E 'as' E + BASE_CORE_METHODS(CastExpr); + + CastExpr(NodeT<> value, NodeT<> type) + : value(std::move(value)) + , type(std::move(type)) {} + + NodeT<> value; + NodeT<> type; + }; + + class InstOfExpr final : public Node { // := E ('has' | 'derives') E + BASE_CORE_METHODS(InstOfExpr); + + enum class InstanceType { + Has, + Derives, + }; + + InstOfExpr(NodeT<> value, NodeT<> type, InstanceType op) + : value(std::move(value)) + , type(std::move(type)) + , op(op) {} + + NodeT<> value; + NodeT<> type; + InstanceType op; + }; + + /* DEPRECATED */ + class Type final : public Node { // := IdentExpr + BASE_CORE_METHODS(Type); + + explicit Type(NodeT<> value) + : value(std::move(value)) {} + explicit Type(NodeT value) + : value(std::move(value)) {} + explicit Type(bool /* unused */) {} + + NodeT<> value; + NodeT generics; + Modifiers specifiers = Modifiers(Modifiers::ExpectedModifier::TypeSpec); + }; + + class AsyncThreading final : public Node { // := IdentExpr + BASE_CORE_METHODS(AsyncThreading); + + enum class AsyncThreadingType { Await, Spawn, Thread, Other }; + + explicit AsyncThreading(NodeT<> value, const token::Token &type) + : value(std::move(value)) { + switch (type.token_kind()) { + case token::KEYWORD_AWAIT: + this->type = AsyncThreadingType::Await; + break; + case token::KEYWORD_SPAWN: + this->type = AsyncThreadingType::Spawn; + break; + case token::KEYWORD_THREAD: + this->type = AsyncThreadingType::Thread; + break; + default: + this->type = AsyncThreadingType::Other; + break; + } + } + + NodeT<> value; + AsyncThreadingType type; + }; +} + +#endif // __AST_EXPRESSIONS_H__ \ No newline at end of file diff --git a/source/parser/ast/source/expressions/AST_ScopeAccess.cc b/source/parser/ast/include/nodes/AST_Nodes.hh similarity index 76% rename from source/parser/ast/source/expressions/AST_ScopeAccess.cc rename to source/parser/ast/include/nodes/AST_Nodes.hh index a610832..b19b86c 100644 --- a/source/parser/ast/source/expressions/AST_ScopeAccess.cc +++ b/source/parser/ast/include/nodes/AST_Nodes.hh @@ -10,23 +10,12 @@ // // //====----------------------------------------------------------------------------------------====// -#include "parser/ast/include/AST.hh" +#ifndef __AST_ALL_NODES_H__ +#define __AST_ALL_NODES_H__ -__AST_BEGIN::node { -PARSE_SIG(ScopeAccess) { - if (tokens->empty()) [[unlikely]] { - return 0; - } +#include "parser/ast/include/nodes/AST_Annotations.hh" +#include "parser/ast/include/nodes/AST_Declarations.hh" +#include "parser/ast/include/nodes/AST_Expressions.hh" +#include "parser/ast/include/nodes/AST_Statements.hh" - return 0; -} - -TEST_SIG(ScopeAccess) { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -VISITOR_IMPL(ScopeAccess); -} // namespace __AST_BEGIN::node +#endif // __AST_ALL_NODES_H__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/AST_Statements.hh b/source/parser/ast/include/nodes/AST_Statements.hh new file mode 100644 index 0000000..3acccca --- /dev/null +++ b/source/parser/ast/include/nodes/AST_Statements.hh @@ -0,0 +1,350 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // +// You are allowed to use, modify, redistribute, and create derivative works, even for // +// commercial purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// + +#ifndef __AST_STATEMENTS_H__ +#define __AST_STATEMENTS_H__ + +#include + +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/core/AST_nodes.hh" +#include "parser/ast/include/types/AST_types.hh" + +// va +// var_decl := 'let' Ident (':' E)? ('=' expr)? ';' + +__AST_NODE_BEGIN { + class NamedVarSpecifier final : public Node { + BASE_CORE_METHODS(NamedVarSpecifier); + + // := Ident (':' E)? + + explicit NamedVarSpecifier(NodeT path, NodeT type = nullptr) + : path(std::move(path)) + , type(std::move(type)) { + if (type != nullptr) { + has_type = true; + } + } + + NodeT path; + NodeT type; + + bool has_type; + }; + + class NamedVarSpecifierList final : public Node { + BASE_CORE_METHODS(NamedVarSpecifierList); + + // := NamedVarSpecifier (',' NamedVarSpecifier)* + + explicit NamedVarSpecifierList(bool /* unused */) {} + + NodeV vars; + }; + + class ForPyStatementCore final : public Node { + BASE_CORE_METHODS(ForPyStatementCore); + + // := NamedVarSpecifier 'in 'expr' Suite + + explicit ForPyStatementCore(bool /* unused */) {} + + token::Token in_marker; + NodeT vars; + NodeT<> range; + NodeT<> body; + }; + + class ForCStatementCore final : public Node { + BASE_CORE_METHODS(ForCStatementCore); + + // := (expr)? ';' (expr)? ';' (expr)? Suite + + explicit ForCStatementCore(bool /* unused */) {} + + NodeT<> init; + NodeT<> condition; + NodeT<> update; + NodeT body; + }; + + class ForState final : public Node { + BASE_CORE_METHODS(ForState); + + // := 'for' (ForPyStatementCore | ForCStatementCore) + + enum class ForType { + Python, + C, + }; + + ForState(NodeT<> core, ForType type) + : core(std::move(core)) + , type(type) {} + + NodeT<> core; + ForType type; + }; + + class WhileState final : public Node { + BASE_CORE_METHODS(WhileState); + + // := 'while' expr Suite + + explicit WhileState(NodeT<> condition, NodeT body) + : condition(std::move(condition)) + , body(std::move(body)) {} + + NodeT<> condition; + NodeT body; + }; + + class IfState final : public Node { + BASE_CORE_METHODS(IfState); + + // := 'if' expr Suite (ElseState)? + + enum class IfType { + If, + Unless, + }; + + explicit IfState(NodeT<> condition) + : condition(std::move(condition)) {} + + NodeT<> condition; + NodeT body; + NodeV else_body; + IfType type = IfType::If; + }; + + class ElseState final : public Node { + BASE_CORE_METHODS(ElseState); + + // := 'else' Suite | 'else' ('if' | 'unless') E Suite + + enum class ElseType { + Else, + ElseIf, + ElseUnless, + }; + + explicit ElseState(bool /* unused */) {} + + NodeT<> condition; + NodeT body; + ElseType type = ElseType::Else; + }; + + class SwitchState final : public Node { + BASE_CORE_METHODS(SwitchState); + + // := 'switch' expr '{' SwitchCaseState* '}' + + SwitchState(NodeT<> condition) + : condition(std::move(condition)) {} + + NodeT<> condition; + NodeV cases; + }; + + class SwitchCaseState final : public Node { + BASE_CORE_METHODS(SwitchCaseState); + + // := 'case' expr Suite | 'default' Suite + + enum class CaseType { + Case, + Default, + Fallthrough, + }; + + SwitchCaseState(NodeT<> condition, NodeT body, CaseType type, token::Token marker) + : condition(std::move(condition)) + , body(std::move(body)) + , type(type) + , marker(std::move(marker)) {} + + NodeT<> condition; + NodeT body; + CaseType type; + token::Token marker; + }; + + class ImportState final : public Node { + BASE_CORE_METHODS(ImportState); + }; + + class SingleImportState final : public Node { + BASE_CORE_METHODS(SingleImportState); + }; + + class MultiImportState final : public Node { + BASE_CORE_METHODS(MultiImportState); + }; + + class AliasState final : public Node { + BASE_CORE_METHODS(AliasState); + }; + + class YieldState final : public Node { + BASE_CORE_METHODS(YieldState); + + // := 'yield' expr ';' + + explicit YieldState(NodeT<> value) + : value(std::move(value)) {} + + NodeT<> value; + }; + + class DeleteState final : public Node { + BASE_CORE_METHODS(DeleteState); + + // := 'yield' expr ';' + + explicit DeleteState(NodeT<> value) + : value(std::move(value)) {} + + NodeT<> value; + }; + + class ReturnState final : public Node { + BASE_CORE_METHODS(ReturnState); + + // := 'return' expr ';' + + explicit ReturnState(NodeT<> value) + : value(std::move(value)) {} + + NodeT<> value; + }; + + class BreakState final : public Node { + BASE_CORE_METHODS(BreakState); + + // := 'break' ';' + + explicit BreakState(token::Token marker) + : marker(std::move(marker)) {} + + token::Token marker; + }; + + class ContinueState final : public Node { + BASE_CORE_METHODS(ContinueState); + + // := 'continue' ';' + + explicit ContinueState(token::Token marker) + : marker(std::move(marker)) {} + + token::Token marker; + }; + + class ExprState final : public Node { + BASE_CORE_METHODS(ExprState); + + // := expr ';' + + explicit ExprState(NodeT<> value) + : value(std::move(value)) {} + + NodeT<> value; + }; + + class BlockState final : public Node { + BASE_CORE_METHODS(BlockState); + + // := '{' Statement* '}' + + explicit BlockState(NodeV<> body) + : body(std::move(body)) {} + + NodeV<> body; + }; + + class SuiteState final : public Node { + BASE_CORE_METHODS(SuiteState); + + // := BlockState | (':' Statement) + // the suite parser will either make a block node if theres a { or a single statement with + // the : + + explicit SuiteState(NodeT body) + : body(std::move(body)) {} + + NodeT body; + }; + + class CatchState final : public Node { + BASE_CORE_METHODS(CatchState); + + // := 'catch' (NamedVarSpecifier ((',' NamedVarSpecifier)*)?)? SuiteState (CatchState | + // FinallyState)? + + CatchState(NodeT catch_state, NodeT body) + : catch_state(std::move(catch_state)) + , body(std::move(body)) {} + + NodeT catch_state; + NodeT body; + }; + + class FinallyState final : public Node { + BASE_CORE_METHODS(FinallyState); + + // := 'finally' SuiteState + + explicit FinallyState(NodeT body) + : body(std::move(body)) {} + + NodeT body; + }; + + class TryState final : public Node { + BASE_CORE_METHODS(TryState); + + // := 'try' SuiteState (CatchState*) (FinallyState)? + + explicit TryState(NodeT body) + : body(std::move(body)) {} + + TryState(NodeT body, + NodeV catch_states, + NodeT finally_state = nullptr) + : body(std::move(body)) + , catch_states(std::move(catch_states)) + , finally_state(std::move(finally_state)) {} + + NodeT body; + NodeV catch_states; + NodeT finally_state; + + bool no_catch; + }; + + class PanicState final : public Node { + BASE_CORE_METHODS(PanicState); + + // := 'panic' E ';' + + explicit PanicState(NodeT<> expr) + : expr(std::move(expr)) {} + + NodeT<> expr; + }; + +} // namespace __AST_NODE_BEGIN + +#endif // __AST_STATEMENTS_H__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/AST_expressions.def b/source/parser/ast/include/nodes/AST_expressions.def deleted file mode 100644 index 7d6d455..0000000 --- a/source/parser/ast/include/nodes/AST_expressions.def +++ /dev/null @@ -1,83 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __AST_EXPRESSIONS_DEF__ -#define __AST_EXPRESSIONS_DEF__ - -#include "parser/ast/include/AST_types.hh" - -// Expression ::= BinaryOp | UnaryOp | Literal | Identifier | DotAccess | ScopeAccess | -// FunctionCall | ArrayAccess | Cast | Conditional | Parenthesized | PathAccess | -// TODO: List | Tuple | Map | Match | Range | Lambda | - -#define EXPRESSION(GENERATE, DERIVE) \ - GENERATE(BinaryOp, DERIVE, \ - NodeT left; \ - token::Token op; \ - NodeT right; \ - ) \ - \ - GENERATE(UnaryOp, DERIVE, \ - token::Token op; \ - NodeT right; \ - ) \ - \ - GENERATE(Literal, DERIVE, \ - token::Token value; \ - ) \ - \ - GENERATE(Identifier, DERIVE, \ - token::Token value; \ - ) \ - \ - GENERATE(DotAccess, DERIVE, \ - NodeV paths; \ - ) \ - \ - GENERATE(ScopeAccess, DERIVE, \ - NodeV paths; \ - ) \ - \ - GENERATE(PathAccess, DERIVE, \ - NodeV paths; \ - ) \ - \ - GENERATE(FunctionCall, DERIVE, \ - NodeT callee; \ - NodeV args; \ - NodeV defaults; \ - ) \ - \ - GENERATE(ArrayAccess, DERIVE, \ - NodeT array; \ - NodeT index; \ - ) \ - \ - GENERATE(Parenthesized, DERIVE, \ - NodeT expr; \ - ) \ - \ - GENERATE(Conditional, DERIVE, \ - NodeT condition; \ - NodeT if_true; \ - NodeT if_false; \ - ) \ - \ - GENERATE(Cast, DERIVE, \ - NodeT type; \ - NodeT expr; \ - ) - -#endif // __AST_EXPRESSIONS_DEF__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/AST_generics.def b/source/parser/ast/include/nodes/AST_generics.def deleted file mode 100644 index 7cc3583..0000000 --- a/source/parser/ast/include/nodes/AST_generics.def +++ /dev/null @@ -1,24 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __AST_GENERIC_DEF__ -#define __AST_GENERIC_DEF__ - -#define GENERICS(GENERATE, DERIVE) \ - GENERATE(Suite, DERIVE, \ - NodeV<> body; \ - ) \ - -#endif // __AST_GENERIC_DEF__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/AST_statements.def b/source/parser/ast/include/nodes/AST_statements.def deleted file mode 100644 index 64410d8..0000000 --- a/source/parser/ast/include/nodes/AST_statements.def +++ /dev/null @@ -1,102 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// @author @mbambav // -// @brief This file defines the AST Statements Parser, which is used to parse statements in the // -// // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __AST_STATEMENTS_DEF__ -#define __AST_STATEMENTS_DEF__ - -#include "parser/ast/include/nodes/modifiers.hh" - -#define STATEMENTS(GENERATE, DERIVE) \ - GENERATE(Assignment, DERIVE, \ - NodeT name; \ - NodeT value; \ - ) \ - \ - GENERATE(ForLoop, DERIVE, \ - NodeT<> initialization; \ - NodeT condition; \ - NodeT incrementor;\ - NodeT body; \ - ) \ - \ - GENERATE(RangeLoop, DERIVE, \ - NodeT variable; \ - NodeT iterable; \ - NodeT body; \ - ) \ - \ - GENERATE(WhileLoop, DERIVE, \ - NodeT condition; \ - NodeT body; \ - ) \ - \ - GENERATE(IfStatement, DERIVE, \ - NodeT condition; \ - NodeT body; \ - ) \ - \ - GENERATE(ElseIfStatement, DERIVE, \ - NodeT condition; \ - NodeT body; \ - ) \ - \ - GENERATE(ElseStatement, DERIVE, \ - NodeT body; \ - ) \ - \ - \ - GENERATE(ConditionalStatement, DERIVE, \ - NodeT if_statement; \ - NodeT else_if_statement; \ - NodeT else_statement; \ - ) \ - \ - GENERATE(ReturnStatement, DERIVE, \ - NodeT value; \ - ) \ - \ - GENERATE(ContinueStatement, DERIVE, \ - bool is_true = true; \ - ) \ - \ - GENERATE(BreakStatement, DERIVE, \ - bool is_true = true; \ - ) \ - \ - GENERATE(YieldStatement, DERIVE, \ - NodeT value; \ - ) - - -#endif // __AST_STATEMENTS_DEF__ - -/* TODO: add in v0.0.4 -GENERATE(SwitchStatement, DERIVE, \ - NodeT variable; \ - \ -) \ -GENERATE(CaseStatement, DERIVE, \ - NodeT _case; \ - NodeT<> body; \ -) \ -GENERATE(DefaultCaseStatement, DERIVE, \ - NodeT<> body; \ -) \ -GENERATE(MatchExpression, DERIVE, \ - NodeT _case; \ -) \ -*/ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/archive/decl_nodes.hpp b/source/parser/ast/include/nodes/archive/decl_nodes.hpp deleted file mode 100644 index fc2c61b..0000000 --- a/source/parser/ast/include/nodes/archive/decl_nodes.hpp +++ /dev/null @@ -1,122 +0,0 @@ -// -*- C++ -*- -//===------------------------------------------------------------------------------------------===// -// -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). -// You are allowed to use, modify, redistribute, and create derivative works, even for commercial -// purposes, provided that you give appropriate credit, and indicate if changes were made. -// For more information, please visit: https://creativecommons.org/licenses/by/4.0/ -// -// SPDX-License-Identifier: CC-BY-4.0 -// Copyright (c) 2024 (CC BY 4.0) -// -//===------------------------------------------------------------------------------------------===// - -#ifndef __AST_DECL_NODES_HH__ -#define __AST_DECL_NODES_HH__ - -#include "parser/ast/include/ast.hh" -#include "parser/ast/include/nodes/nodes.hh" - -__AST_BEGIN::node { -using namespace token; - -// Functions and Methods -class FunctionDecl final : public Declaration { - AST_NODE_METHODS(FunctionDecl); - NodePtr name; - NodeList params; - NodeList kw_params; - NodePtr return_ty; - NodePtr generics; - NodePtr body; -}; - -// untouched beyond this point. - -class FunctionDefinition final : public Declaration { - AST_NODE_METHODS(FunctionDefinition); - bool isUnsafe = false; - NodePtr baseObject; - NodePtr functionDecl; - - NodePtr suite; -}; - -class OperatorDefinition final : public Declaration { - AST_NODE_METHODS(OperatorDefinition); - Token op; - NodePtr functionDecl; - NodePtr suite; -}; - -// Class and class -class ClassDefinition final : public Declaration { - AST_NODE_METHODS(ClassDefinition); - NodePtr baseObject; - NodePtr name; - NodePtr derives; - NodePtr _requires; - NodePtr suite; -}; - -class EnumDefinition final : public Declaration { - AST_NODE_METHODS(EnumDefinition); - NodePtr baseObject; - NodePtr name; - NodePtr body; -}; - -class classDefinition final : public Declaration { - AST_NODE_METHODS(classDefinition); - NodePtr baseObject; - NodePtr _requires; - NodePtr suite; -}; - -class UnionDefinition final : public Declaration { - AST_NODE_METHODS(UnionDefinition); - NodePtr baseObject; - NodePtr _requires; - NodePtr body; -}; - -class TypeDefinition final : public Declaration { - AST_NODE_METHODS(TypeDefinition); - NodePtr baseObject; - NodePtr name; - NodePtr _requires; - NodePtr type; -}; - -// Inheritance and Polymorphism -class AbstractDefinition final : public Declaration { - AST_NODE_METHODS(AbstractDefinition); - NodePtr baseObject; - NodePtr name; - NodePtr derives; - NodePtr _requires; - NodePtr suite; -}; - -class InterfaceDefinition final : public Declaration { - AST_NODE_METHODS(InterfaceDefinition); - NodePtr baseObject; - NodePtr name; - NodePtr derives; - NodePtr _requires; - NodePtr suite; -}; - -// Variable Declarations -class VariableDeclaration final : public Declaration { - AST_NODE_METHODS(VariableDeclaration); - NodePtr accessModifiers; - bool isUnsafe = false; - Token qualifier; // const, atomic, shared, eval - NodePtr<> parameter; // TypedParameter or UntypedParameter - NodePtr initializer; -}; - -} // namespace __AST_BEGIN::node - -#endif // __AST_DECL_NODES_HH__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/archive/expr_nodes.hpp b/source/parser/ast/include/nodes/archive/expr_nodes.hpp deleted file mode 100644 index 63e4431..0000000 --- a/source/parser/ast/include/nodes/archive/expr_nodes.hpp +++ /dev/null @@ -1,199 +0,0 @@ -// -*- C++ -*- -//===------------------------------------------------------------------------------------------===// -// -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). -// You are allowed to use, modify, redistribute, and create derivative works, even for commercial -// purposes, provided that you give appropriate credit, and indicate if changes were made. -// For more information, please visit: https://creativecommons.org/licenses/by/4.0/ -// -// SPDX-License-Identifier: CC-BY-4.0 -// Copyright (c) 2024 (CC BY 4.0) -// -//===------------------------------------------------------------------------------------------===// - -#ifndef __AST_EXPR_NODES_HH__ -#define __AST_EXPR_NODES_HH__ - -#include -#include "parser/ast/include/ast.hh" -#include "parser/ast/include/nodes/nodes.hh" -#include "token/include/token_list.hh" - -namespace parser::ast::node { -using namespace token; -// Control Flow -class MatchExpression final : public Expression { - AST_NODE_METHODS(MatchExpression); - NodeList, NodePtr<>>> - cases; // (Expression | '_') -> (CodeBlock | (':' Expression)) -}; - -// Functions and Methods -class ReturnExpression final : public Expression { - AST_NODE_METHODS(ReturnExpression); - NodePtr expression; -}; - -class YieldExpression final : public Expression { - AST_NODE_METHODS(YieldExpression); - NodePtr expression; -}; - -// Operators -class BinaryOperation final : public Expression { - AST_NODE_METHODS(BinaryOperation); - NodePtr left; - NodePtr op; - NodePtr right; -}; - -class UnaryOperation final : public Expression { - AST_NODE_METHODS(UnaryOperation); - NodePtr op; - NodePtr expression; -}; - -// Expressions -class FunctionCall final : public Expression { - AST_NODE_METHODS(FunctionCall); - NodePtr function; - NodePtr genericAccess; - NodeList arguments; -}; - -class ParenthesizedExpression final : public Expression { - AST_NODE_METHODS(ParenthesizedExpression); - NodePtr expression; -}; - -class ArrayAccess final : public Expression { - AST_NODE_METHODS(ArrayAccess); - NodePtr array; - NodePtr index; -}; - -class ObjectAccess final : public Expression { - AST_NODE_METHODS(ObjectAccess); - NodePtr object; - NodePtr member; -}; - -class ConditionalExpression final : public Expression { - AST_NODE_METHODS(ConditionalExpression); - NodePtr condition; - NodePtr trueExpression; - NodePtr falseExpression; -}; - -// Base Elements -class Literal final : public Expression { - public: - enum class LiteralType : u8 { INVALID, BOOL, CHAR, FLOAT, STRING, INTEGER, SCIENTIFIC, NONE }; - - AST_NODE_METHODS(Literal); - LiteralType type = LiteralType::INVALID; - Token value; - - TO_JSON_SIGNATURE { - jsonify::Jsonify node_json(node_repr(), depth); - - switch (type) { - case LiteralType::INVALID: - node_json.add("type", std::string("INVALID")); - break; - case LiteralType::BOOL: - node_json.add("type", std::string("BOOL")); - break; - case LiteralType::CHAR: - node_json.add("type", std::string("CHAR")); - break; - case LiteralType::FLOAT: - node_json.add("type", std::string("FLOAT")); - break; - case LiteralType::STRING: - node_json.add("type", std::string("STRING")); - break; - case LiteralType::INTEGER: - node_json.add("type", std::string("INTEGER")); - break; - case LiteralType::SCIENTIFIC: - node_json.add("type", std::string("SCIENTIFIC")); - break; - case LiteralType::NONE: - node_json.add("type", std::string("NONE")); - break; - } - - node_json.add("value", value); - - TO_JSON_RETURN(node_json); - } -}; - -class Identifier final : public Expression { - AST_NODE_METHODS(Identifier); - Token value; - - TO_JSON_SIGNATURE { - jsonify::Jsonify node_json(node_repr(), depth); - - node_json.add("value", value); - - TO_JSON_RETURN(node_json); - } -}; - -class AnySeparatedID final : public Expression { - AST_NODE_METHODS(AnySeparatedID); - NodeList identifiers; // Can be a mix of DotSeparatedID or QualifiedNamespaceID - - TO_JSON_SIGNATURE { - jsonify::Jsonify node_json(node_repr(), depth); - - - node_json.add("path", "none"); - - TO_JSON_RETURN(node_json); - } -}; - -class QualifiedNamespaceID final : public Expression { // PATH so id::id::id... - AST_NODE_METHODS(QualifiedNamespaceID); - NodeList identifiers; // id::id::id... - - TO_JSON_SIGNATURE { - jsonify::Jsonify node_json(node_repr(), depth); - - std::vector temp_de_ref; - - for (auto &_ : identifiers) { - temp_de_ref.push_back(*_); - } - - node_json.add("path", temp_de_ref); - - TO_JSON_RETURN(node_json); - } -}; - -class DotSeparatedID final : public Expression { // PATH so id::id::id... - AST_NODE_METHODS(DotSeparatedID); - NodeList identifiers; // id.id.id... - - TO_JSON_SIGNATURE { - jsonify::Jsonify node_json(node_repr(), depth); - - std::vector temp_de_ref; - - for (auto &_ : identifiers) { - temp_de_ref.push_back(*_); - } - - node_json.add("path", temp_de_ref); - - TO_JSON_RETURN(node_json); - } -}; -} // namespace __AST_BEGIN::node - -#endif // __AST_EXPR_NODES_HH__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/archive/nodes.hpp b/source/parser/ast/include/nodes/archive/nodes.hpp deleted file mode 100644 index fd959da..0000000 --- a/source/parser/ast/include/nodes/archive/nodes.hpp +++ /dev/null @@ -1,262 +0,0 @@ -// -*- C++ -*- -//===------------------------------------------------------------------------------------------===// -// -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). -// You are allowed to use, modify, redistribute, and create derivative works, even for commercial -// purposes, provided that you give appropriate credit, and indicate if changes were made. -// For more information, please visit: https://creativecommons.org/licenses/by/4.0/ -// -// SPDX-License-Identifier: CC-BY-4.0 -// Copyright (c) 2024 (CC BY 4.0) -// -//===------------------------------------------------------------------------------------------===// - -#ifndef __AST_NODES_HH__ -#define __AST_NODES_HH__ - -#include "parser/ast/include/ast.hh" - -namespace parser::ast::node { -using namespace token; - -class UntypedParameter; -class TypedParameter; -class AnySeparatedID; -class QualifiedNamespaceID; -class Suite; -class Identifier; -class DefaultArgument; -class BaseObjectDecl; -class RequiresDeclaration; -class AccessModifiers; -class DerivesDecl; -class EnumBody; -class UnionBody; - -// Main Program Structure -class Program final : public ASTBase { - AST_NODE_METHODS(Program); - NodeList> statements; -}; - -// Modules and Imports -class Module final : public ASTBase { - AST_NODE_METHODS(Module); - NodePtr namespaceID; - NodePtr suite; -}; - -class ImportStatement final : public ASTBase { - AST_NODE_METHODS(ImportStatement); - NodePtr namespaceID; - NodeList importList; - NodePtr alias; -}; - -class FFIImportStatement final : public ASTBase { - AST_NODE_METHODS(FFIImportStatement); - Token ffiString; - NodePtr importStatement; -}; - -// Class and Struct -class BaseObjectDecl : public ASTBase { - AST_NODE_METHODS(BaseObjectDecl); - NodePtr accessModifiers; - Token qualifier; // inline, async, static, eval, const, ffi -}; - -class EnumBody final : public ASTBase { - AST_NODE_METHODS(EnumBody); - NodeList> parameters; // TypedParameter or UntypedParameter with optional Expression -}; - -class UnionBody final : public ASTBase { - AST_NODE_METHODS(UnionBody); - NodeList> parameters; // TypedParameter or UntypedParameter -}; - -// Inheritance and Polymorphism -class DerivesDecl final : public ASTBase { - AST_NODE_METHODS(DerivesDecl); - NodeList baseClasses; -}; - -class TypeBound final : public ASTBase { - AST_NODE_METHODS(TypeBound); - NodePtr parameter; - NodeList bounds; -}; - -class GenericType final : public ASTBase { - AST_NODE_METHODS(GenericType); - bool isEval = false; - NodePtr<> parameter; // TypedParameter or UntypedParameter - NodePtr expression; -}; - -class RequiresDeclaration final : public ASTBase { - AST_NODE_METHODS(RequiresDeclaration); - NodeList genericTypes; - NodeList typeBounds; -}; - -// Error Handling -class CatchDefinition final : public ASTBase { - AST_NODE_METHODS(CatchDefinition); - NodePtr identifier; - NodePtr alias; - NodePtr suite; -}; - -class FinallyDefinition final : public ASTBase { - AST_NODE_METHODS(FinallyDefinition); - NodePtr suite; -}; - -class PanicDefinition final : public ASTBase { - AST_NODE_METHODS(PanicDefinition); - NodePtr expression; -}; - -class TryDefinition final : public ASTBase { - AST_NODE_METHODS(TryDefinition); - NodePtr suite; - NodePtr catchBlock; - NodePtr finallyBlock; -}; - -class TestDefinition final : public ASTBase { - AST_NODE_METHODS(TestDefinition); - Token testName; - NodePtr suite; -}; - -// Access Specifiers -class AccessModifiers final : public ASTBase { - AST_NODE_METHODS(AccessModifiers); - Token modifier; // priv, pub, prot, intl -}; - -// Concurrency -class AwaitCall final : public ASTBase { - AST_NODE_METHODS(AwaitCall); - NodePtr expression; -}; - -class SpawnCall final : public ASTBase { - AST_NODE_METHODS(SpawnCall); - NodePtr expression; -}; - -class ThreadCall final : public ASTBase { - AST_NODE_METHODS(ThreadCall); - NodePtr expression; -}; - -// Other -class DeleteCall final : public ASTBase { - AST_NODE_METHODS(DeleteCall); - NodePtr expression; -}; - -// Type Definitions -class GenericAccess final : public ASTBase { - AST_NODE_METHODS(GenericAccess); - NodeList> identifiers; // QualifiedNamespaceIDOrLiteral -}; - -// Operators -class Operator final : public ASTBase { - AST_NODE_METHODS(Operator); - Token op; -}; - -class Expressions final : public ASTBase { - AST_NODE_METHODS(Expressions); - NodeList expressions; -}; - -class Statements final : public ASTBase { - AST_NODE_METHODS(Statements); - NodeList statements; -}; - -// Code Structure -class CodeBlock final : public ASTBase { - AST_NODE_METHODS(CodeBlock); - NodeList> statementsOrExpressions; -}; - -class CodeLine final : public ASTBase { - AST_NODE_METHODS(CodeLine); - NodePtr<> statementOrExpression; -}; - -class UntypedParameter final : public ASTBase { - AST_NODE_METHODS(UntypedParameter); - NodePtr identifier; -}; - -class TypedParameter final : public ASTBase { - AST_NODE_METHODS(TypedParameter); - NodePtr identifier; - NodePtr type; -}; - -class Suite final : public ASTBase { - AST_NODE_METHODS(Suite); - NodePtr<> content; // Either CodeLine or CodeBlock -}; - -// Default Argument -class DefaultArgument final : public ASTBase { - AST_NODE_METHODS(DefaultArgument); - NodePtr parameter; - NodePtr expression; -}; - -// Helper Functions -class UntypedParameterList final : public ASTBase { - AST_NODE_METHODS(UntypedParameterList); - NodeList parameters; -}; - -class TypedParameterList final : public ASTBase { - AST_NODE_METHODS(TypedParameterList); - NodeList parameters; -}; - -class DefaultArgumentList final : public ASTBase { - AST_NODE_METHODS(DefaultArgumentList); - NodeList arguments; -}; - -class GenericTypeList final : public ASTBase { - AST_NODE_METHODS(GenericTypeList); - NodeList types; -}; - -class TypeBoundList final : public ASTBase { - AST_NODE_METHODS(TypeBoundList); - NodeList bounds; -}; - -class QualifiedNamespaceIDOrLiteralList final : public ASTBase { - AST_NODE_METHODS(QualifiedNamespaceIDOrLiteralList); - NodeList> identifiersOrLiterals; // QualifiedNamespaceID or Literal -}; - -class TypeList final : public ASTBase { - AST_NODE_METHODS(TypeList); - NodeList types; -}; - -class ExpressionList final : public ASTBase { - AST_NODE_METHODS(ExpressionList); - NodeList expressions; -}; - -} // namespace __AST_BEGIN::node - -#endif // __AST_NODES_HH__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/archive/state_nodes.hpp b/source/parser/ast/include/nodes/archive/state_nodes.hpp deleted file mode 100644 index fa80fbd..0000000 --- a/source/parser/ast/include/nodes/archive/state_nodes.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// -*- C++ -*- -//===------------------------------------------------------------------------------------------===// -// -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). -// You are allowed to use, modify, redistribute, and create derivative works, even for commercial -// purposes, provided that you give appropriate credit, and indicate if changes were made. -// For more information, please visit: https://creativecommons.org/licenses/by/4.0/ -// -// SPDX-License-Identifier: CC-BY-4.0 -// Copyright (c) 2024 (CC BY 4.0) -// -//===------------------------------------------------------------------------------------------===// - -#ifndef __AST_STATE_NODES_HH__ -#define __AST_STATE_NODES_HH__ - -#include "parser/ast/include/ast.hh" -#include "parser/ast/include/nodes/nodes.hh" - -namespace parser::ast::node { -using namespace token; - -// Control Flow -class ForLoop final : public Statement { - AST_NODE_METHODS(ForLoop); - NodePtr<> loopType; // Either CStyleForLoop or PyStyleForLoop - NodePtr suite; -}; - -class WhileLoop final : public Statement { - AST_NODE_METHODS(WhileLoop); - NodePtr condition; - NodePtr suite; -}; - -class IfStatement final : public Statement { - AST_NODE_METHODS(IfStatement); - NodePtr condition; - NodePtr suite; -}; - -class ElseIfStatement final : public Statement { - AST_NODE_METHODS(ElseIfStatement); - NodePtr condition; - NodePtr suite; -}; - -class ElseStatement final : public Statement { - AST_NODE_METHODS(ElseStatement); - NodePtr suite; -}; - -class ContinueStatement final : public Statement { - AST_NODE_METHODS(ContinueStatement); -}; - -class BreakStatement final : public Statement { - AST_NODE_METHODS(BreakStatement); -}; - -class SwitchStatement final : public Statement { - AST_NODE_METHODS(SwitchStatement); - NodeList> cases; // CaseStatement or DefaultCaseStatement -}; - -class CaseStatement final : public Statement { - AST_NODE_METHODS(CaseStatement); - NodePtr condition; - NodePtr suite; -}; - -class DefaultCaseStatement final : public Statement { - AST_NODE_METHODS(DefaultCaseStatement); - NodePtr suite; -}; - -// Statements -class Assignment final : public Statement { - AST_NODE_METHODS(Assignment); - NodePtr variable; - NodePtr expression; -}; - -class BlockStatement final : public Statement { - AST_NODE_METHODS(BlockStatement); - NodePtr suite; -}; -} // namespace __AST_BEGIN::node - -#endif // __AST_STATE_NODES_HH__ \ No newline at end of file diff --git a/source/parser/ast/include/nodes/modifiers.hh b/source/parser/ast/include/nodes/modifiers.hh deleted file mode 100644 index d6244d0..0000000 --- a/source/parser/ast/include/nodes/modifiers.hh +++ /dev/null @@ -1,72 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// @author @ze71111 // -// // -//===-----------------------------------------------------------------------------------------====// - -#ifndef __MODIFIERS_H__ -#define __MODIFIERS_H__ - -#include "clang/AST/ASTTypeTraits.h" -#include "parser/ast/include/AST_core.def" -__AST_BEGIN { - enum class StorageSpecifier : char { - Static, ///< 'static' - FFI, ///< 'ffi' - /* TODO */ ThreadLocal, ///< 'thread_local' - /* TODO */ Mutable, ///< 'mutable' - }; - - enum class TypeQualifier : char { - Const, ///< 'const' - Volatile, ///< 'volatile' - /* TODO */ Atomic, ///< 'atomic' - /* TODO */ Mutable, ///< 'mutable' - }; - - enum class AccessSpecifier : char { - Public, ///< 'pub' - default = exposed by linkage and visibility - Private, ///< 'priv' = not exposed by linkage and visibility - Protected, ///< 'prot' = not exposed by linkage but by visibility - /* TODO */ Internal ///< 'internal' = exposed by linkage but not visibility - }; - - enum class FunctionSpecifier : char { - Inline, ///< 'inline' - Abstract, ///< 'abstract' - Const, ///< 'const' - in functions this is 'const' but for classes its 'final' - Override, ///< '#[override]' - compiler directive - Eval ///< 'eval' - eval in the case of functions default to 'constinit' for - /// 'constexpr' or 'consteval' use 'const eval' - - /// ONLY the following are allowed in UDTs (User Defined Types): - /// 'const' - }; - - enum class FunctionQualifier : char { - NoExcept, ///< 'noexcept' - Abstract, ///< 'abstract' - Default, ///< 'default' - Delete, ///< 'delete' - /* TODO */ Const, ///< 'const' - /* TODO */ Override ///< 'override' - - /// ONLY allowed in the scope of a UDT: - /// 'const' - /// 'abstract' - /// 'override' - }; -} - - -#endif // __MODIFIERS_H__ \ No newline at end of file diff --git a/source/parser/ast/source/declarations/Declaration.cc b/source/parser/ast/include/types/AST_jsonify_visitor.hh similarity index 51% rename from source/parser/ast/source/declarations/Declaration.cc rename to source/parser/ast/include/types/AST_jsonify_visitor.hh index b5224e9..de4f5a3 100644 --- a/source/parser/ast/source/declarations/Declaration.cc +++ b/source/parser/ast/include/types/AST_jsonify_visitor.hh @@ -9,25 +9,41 @@ // Copyright (c) 2024 (CC BY 4.0) // // // //====----------------------------------------------------------------------------------------====// -// // -// // -//===-----------------------------------------------------------------------------------------====// -#include "parser/ast/include/AST.hh" +#ifndef __AST_JSONIFY_VISIT_H__ +#define __AST_JSONIFY_VISIT_H__ -#include "parser/ast/include/case_types.def" -#include "token/include/token_list.hh" +#include "neo-json/include/json.hh" +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/nodes/AST_Nodes.hh" +#include "parser/ast/include/types/AST_types.hh" +#include "parser/ast/include/types/AST_visitor.hh" -namespace parser::ast { +__AST_VISITOR_BEGIN { + class Jsonify : public Visitor { + public: + Jsonify() = default; + Jsonify(const Jsonify &) = default; + Jsonify(Jsonify &&) = delete; + Jsonify &operator=(const Jsonify &) = default; + Jsonify &operator=(Jsonify &&) = delete; + ~Jsonify() override = default; -NodeT get_Declaration(token::TokenList &tokens) { - for (auto &token : tokens) {} + neo::json json{"ast"}; - return nullptr; -} + GENERATE_VISIT_EXTENDS; + }; -Declaration::Declaration() = default; -Declaration::Declaration(token::TokenList &tokens) - : Node(tokens) - , tokens(&tokens) {} + inline neo::json get_node_json(const NodeT<> &node) { + auto visitor = Jsonify(); + + if (node == nullptr) { + return neo::json("nullptr"); + } + + node->accept(visitor); + return visitor.json; + } } // namespace __AST_BEGIN + +#endif // __AST_JSONIFY_VISIT_H__ \ No newline at end of file diff --git a/source/parser/ast/include/types/AST_parse_error.hh b/source/parser/ast/include/types/AST_parse_error.hh new file mode 100644 index 0000000..441314d --- /dev/null +++ b/source/parser/ast/include/types/AST_parse_error.hh @@ -0,0 +1,62 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // +// You are allowed to use, modify, redistribute, and create derivative works, even for // +// commercial purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// + +#ifndef __AST_PARSE_ERROR_H__ +#define __AST_PARSE_ERROR_H__ + +#include +#include + +#include "neo-panic/include/error.hh" +#include "parser/ast/include/config/AST_config.def" +#include "token/include/token.hh" + +__AST_BEGIN { + class ParseError { + token::Token err; + token::Token expected; + std::string msg; + + public: + ParseError() = default; + ~ParseError() = default; + ParseError(const ParseError &) = default; + ParseError &operator=(const ParseError &) = default; + ParseError(ParseError &&) = default; + ParseError &operator=(ParseError &&) = default; + + ParseError(const token::Token &err, const token::Token &expected) + : err(err) + , expected(expected) { + + this->msg = "expected '" + expected.value() + "' but found '" + err.value() + "'"; + } + + ParseError(token::Token err, std::string msg) + : err(std::move(err)) + , msg(std::move(msg)) {} + + explicit ParseError(std::string msg) + : msg(std::move(msg)) {} + + [[nodiscard]] std::string what() const { return msg; } + void panic() const { + error::Panic(error::CodeError{ + .pof = const_cast(&err), + .err_code = 0.0001, + .mark_pof = true, + }); + } + }; +} // namespace __AST_BEGIN + +#endif // __AST_PARSE_ERROR_H__ \ No newline at end of file diff --git a/source/parser/ast/include/types/AST_types.hh b/source/parser/ast/include/types/AST_types.hh new file mode 100644 index 0000000..5f20650 --- /dev/null +++ b/source/parser/ast/include/types/AST_types.hh @@ -0,0 +1,69 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). You // +// are allowed to use, modify, redistribute, and create derivative works, even for commercial // +// purposes, provided that you give appropriate credit, and indicate if changes were made. // +// For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +///====--------------------------------------------------------------------------------------====/// +/// /// +/// @file AST_types.hh /// +/// @brief Defines common types for Abstract Syntax Tree (AST) nodes used throughout the Helix /// +/// project. This includes types for nodes, parse results, and helpers for creating AST /// +/// nodes. /// +/// /// +/// This file provides types and helper functions used in the construction and management of /// +/// AST nodes within the Helix parser. It defines `NodeT`, a template for handling AST /// +/// nodes, `ParseResult`, for handling parsing results (either a node or an error), and /// +/// `NodeV`, a vector of AST nodes. Additionally, a `make_node` function is provided for /// +/// creating new AST nodes with perfect forwarding of arguments. /// +/// /// +/// @code /// +/// NodeT node = make_node(token, type); /// +/// NodeV<> nodes = {node}; /// +/// @endcode /// +/// /// +///===---------------------------------------------------------------------------------------====/// + +#ifndef __AST_TYPES_H__ +#define __AST_TYPES_H__ + +#include +#include +#include + +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/types/AST_parse_error.hh" +#include "token/include/token.hh" + +__AST_NODE_BEGIN { class Node; } + +__AST_BEGIN { + /// NodeT is a unique pointer to a T (where T is a AST node) + template + using NodeT = std::shared_ptr; + + template // either a node or a parse error + using ParseResult = std::expected, ParseError>; + + /// NodeV is a vector of NodeT + template + using NodeV = std::vector>; + + /// make_node is a helper function to create a new node with perfect forwarding + /// @tparam T is the type of the node + /// @param args are the arguments to pass to the constructor of T + /// @return a unique pointer to the new node + template + inline constexpr NodeT make_node(Args && ...args) { + // return a heap-alloc unique pointer to the new node with + // perfect forwarding of the arguments allowing the caller + // to identify any errors in the arguments at compile time + return std::make_shared(std::forward(args)...); + } +} // namespace __AST_BEGIN + +#endif // __AST_TYPES_H__ \ No newline at end of file diff --git a/source/parser/ast/source/expressions/AST_ArrayAccess.cc b/source/parser/ast/include/types/AST_visitor.hh similarity index 66% rename from source/parser/ast/source/expressions/AST_ArrayAccess.cc rename to source/parser/ast/include/types/AST_visitor.hh index 89a8e2b..8d50c0c 100644 --- a/source/parser/ast/source/expressions/AST_ArrayAccess.cc +++ b/source/parser/ast/include/types/AST_visitor.hh @@ -10,24 +10,23 @@ // // //====----------------------------------------------------------------------------------------====// -#include "parser/ast/include/AST.hh" +#ifndef __AST_VISITOR_H__ +#define __AST_VISITOR_H__ -namespace parser::ast::node { -ParseResult ArrayAccess::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } +#include "parser/ast/include/config/AST_generate.hh" - return 0; -} +__AST_VISITOR_BEGIN { + class Visitor { + public: + Visitor() = default; + Visitor(const Visitor &) = default; + Visitor &operator=(const Visitor &) = default; + Visitor(Visitor &&) = default; + Visitor &operator=(Visitor &&) = default; + virtual ~Visitor() = default; -bool ArrayAccess::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; + GENERATE_VISIT_FUNCS; + }; } -void ArrayAccess::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node +#endif // __AST_VISITOR_H__ \ No newline at end of file diff --git a/source/parser/ast/source/AST_Jsonify.cc b/source/parser/ast/source/AST_Jsonify.cc deleted file mode 100644 index 80d162a..0000000 --- a/source/parser/ast/source/AST_Jsonify.cc +++ /dev/null @@ -1,162 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// This file defines the JsonifyVisitor class, which is used to convert the AST to JSON. // -// The JSON representation of the AST is used for debugging and testing purposes. // -// // -//===-----------------------------------------------------------------------------------------====// - -#include -#include - -#include "parser/ast/include/AST_core.def" -#include "parser/ast/include/AST_jsonify_visitor.hh" - -__AST_BEGIN::visitors { -neo::json get_node_json(const Node *node) { - auto visitor = JsonifyVisitor(); - node->accept(visitor); - return visitor.json; -} - -void JsonifyVisitor::visit(const node::Literal &node) { - json.section("literal") - .add("value", node.value) - .add("type", (int)node.getNodeType()); -}; - -void JsonifyVisitor::visit(const node ::Comment &node) {} - -void JsonifyVisitor::visit(const node ::CompilerDirective &node) {} - -void JsonifyVisitor::visit(const node ::Suite &node) {} - -void JsonifyVisitor::visit(const node ::VariableDecl &node) {} - -void JsonifyVisitor::visit(const node ::Assignment &node) {} - -void JsonifyVisitor::visit(const node ::ForLoop &node) {} - -void JsonifyVisitor::visit(const node ::RangeLoop &node) {} - -void JsonifyVisitor::visit(const node ::WhileLoop &node) {} - -void JsonifyVisitor::visit(const node ::IfStatement &node) {} - -void JsonifyVisitor::visit(const node ::ElseIfStatement &node) {} - -void JsonifyVisitor::visit(const node ::ElseStatement &node) {} - -void JsonifyVisitor::visit(const node ::ConditionalStatement &node) {} - -void JsonifyVisitor::visit(const node ::ReturnStatement &node) {} - -void JsonifyVisitor::visit(const node ::ContinueStatement &node) {} - -void JsonifyVisitor::visit(const node ::BreakStatement &node) {} - -void JsonifyVisitor::visit(const node ::YieldStatement &node) {} - -void JsonifyVisitor::visit(const node ::BinaryOp &node) { - json.section("binary_op") - .add("type", (int)node.getNodeType()) - .add("left", get_node_json(node.left)) - .add("operator", node.op) - .add("right", get_node_json(node.right)); -} - -void JsonifyVisitor::visit(const node ::UnaryOp &node) { - json.section("unary_op") - .add("operator", node.op) - .add("right", get_node_json(node.right)) - .add("type", (int)node.getNodeType()); -} - -void JsonifyVisitor::visit(const node ::Identifier &node) { - json.section("identifier") - .add("value", node.value) - .add("type", (int)node.getNodeType()); -} - -void JsonifyVisitor::visit(const node ::DotAccess &node) { - std::vector paths; - - for (auto &child : node.paths) { - paths.push_back(get_node_json(child)); - } - - json.section("dot_access") - .add("paths", paths) - .add("type", (int)node.getNodeType()); -} - -void JsonifyVisitor::visit(const node ::ScopeAccess &node) { - std::vector paths; - - for (auto &child : node.paths) { - paths.push_back(get_node_json(child)); - } - - json.section("scope_access") - .add("paths", paths) - .add("type", (int)node.getNodeType()); -} - -void JsonifyVisitor::visit(const node ::PathAccess &node) { - std::vector paths; - - for (auto &child : node.paths) { - paths.push_back(get_node_json(child)); - } - - json.section("path_access") - .add("paths", paths) - .add("type", (int)node.getNodeType()); -} -/*GENERATE(FunctionCall, DERIVE, \ - NodeT callee; \ - NodeV args; \ - NodeV defaults; \ -) */ -void JsonifyVisitor::visit(const node ::FunctionCall &node) { - std::vector args; - for (auto &arg : node.args) { - args.push_back(get_node_json(arg)); - } - - json.section("function_call") - .add("type", (int)node.getNodeType()) - .add("callee", get_node_json(node.callee)) - .add("args", args); - -} - -void JsonifyVisitor::visit(const node ::ArrayAccess &node) { - json.section("array_access") - .add("type", (int)node.getNodeType()); -} - -void JsonifyVisitor::visit(const node ::Parenthesized &node) { - json.section("parenthesized") - .add("type", (int)node.getNodeType()); -} - -void JsonifyVisitor::visit(const node ::Conditional &node) {} - -void JsonifyVisitor::visit(const node ::Cast &node) { - json.section("cast") - .add("type", (int)node.getNodeType()) - .add("cast_t", get_node_json(node.type)) - .add("expr", get_node_json(node.expr)); -} - -} // namespace __AST_BEGIN::visitors diff --git a/source/parser/ast/source/annotations/AST_CompilerDirective.cc b/source/parser/ast/source/annotations/AST_CompilerDirective.cc deleted file mode 100644 index 3590627..0000000 --- a/source/parser/ast/source/annotations/AST_CompilerDirective.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult CompilerDirective::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool CompilerDirective::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void CompilerDirective::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/annotations/Annotation.cc b/source/parser/ast/source/annotations/Annotation.cc deleted file mode 100644 index 8360a85..0000000 --- a/source/parser/ast/source/annotations/Annotation.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// // -//===-----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -#include "parser/ast/include/case_types.def" -#include "token/include/token_list.hh" - -__AST_BEGIN { - -NodeT get_Annotation(token::TokenList &tokens) { - for (auto &token : tokens) {} - - return nullptr; -} - -Annotation::Annotation() = default; -Annotation::Annotation(token::TokenList &tokens) - : Node(tokens) - , tokens(&tokens) {} -} // namespace __AST_BEGIN diff --git a/source/parser/ast/source/expressions/AST_Conditional.cc b/source/parser/ast/source/expressions/AST_Conditional.cc deleted file mode 100644 index 0b6931b..0000000 --- a/source/parser/ast/source/expressions/AST_Conditional.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult Conditional::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool Conditional::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void Conditional::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/expressions/AST_DotAccess.cc b/source/parser/ast/source/expressions/AST_DotAccess.cc deleted file mode 100644 index 949c9a1..0000000 --- a/source/parser/ast/source/expressions/AST_DotAccess.cc +++ /dev/null @@ -1,41 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -#define __HIDE_FROM_LIBHELIX__ - -namespace parser::ast::node { -ParseResult DotAccess::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - // DotAccess ::= paths ('.' paths)* - - i32 len = 0; - - paths.push_back(get_Expression(*tokens)); - - return 0; -} - -bool DotAccess::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void DotAccess::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/expressions/AST_FunctionCall.cc b/source/parser/ast/source/expressions/AST_FunctionCall.cc deleted file mode 100644 index dd99606..0000000 --- a/source/parser/ast/source/expressions/AST_FunctionCall.cc +++ /dev/null @@ -1,80 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "neo-pprint/include/hxpprint.hh" -#include "parser/ast/include/AST.hh" -#include "parser/ast/include/AST_interface.hh" -#include "token/include/token_list.hh" - -namespace parser::ast::node { -ParseResult FunctionCall::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - // FunctionCall ::= AnySeparatedID GenericAccess? '(' (ExpressionList)? ')' - // TODO: add support for generic access - - i32 len = 0; - - // Parse the function name - callee = new PathAccess(*tokens); - len += 1; - - i32 _len = 0; - - auto slice = tokens->slice(len); - tokens = &slice; - - for (auto &tok : *tokens) { - if (tok->token_kind() == token::tokens::PUNCTUATION_OPEN_PAREN) { - len += 1; - tok.advance(); - continue; - } - - if (tok->token_kind() == token::tokens::PUNCTUATION_CLOSE_PAREN) { - len += 1; - tok.advance(); - break; - } - - if (tok->token_kind() == token::tokens::PUNCTUATION_COMMA) { - len += 1; - tok.advance(); - continue; - } - - token::TokenList slice = tokens->slice(len); - token::print_tokens(slice); - auto *expr_node = get_Expression(slice); - - if (expr_node != nullptr) { - args.push_back(expr_node); - tok.advance(_len = expr_node->parse()); - len += _len; - } - } - - return len; -} - -bool FunctionCall::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void FunctionCall::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/expressions/AST_Identifier.cc b/source/parser/ast/source/expressions/AST_Identifier.cc deleted file mode 100644 index be0a9da..0000000 --- a/source/parser/ast/source/expressions/AST_Identifier.cc +++ /dev/null @@ -1,39 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult Identifier::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - if (tokens->front().token_kind() == token::IDENTIFIER) { - value = tokens->front(); - - return 1; - } - - return 0; -} - -bool Identifier::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void Identifier::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/expressions/AST_Literal.cc b/source/parser/ast/source/expressions/AST_Literal.cc deleted file mode 100644 index 89c3355..0000000 --- a/source/parser/ast/source/expressions/AST_Literal.cc +++ /dev/null @@ -1,74 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult Literal::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - switch (tokens->front().token_kind()) { - case token::LITERAL_STRING: - [[fallthrough]]; - // string concat but handle edge cases like a mix or - // r|b|u|f strings too, while maintaining the correct order and locational metadata - case token::LITERAL_TRUE: - [[fallthrough]]; - case token::LITERAL_FALSE: - [[fallthrough]]; - case token::LITERAL_INTEGER: - [[fallthrough]]; - case token::LITERAL_FLOATING_POINT: - [[fallthrough]]; - case token::LITERAL_CHAR: - [[fallthrough]]; - case token::LITERAL_NULL: - value = tokens->front(); - return 1; - default: - break; - } - - return 0; -} - -bool Literal::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - - switch (tokens->front().token_kind()) { - case token::LITERAL_STRING: - [[fallthrough]]; - case token::LITERAL_TRUE: - [[fallthrough]]; - case token::LITERAL_FALSE: - [[fallthrough]]; - case token::LITERAL_INTEGER: - [[fallthrough]]; - case token::LITERAL_FLOATING_POINT: - [[fallthrough]]; - case token::LITERAL_CHAR: - [[fallthrough]]; - case token::LITERAL_NULL: - return true; - default: - break; - } - - return false; -} - -void Literal::accept(Visitor &visitor) const { visitor.visit(*this); } -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/expressions/AST_Parenthesized.cc b/source/parser/ast/source/expressions/AST_Parenthesized.cc deleted file mode 100644 index 789cedd..0000000 --- a/source/parser/ast/source/expressions/AST_Parenthesized.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult Parenthesized::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool Parenthesized::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void Parenthesized::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/expressions/AST_PathAccess.cc b/source/parser/ast/source/expressions/AST_PathAccess.cc deleted file mode 100644 index 5f77f5f..0000000 --- a/source/parser/ast/source/expressions/AST_PathAccess.cc +++ /dev/null @@ -1,36 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -// PathAccess := (DotAccess | ScopeAccess)* - -namespace parser::ast::node { -ParseResult PathAccess::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool PathAccess::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - - return false; -} - -void PathAccess::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/expressions/AST_UnaryOp.cc b/source/parser/ast/source/expressions/AST_UnaryOp.cc deleted file mode 100644 index 40c1ae7..0000000 --- a/source/parser/ast/source/expressions/AST_UnaryOp.cc +++ /dev/null @@ -1,50 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult UnaryOp::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - // UnaryOp ::= op right - - i32 len = 0; - - op = tokens->front(); - - ++len; - - auto slice = tokens->slice(len); - - right = get_Expression(slice); - - if (right != nullptr) { - len += right->parse(); - return len; - } - - return 0; -} - -bool UnaryOp::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void UnaryOp::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/expressions/Expression.cc b/source/parser/ast/source/expressions/Expression.cc deleted file mode 100644 index 5a6c30f..0000000 --- a/source/parser/ast/source/expressions/Expression.cc +++ /dev/null @@ -1,118 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// This file defines the AST Expression Parser, which is used to parse expressions in the AST. // -// // -//===-----------------------------------------------------------------------------------------====// - -#include - -#include "neo-panic/include/error.hh" -#include "neo-pprint/include/hxpprint.hh" -#include "parser/ast/include/AST.hh" -#include "parser/ast/include/case_types.def" -#include "token/include/generate.hh" -#include "token/include/token_list.hh" - -/* IDEINTIFIED - -break into 2 parts the compound expressions and the single expressions - -single expressions are: - [x] Literals - [x] Identifier - [x] UnaryOp - [x] FunctionCall - [x] ScopeAccess - [x] Parenthesized - -compound expressions are: - [-] PathAccess - [-] DotAccess - - [-] BinaryOp - [-] ArrayAccess - [-] Cast - - -TODO: add the following: - [-] List - [-] Set - [-] Tuple - [-] Map - [-] Match - [-] Range - [-] Lambda - [-] GenericAccess - [-] TernaryOp -*/ - -namespace parser::ast { -NodeT get_simple_Expression(token::TokenList &tokens) { - for (auto &tok : tokens) { - auto peek = tok.peek(); - bool has_peek = tok.peek().has_value(); - - switch (tok->token_kind()) { - case IS_LITERAL: - return new node::Literal(tokens); - - case IS_IDENTIFIER: { - - if (has_peek) { - switch (peek->get().token_kind()) { - case token::OPERATOR_SCOPE: - return new node::ScopeAccess(tokens); - case token::PUNCTUATION_OPEN_PAREN: - return new node::FunctionCall(tokens); - default: - return new node::Identifier(tokens); - } - } - return new node::Identifier(tokens); - } - - case IS_OPERATOR: - return new node::UnaryOp(tokens); - - case token::PUNCTUATION_OPEN_PAREN: - return new node::Parenthesized(tokens); - - default: - break; - } - } - - return nullptr; -} - -NodeT get_Expression(token::TokenList &tokens) { - /// Parse any expression - /// Expression ::= Literal | AnySeparatedID | BinaryOperation | UnaryOperation | FunctionCall | - /// ParenthesizedExpression | ArrayAccess | ObjectAccess | ConditionalExpression Parsing Order - - /// The order of operations is as follows: (is this correct?) - // Operator ::= UnaryOp | BinaryOp - // Identifier ::= DotAccess | ScopeAccess | PathAccess | FunctionCall - // Literal ::= Literal | BinaryOp | UnaryOp | Cast | Conditional - // Parenthesized ::= ( Expression ) - - // we parse compound expressions here - - return get_simple_Expression(tokens); -} - -Expression::Expression() = default; -Expression::Expression(token::TokenList &tokens) - : Node(tokens) - , tokens(&tokens) {} -} // namespace __AST_BEGIN diff --git a/source/parser/ast/source/makefiles.py b/source/parser/ast/source/makefiles.py deleted file mode 100644 index 1b7fd3a..0000000 --- a/source/parser/ast/source/makefiles.py +++ /dev/null @@ -1,156 +0,0 @@ -exprs = [ - "BinaryOp", - "UnaryOp", - "Identifier", - "DotAccess", - "ScopeAccess", - "PathAccess", - "FunctionCall", - "ArrayAccess", - "Parenthesized", - "Conditional", - "Cast" -] - -states = [ - "Assignment", - "ForLoop", - "RangeLoop", - "WhileLoop", - "IfStatement", - "ElseIfStatement", - "ElseStatement", - "ConditionalStatement", - "ReturnStatement", - "ContinueStatement", - "BreakStatement", - "YieldStatement" -] - -annos = [ - "Comment", -"CompilerDirective" - -] - - - -data_to_write = ("""//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" -#include "parser/ast/include/AST_core.def" - -__AST_BEGIN::node { -ParseResult \0REPLACE\0::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool \0REPLACE\0::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void \0REPLACE\0::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node -""") - - -data_to_write2 = ("""//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// // -//===-----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -#include "parser/ast/include/case_types.def" -#include "token/include/token_list.hh" - -namespace parser::ast { - -NodeT<\0REPLACE\0> get_\0REPLACE\0(token::TokenList &tokens) { - for (auto &token : tokens) {} - - return nullptr; -} - -\0REPLACE\0::\0REPLACE\0() = default; -\0REPLACE\0::\0REPLACE\0(token::TokenList &tokens) - : Node(tokens) - , tokens(&tokens) {} -} // namespace __AST_BEGIN -""") - - -import os - - -os.makedirs("expressions", exist_ok=True) -os.makedirs("statements", exist_ok=True) -os.makedirs("annotations", exist_ok=True) -os.makedirs("types", exist_ok=True) -os.makedirs("declarations", exist_ok=True) - -for file in exprs: - with open(f"expressions/AST_{file}.cc", "w") as f: - f.write(data_to_write.replace("\0REPLACE\0", file)) - print(f"Created file: {file}.cc") - -for file in states: - with open(f"statements/AST_{file}.cc", "w") as f: - f.write(data_to_write.replace("\0REPLACE\0", file)) - print(f"Created file: {file}.cc") - -for file in annos: - with open(f"annotations/AST_{file}.cc", "w") as f: - f.write(data_to_write.replace("\0REPLACE\0", file)) - print(f"Created file: {file}.cc") - - -# make 5 files: Expression.cc, Statement.cc, Annotation.cc, Type.cc, and Declaration.cc in thier respective directories -# each file should have the same content as the data_to_write2 variable, with the \0REPLACE\0 replaced with the name of the file -# for example, the Expression.cc file should have the content of data_to_write2 with \0REPLACE\0 replaced with Expression - -with open("statements/Statement.cc", "w") as f: - f.write(data_to_write2.replace("\0REPLACE\0", "Statement")) - print("Created file: Statement.cc") - -with open("annotations/Annotation.cc", "w") as f: - f.write(data_to_write2.replace("\0REPLACE\0", "Annotation")) - print("Created file: Annotation.cc") - -with open("types/Type.cc", "w") as f: - f.write(data_to_write2.replace("\0REPLACE\0", "Type")) - print("Created file: Type.cc") - -with open("declarations/Declaration.cc", "w") as f: - f.write(data_to_write2.replace("\0REPLACE\0", "Declaration")) - print("Created file: Declaration.cc") - -print("Done!") diff --git a/source/parser/ast/source/nodes/Decls.cc b/source/parser/ast/source/nodes/Decls.cc new file mode 100644 index 0000000..b7869ec --- /dev/null +++ b/source/parser/ast/source/nodes/Decls.cc @@ -0,0 +1,988 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). You // +// are allowed to use, modify, redistribute, and create derivative works, even for commercial // +// purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// +/// /// +/// @file Decls.cc /// +/// @brief This file contains the entire logic to parse declarations using a recursive descent /// +/// parser. the parser adheres to an ll(1) grammar, which means it processes the input /// +/// left-to-right and constructs the leftmost derivation using one token of lookahead. /// +/// /// +/// The parser is implemented using the `parse` method, which is a recursive descent parser /// +/// that uses the token list to parse the Declaration grammar. /// +/// /// +/// @code /// +/// Declaration decl(tokens); /// +/// ParseResult<> node = decl.parse(); /// +/// /// +/// if (node.has_value()) { /// +/// NodeT<> ast = node.value(); /// +/// } else { /// +/// std::cerr << node.error().what() << std::endl; /// +/// } /// +/// @endcode /// +/// /// +/// By default, the parser will parse the entire declaration, but you can also parse a specific /// +/// declaration by calling the specific parse method. or get a specific node by calling /// +/// parse and then passing a template argument to the method. /// +/// /// +/// @code /// +/// Declaration state(tokens); /// +/// ParseResult node = state.parse(); /// +/// @endcode /// +/// /// +/// The parser is implemented using the following grammar: /// +/// /// +/// STS * /* node types */ /// +/// [x] * Literal * L /// +/// [x] * Operator * O /// +/// [x] * Token * T /// +/// [x] * Expression * E /// +/// [x] * Statement * S /// +/// [x] * Declaration * D /// +/// /// +/// STS * /* generics and type bounds */ /// +/// [x] * RequiresParamDecl * 'const'? (S.NamedVarSpecifier) ('=' E)? /// +/// [x] * RequiresParamList * (RequiresParamDecl (',' RequiresParamDecl)*)? /// +/// [x] * TypeBoundDecl * 'if' InstOfExpr /// +/// [x] * TypeBoundList * (TypeBoundDecl (',' TypeBoundDecl)*)? /// +/// [x] * RequiresDecl * 'requires' '<' RequiresParamList '>' TypeBoundList? /// +/// [x] * EnumMemberDecl * E.IdentExpr ('=' E)? /// +/// [x] * UDTDeriveDecl * 'derives' (E.Type (',' E.Type)*)? /// +/// /// +/// /* declaration helpers */ /// +/// [x] * StorageSpecifier * 'ffi' | 'static' | 'async' | 'eval' /// +/// [x] * FFISpecifier * 'class' | 'interface' | 'struct' | 'enum' | 'union' | 'type' /// +/// [x] * TypeQualifier * 'const' | 'module' | 'yield' | 'async' | 'ffi' | 'static' /// +/// [x] * AccessSpecifier * 'pub' | 'priv' | 'prot' | 'intl' /// +/// [x] * FunctionSpecifier * 'inline' | 'async' | 'static' | 'const' | 'eval' | 'other' /// +/// [x] * FunctionQualifier * 'default' | 'panic' | 'delete' | 'const' /// +/// /// +/// [x] * VisDecl * AccessSpecifier // +/// [x] * VarDecl * S.NamedVarSpecifier ('=' E)? ~ also pass in a bool to force type need // +/// [x] * SharedModifiers * (FunctionSpecifier)*)? /// +/// /// +/// /* declaration nodes */ /// +/// [ ] * FFIDecl * VisDecl? 'ffi' L.StringLiteral D /// +/// [ ] * LetDecl * VisDecl? 'let' SharedModifiers VarDecl* ';' /// +/// [ ] * ConstDecl * VisDecl? 'const' SharedModifiers VarDecl* ';' /// +/// [ ] * TypeDecl * VisDecl? 'type' E.IdentExpr RequiresDecl? '=' E ';' /// +/// [x] * EnumDecl * VisDecl? 'enum' ('derives' E.Type)? E.ObjInitExpr /// +/// [ ] * OpDecl * SharedModifiers? 'op' T FuncDecl[no_SharedModifiers=true] /// +/// [x] * FuncDecl * SharedModifiers? 'fn' E.PathExpr '(' VarDecl[true]* ')' RequiresDecl? S.Suite +/// [x] * StructDecl* 'const'? VisDecl? 'struct' E.IdentExpr UDTDeriveDecl? RequiresDecl? S.Suite +/// [x] * ClassDecl * 'const'? VisDecl? 'class' E.IdentExpr UDTDeriveDecl? RequiresDecl? S.Suite +/// [x] * InterDecl * 'const'? VisDecl? 'interface' E.IdentExpr UDTDeriveDecl? RequiresDecl? S.Suite +/// [x] * ModuleDecl* 'inline'? 'module' E.PathExpr S.Suite /// +/// /// +/// [ ] * ExtDecl * 'extend' E.PathExpr UDTDeriveDecl? S.Suite /* TODO: dont forget */ /// +/// /// +/// [ ] * UnionDecl * VisDecl? 'union' E.IdentExpr UDTDeriveDecl? RequiresDecl? S.Suite /// +/// TODO: should unions be Statements in the form of anonymous unions or concrete type decls??? /// +//===-----------------------------------------------------------------------------------------====// + +#include +#include +#include +#include +#include + +#include "neo-pprint/include/hxpprint.hh" +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/config/AST_generate.hh" +#include "parser/ast/include/config/AST_modifiers.hh" +#include "parser/ast/include/config/case_types.def" +#include "parser/ast/include/core/AST_nodes.hh" +#include "parser/ast/include/nodes/AST_Expressions.hh" +#include "parser/ast/include/types/AST_jsonify_visitor.hh" +#include "parser/ast/include/types/AST_types.hh" +#include "token/include/generate.hh" +#include "token/include/token_list.hh" + +AST_NODE_IMPL(Declaration, RequiresParamDecl) { + IS_NOT_EMPTY; + // RequiresParamDecl := const'? (S.NamedVarSpecifier) ('=' E)? + + NodeT node = make_node(true); + ParseResult var; + + if CURRENT_TOKEN_IS (token::KEYWORD_CONST) { + iter.advance(); // skip 'const' + node->is_const = true; + } + + var = state_parser.parse(node->is_const); // force type if is_const is true + RETURN_IF_ERROR(var); + + node->var = var.value(); + + if CURRENT_TOKEN_IS (token::OPERATOR_ASSIGN) { + iter.advance(); // skip '=' + + ParseResult<> value = expr_parser.parse(); + RETURN_IF_ERROR(value); + + node->value = value.value(); + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, RequiresParamDecl) { + json.section("RequiresParamDecl") + .add("is_const", node.is_const ? "true" : "false") + .add("var", get_node_json(node.var)) + .add("value", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, RequiresParamList) { + IS_NOT_EMPTY; + // RequiresParamList := RequiresParamDecl (',' RequiresParamDecl)*)? + +#define TOKENS_REQUIRED {token::KEYWORD_CONST, token::IDENTIFIER} + IS_IN_EXCEPTED_TOKENS(TOKENS_REQUIRED); +#undef TOKENS_REQUIRED + + ParseResult first = parse(); + RETURN_IF_ERROR(first); + + NodeT node = make_node(first.value()); + + while (CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA)) { + iter.advance(); // skip ',' + + ParseResult next = parse(); + RETURN_IF_ERROR(next); + + node->params.emplace_back(next.value()); + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, RequiresParamList) { + std::vector params; + + for (const auto ¶m : node.params) { + params.push_back(get_node_json(param)); + } + + json.section("RequiresParamList", params); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, EnumMemberDecl) { + IS_NOT_EMPTY; + // EnumMemberDecl := E.IdentExpr ('=' E)? + IS_EXCEPTED_TOKEN(token::IDENTIFIER); + + ParseResult name = expr_parser.parse(); + RETURN_IF_ERROR(name); + + NodeT node = make_node(name.value()); + + if (CURRENT_TOKEN_IS(token::OPERATOR_ASSIGN)) { + iter.advance(); // skip '=' + + ParseResult<> value = expr_parser.parse(); + RETURN_IF_ERROR(value); + + node->value = value.value(); + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, EnumMemberDecl) { + json.section("EnumMemberDecl") + .add("name", get_node_json(node.name)) + .add("value", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, UDTDeriveDecl) { + IS_NOT_EMPTY; + // UDTDeriveDecl := 'derives' (VisDecl? E.Type (',' VisDecl? E.Type)*)? + + IS_EXCEPTED_TOKEN(token::KEYWORD_DERIVES); + + iter.advance(); // skip 'derives' + + AccessSpecifier access = AccessSpecifier( + token::Token(token::KEYWORD_PUBLIC, "HZL_CMPILER_INL.ACCESS_SPECIFIER__.tmp")); + if (AccessSpecifier::is_access_specifier(CURRENT_TOK)) { + access = AccessSpecifier(CURRENT_TOK); + } + + ParseResult type = expr_parser.parse(); + RETURN_IF_ERROR(type); + + NodeT node = make_node(std::make_pair(type.value(), access)); + + while (CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA)) { + iter.advance(); // skip ',' + + AccessSpecifier access = AccessSpecifier( + token::Token(token::KEYWORD_PUBLIC, "HZL_CMPILER_INL.ACCESS_SPECIFIER__.tmp")); + if (AccessSpecifier::is_access_specifier(CURRENT_TOK)) { + access = AccessSpecifier(CURRENT_TOK); + } + + ParseResult next = expr_parser.parse(); + RETURN_IF_ERROR(next); + + node->derives.emplace_back(next.value(), access); + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, UDTDeriveDecl) { + std::vector derives; + + for (const auto &derive : node.derives) { + derives.push_back(get_node_json(derive.first)); + derives.push_back(derive.second.to_json()); + } + + json.section("UDTDeriveDecl", derives); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, TypeBoundList) { + IS_NOT_EMPTY; + // TypeBoundList := InstOfExpr (',' InstOfExpr)*)? + + ParseResult bound = expr_parser.parse(expr_parser.parse_primary()); + RETURN_IF_ERROR(bound); + + NodeT node = make_node(bound.value()); + + while (CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA)) { + iter.advance(); // skip ',' + + ParseResult next = expr_parser.parse(expr_parser.parse_primary()); + RETURN_IF_ERROR(next); + + node->bounds.emplace_back(next.value()); + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, TypeBoundList) { + std::vector bounds; + + for (const auto &bound : node.bounds) { + bounds.push_back(get_node_json(bound)); + } + + json.section("TypeBoundList", bounds); +} + +// ---------------------------------------------------------------------------------------------- // + +/* TODO: DEPRECATE MERGED WITH LIST*/ +AST_NODE_IMPL(Declaration, TypeBoundDecl) { + IS_NOT_EMPTY; + NOT_IMPLEMENTED; +} + +AST_NODE_IMPL_VISITOR(Jsonify, TypeBoundDecl) { json.section("TypeBoundDecl"); } + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, RequiresDecl) { + IS_NOT_EMPTY; + // RequiresDecl := requires' '<' RequiresParamList '>' ('if' TypeBoundList)? + + IS_EXCEPTED_TOKEN(token::KEYWORD_REQUIRES); + iter.advance(); // skip 'requires + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_ANGLE); + iter.advance(); // skip '<' + + ParseResult params = parse(); + RETURN_IF_ERROR(params); + + NodeT node = make_node(params.value()); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_ANGLE); + iter.advance(); // skip '>' + + if (CURRENT_TOKEN_IS(token::KEYWORD_IF)) { + iter.advance(); // skip 'if' + + ParseResult bounds = parse(); + RETURN_IF_ERROR(bounds); + + node->bounds = bounds.value(); + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, RequiresDecl) { + json.section("RequiresDecl") + .add("params", get_node_json(node.params)) + .add("bounds", get_node_json(node.bounds)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, StructDecl, const std::shared_ptr &modifiers) { + IS_NOT_EMPTY; + // StructDecl := Modifiers 'struct' E.IdentExpr UDTDeriveDecl? RequiresDecl? S.Suite + + NodeT node = make_node(true); + + if (modifiers != nullptr) { + for (auto &tok : *modifiers) { + if (!node->modifiers.find_add(tok.current().get())) { + return std::unexpected( + PARSE_ERROR(tok.current().get(), "invalid modifier for struct")); + } + } + } else { + while (node->modifiers.find_add(CURRENT_TOK)) { + iter.advance(); // skip modifier + } + } + + IS_EXCEPTED_TOKEN(token::KEYWORD_STRUCT); + iter.advance(); // skip 'struct' + + ParseResult name = expr_parser.parse(); + RETURN_IF_ERROR(name); + + node->name = name.value(); + + if (CURRENT_TOKEN_IS(token::KEYWORD_DERIVES)) { + ParseResult derives = parse(); + RETURN_IF_ERROR(derives); + + node->derives = derives.value(); + } + + if (CURRENT_TOKEN_IS(token::KEYWORD_REQUIRES)) { + ParseResult generics = parse(); + RETURN_IF_ERROR(generics); + + node->generics = generics.value(); + } + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_SEMICOLON)) { // forward declaration + iter.advance(); // skip ';' + return node; + } + + ParseResult body = state_parser.parse(); + RETURN_IF_ERROR(body); + + node->body = body.value(); + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, StructDecl) { + json.section("StructDecl") + .add("name", get_node_json(node.name)) + .add("derives", get_node_json(node.derives)) + .add("generics", get_node_json(node.generics)) + .add("body", get_node_json(node.body)) + .add("modifiers", node.modifiers.to_json()); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, ConstDecl) { /* TODO - MAYBE REMOVE */ + IS_NOT_EMPTY; + // ConstDecl := Modifiers 'const' Modifiers VarDecl* ';' + + NOT_IMPLEMENTED; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ConstDecl) { json.section("ConstDecl"); } + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, ClassDecl, const std::shared_ptr &modifiers) { + IS_NOT_EMPTY; + // ClassDecl := Modifiers 'class' E.IdentExpr UDTDeriveDecl? RequiresDecl? S.Suite + + NodeT node = make_node(true); + + if (modifiers != nullptr) { + for (auto &tok : *modifiers) { + if (!node->modifiers.find_add(tok.current().get())) { + return std::unexpected( + PARSE_ERROR(tok.current().get(), "invalid modifier for class")); + } + } + } else { + while (node->modifiers.find_add(CURRENT_TOK)) { + iter.advance(); // skip modifier + } + } + + IS_EXCEPTED_TOKEN(token::KEYWORD_CLASS); + iter.advance(); // skip 'class' + + ParseResult name = expr_parser.parse(); + RETURN_IF_ERROR(name); + + node->name = name.value(); + + if (CURRENT_TOKEN_IS(token::KEYWORD_DERIVES)) { + ParseResult derives = parse(); + RETURN_IF_ERROR(derives); + + node->derives = derives.value(); + } + + if (CURRENT_TOKEN_IS(token::KEYWORD_REQUIRES)) { + ParseResult generics = parse(); + RETURN_IF_ERROR(generics); + + node->generics = generics.value(); + } + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_SEMICOLON)) { // forward declaration + iter.advance(); // skip ';' + return node; + } + + ParseResult body = state_parser.parse(); + RETURN_IF_ERROR(body); + + node->body = body.value(); + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ClassDecl) { + json.section("ClassDecl") + .add("name", get_node_json(node.name)) + .add("derives", get_node_json(node.derives)) + .add("generics", get_node_json(node.generics)) + .add("body", get_node_json(node.body)) + .add("modifiers", node.modifiers.to_json()); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, InterDecl, const std::shared_ptr &modifiers) { + IS_NOT_EMPTY; + // InterDecl := Modifiers 'interface' E.IdentExpr UDTDeriveDecl? RequiresDecl? S.Suite + + NodeT node = make_node(true); + + if (modifiers != nullptr) { + for (auto &tok : *modifiers) { + if (!node->modifiers.find_add(tok.current().get())) { + return std::unexpected( + PARSE_ERROR(tok.current().get(), "invalid modifier for interface")); + } + } + } else { + while (node->modifiers.find_add(CURRENT_TOK)) { + iter.advance(); // skip modifier + } + } + + IS_EXCEPTED_TOKEN(token::KEYWORD_INTERFACE); + iter.advance(); // skip 'interface' + + ParseResult name = expr_parser.parse(); + RETURN_IF_ERROR(name); + + node->name = name.value(); + + if (CURRENT_TOKEN_IS(token::KEYWORD_DERIVES)) { + ParseResult derives = parse(); + RETURN_IF_ERROR(derives); + + node->derives = derives.value(); + } + + if (CURRENT_TOKEN_IS(token::KEYWORD_REQUIRES)) { + ParseResult generics = parse(); + RETURN_IF_ERROR(generics); + + node->generics = generics.value(); + } + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_SEMICOLON)) { // forward declaration + return std::unexpected( + PARSE_ERROR(CURRENT_TOK, "forward declaration's are not allowed for interface's")); + } + + ParseResult body = state_parser.parse(); + RETURN_IF_ERROR(body); + + node->body = body.value(); + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, InterDecl) { + json.section("InterDecl") + .add("name", get_node_json(node.name)) + .add("derives", get_node_json(node.derives)) + .add("generics", get_node_json(node.generics)) + .add("body", get_node_json(node.body)) + .add("modifiers", node.modifiers.to_json()); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, EnumDecl, const std::shared_ptr &modifiers) { + IS_NOT_EMPTY; + // EnumDecl := Modifiers 'enum' ('derives' E.Type)? (('{' (EnumMemberDecl (',' + // EnumMemberDecl)*)? '}') | (':' (EnumMemberDecl (',' EnumMemberDecl)*) ';')) + + NodeT node = make_node(true); + + if (modifiers != nullptr) { + for (auto &tok : *modifiers) { + if (!node->vis.find_add(tok.current().get())) { + return std::unexpected( + PARSE_ERROR(tok.current().get(), "invalid modifier for enum")); + } + } + } else { + while (node->vis.find_add(CURRENT_TOK)) { + iter.advance(); // skip modifier + } + } + + IS_EXCEPTED_TOKEN(token::KEYWORD_ENUM); + iter.advance(); // skip 'enum' + + ParseResult name = expr_parser.parse(); + RETURN_IF_ERROR(name); + + node->name = name.value(); + + if (CURRENT_TOKEN_IS(token::KEYWORD_DERIVES)) { + iter.advance(); // skip 'derives' + + ParseResult derives = expr_parser.parse(); + RETURN_IF_ERROR(derives); + + node->derives = derives.value(); + } + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_OPEN_BRACE)) { + iter.advance(); // skip '{' + + while (CURRENT_TOKEN_IS(token::IDENTIFIER)) { + ParseResult member = parse(); + RETURN_IF_ERROR(member); + + node->members.emplace_back(member.value()); + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA)) { + iter.advance(); // skip ',' + } + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_BRACE); + iter.advance(); // skip '}' + + } else if (CURRENT_TOKEN_IS(token::PUNCTUATION_COLON)) { + iter.advance(); // skip ':' + + while (CURRENT_TOKEN_IS(token::IDENTIFIER)) { + ParseResult member = parse(); + RETURN_IF_ERROR(member); + + node->members.emplace_back(member.value()); + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA)) { + iter.advance(); // skip ',' + } + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); // skip ';' + + } else { + return std::unexpected(PARSE_ERROR(CURRENT_TOK, "expected enum body")); + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, EnumDecl) { + std::vector members; + + for (const auto &member : node.members) { + members.push_back(get_node_json(member)); + } + + json.section("EnumDecl") + .add("derives", get_node_json(node.derives)) + .add("members", members) + .add("vis", node.vis.to_json()) + .add("name", get_node_json(node.name)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, TypeDecl, const std::shared_ptr &modifiers) { + IS_NOT_EMPTY; + // TypeDecl := Modifiers 'type' E.IdentExpr RequiresDecl? '=' E ';' + + NOT_IMPLEMENTED; +} + +AST_NODE_IMPL_VISITOR(Jsonify, TypeDecl) { json.section("TypeDecl"); } + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, FuncDecl, const std::shared_ptr &modifiers) { + IS_NOT_EMPTY; + // FuncDecl := Modifiers 'fn' E.PathExpr '(' VarDecl[true]* ')' RequiresDecl? ('->' + // E.TypeExpr)? (S.Suite | ';' | '=' ('default' | 'delete')) + + // one rule to follow is we cant have keyword arguments after positional arguments + bool has_keyword = false; + + NodeT node = make_node(true); + + if (modifiers != nullptr) { + for (auto &tok : *modifiers) { + if (!node->modifiers.find_add(tok.current().get())) { + return std::unexpected( + PARSE_ERROR(tok.current().get(), "invalid modifier for function")); + } + } + } else { + while (node->modifiers.find_add(CURRENT_TOK)) { + iter.advance(); // skip modifier + } + } + + IS_EXCEPTED_TOKEN(token::KEYWORD_FUNCTION); + iter.advance(); // skip 'fn' + + ParseResult name = expr_parser.parse(); + RETURN_IF_ERROR(name); + + if (name.value()->type == PathExpr::PathType::Dot) { + return std::unexpected(PARSE_ERROR(CURRENT_TOK, "invalid function name")); + } + + node->name = name.value(); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_PAREN); + iter.advance(); // skip '(' + + while (CURRENT_TOKEN_IS(token::IDENTIFIER) || CURRENT_TOKEN_IS(token::KEYWORD_CONST)) { + token::Token starting = CURRENT_TOK; + + ParseResult param = parse(true); + RETURN_IF_ERROR(param); + + if (param.value()->value != nullptr) { + if (has_keyword) { + return std::unexpected( + PARSE_ERROR(starting, "positional argument after default argument")); + } + + has_keyword = true; + } + + node->params.emplace_back(param.value()); + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA)) { + iter.advance(); // skip ',' + } + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_PAREN); + iter.advance(); // skip ')' + + if (CURRENT_TOKEN_IS(token::KEYWORD_REQUIRES)) { + ParseResult generics = parse(); + RETURN_IF_ERROR(generics); + + node->generics = generics.value(); + } + + if (CURRENT_TOKEN_IS(token::OPERATOR_ARROW)) { + iter.advance(); // skip '->' + + ParseResult returns = expr_parser.parse(); + RETURN_IF_ERROR(returns); + + node->returns = returns.value(); + } + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_SEMICOLON)) { + iter.advance(); // skip ';' + } else if (CURRENT_TOKEN_IS(token::OPERATOR_ASSIGN)) { + iter.advance(); // skip '=' + + while (node->qualifiers.find_add(CURRENT_TOK)) { + iter.advance(); // skip qualifier + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); // skip ';' + } else if (CURRENT_TOKEN_IS(token::PUNCTUATION_OPEN_BRACE)) { + ParseResult body = state_parser.parse(); + RETURN_IF_ERROR(body); + + node->body = body.value(); + } else { + return std::unexpected(PARSE_ERROR(CURRENT_TOK, "expected function body")); + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, FuncDecl) { + std::vector params; + + for (const auto ¶m : node.params) { + params.push_back(get_node_json(param)); + } + + json.section("FuncDecl") + .add("name", get_node_json(node.name)) + .add("params", params) + .add("generics", get_node_json(node.generics)) + .add("returns", get_node_json(node.returns)) + .add("body", get_node_json(node.body)) + .add("modifiers", node.modifiers.to_json()) + .add("qualifiers", node.qualifiers.to_json()); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, VarDecl, bool force_type, bool force_value) { + IS_NOT_EMPTY; + // VarDecl := S.NamedVarSpecifier ('=' E)? ~ also pass in a bool to force type need + + ParseResult var = state_parser.parse(force_type); + RETURN_IF_ERROR(var); + + if (CURRENT_TOKEN_IS(token::OPERATOR_ASSIGN)) { + iter.advance(); // skip '=' + + ParseResult<> value = expr_parser.parse(); + RETURN_IF_ERROR(value); + + NodeT node = make_node(var.value(), value.value()); + return node; + } + + if (force_value) { + return std::unexpected(PARSE_ERROR(CURRENT_TOK, "expected value for variable")); + } + + NodeT node = make_node(var.value()); + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, VarDecl) { + json.section("VarDecl") + .add("var", get_node_json(node.var)) + .add("value", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, FFIDecl, const std::shared_ptr &modifiers) { + IS_NOT_EMPTY; + // FFIDecl := Modifiers 'ffi' L.StringLiteral D + + NOT_IMPLEMENTED; +} + +AST_NODE_IMPL_VISITOR(Jsonify, FFIDecl) { json.section("FFIDecl"); } + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, LetDecl, const std::shared_ptr &modifiers) { + IS_NOT_EMPTY; + // LetDecl := Modifiers 'let' Modifiers VarDecl* ';' + + NodeT node = make_node(true); + + if (modifiers != nullptr) { + for (auto &tok : *modifiers) { + if (!node->vis.find_add(tok.current().get())) { + return std::unexpected( + PARSE_ERROR(tok.current().get(), "invalid modifier for let")); + } + } + } else { + while (node->vis.find_add(CURRENT_TOK)) { + iter.advance(); // skip modifier + } + } + + IS_EXCEPTED_TOKEN(token::KEYWORD_LET); + iter.advance(); // skip 'let' + + while (node->modifiers.find_add(CURRENT_TOK)) { + iter.advance(); // skip modifier + } + + while + CURRENT_TOKEN_IS(token::IDENTIFIER) { + ParseResult var = parse(); + RETURN_IF_ERROR(var); + + // if no value is provided type is required + if ((var.value()->value == nullptr) && (var.value()->var->type == nullptr)) { + return std::unexpected( + PARSE_ERROR(var.value()->var->path->name, "expected a type or value for let")); + } + + node->vars.emplace_back(var.value()); + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA)) { + iter.advance(); // skip ',' + } + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); // skip ';' + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, LetDecl) { + std::vector vars; + + for (const auto &var : node.vars) { + vars.push_back(get_node_json(var)); + } + + json.section("LetDecl") + .add("vars", vars) + .add("vis", node.vis.to_json()) + .add("modifiers", node.modifiers.to_json()); +} + +// ---------------------------------------------------------------------------------------------- // + +/* TODO: MERGE WITH FUNCTION DECL */ +AST_NODE_IMPL(Declaration, OpDecl, const std::shared_ptr &modifiers) { + IS_NOT_EMPTY; + // OpDecl := Modifiers 'op' T FuncDecl[no_SharedModifiers=true] + + NOT_IMPLEMENTED; +} + +AST_NODE_IMPL_VISITOR(Jsonify, OpDecl) { json.section("OpDecl"); } + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Declaration, ModuleDecl, const std::shared_ptr &modifiers) { + IS_NOT_EMPTY; + // ModuleDecl := 'inline'? 'module' E.PathExpr[scopeOnly=true] S.Suite + + if (modifiers != nullptr) { + for (auto &tok : *modifiers) { + return std::unexpected( + PARSE_ERROR(tok.current().get(), "invalid specifier for module")); + } + } + + bool inline_module = false; + + if (CURRENT_TOKEN_IS(token::KEYWORD_INLINE)) { + inline_module = true; + iter.advance(); // skip 'inline' + } + + IS_EXCEPTED_TOKEN(token::KEYWORD_MODULE); + iter.advance(); // skip 'module' + + ParseResult name = expr_parser.parse(); + RETURN_IF_ERROR(name); + + ParseResult body = state_parser.parse(); + RETURN_IF_ERROR(body); + + NodeT node = make_node(name.value(), body.value(), inline_module); + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ModuleDecl) { + json.section("ModuleDecl") + .add("name", get_node_json(node.name)) + .add("body", get_node_json(node.body)) + .add("inline_module", node.inline_module ? "true" : "false"); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_BASE_IMPL(Declaration, parse) { + IS_NOT_EMPTY; + + token::Token tok = CURRENT_TOK; /// get the current token from the iterator + std::shared_ptr modifiers = nullptr; /// create a pointer to the modifiers + + /* TODO: make this not happen if bool is passed */ + while (Modifiers::is_modifier(tok)) { + if (modifiers == nullptr || modifiers->empty()) { + modifiers = std::make_shared(); + } + + modifiers->push_back(tok); /// add the modifier to the list + iter.advance(); /// advance the iterator + + tok = CURRENT_TOK; /// get the next token + } + + switch (tok.token_kind()) { + case token::KEYWORD_CONST: + return parse(); + case token::KEYWORD_CLASS: + return parse(modifiers); + case token::KEYWORD_ENUM: + if (modifiers != nullptr) { + return std::unexpected(PARSE_ERROR(tok, "invalid modifier for enum")); + } + + return parse(modifiers); + case token::KEYWORD_INTERFACE: + return parse(modifiers); + case token::KEYWORD_LET: + return parse(modifiers); + case token::KEYWORD_FFI: + return parse(modifiers); + case token::KEYWORD_FUNCTION: + return parse(modifiers); + case token::KEYWORD_OPERATOR: + return parse(modifiers); + case token::KEYWORD_TYPE: + return parse(modifiers); + // case token::KEYWORD_UNION: + // return parse(modifiers); + // TODO: evaluate if unions should be statements or declarations + case token::KEYWORD_STRUCT: + return parse(modifiers); + case token::KEYWORD_MODULE: + return parse(modifiers); + default: + return state_parser.parse(); + } +} diff --git a/source/parser/ast/source/nodes/Exprs.cc b/source/parser/ast/source/nodes/Exprs.cc new file mode 100644 index 0000000..c3a6947 --- /dev/null +++ b/source/parser/ast/source/nodes/Exprs.cc @@ -0,0 +1,1597 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). You // +// are allowed to use, modify, redistribute, and create derivative works, even for commercial // +// purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// +/// /// +/// @file Expr.cc /// +/// @brief This file contains the entire logic to parse expressions using a recursive descent /// +/// parser. the parser adheres to an ll(1) grammar, which means it processes the input /// +/// left-to-right and constructs the leftmost derivation using one token of lookahead. /// +/// /// +/// The parser is implemented using the `parse` method, which is a recursive descent parser /// +/// that uses the token list to parse the expression grammar. /// +/// /// +/// @code /// +/// Expression expr(tokens); /// +/// ParseResult<> node = expr.parse(); /// +/// /// +/// if (node.has_value()) { /// +/// NodeT<> ast = node.value(); /// +/// } else { /// +/// std::cerr << node.error().what() << std::endl; /// +/// } /// +/// @endcode /// +/// /// +/// By default, the parser will parse the entire expression, but you can also parse a specific /// +/// expression by calling the specific parse method. or get a specific node by calling parse /// +/// and then passing a template argument to the method. /// +/// /// +/// @code /// +/// Expression expr(tokens); /// +/// ParseResult node = expr.parse(); /// +/// @endcode /// +/// /// +/// The parser is implemented using the following grammar: /// +/// /// +/// STS * /* node types */ /// +/// [x] * Literal * L /// +/// [x] * Operator * O /// +/// [x] * Token * T /// +/// /// +/// * helper nodes (not supposed to be explicitly used) */ /// +/// [x] * ArgumentListExpr * AL -> ( AE? ( ',' AE )* ) /// +/// [x] * NamedArgumentExpr * KA -> '.' ID '=' E /// +/// [x] * ArgumentExpr * AE -> E | ID '=' E /// +/// [x] * MapPairExpr * MP -> E ':' E /// +/// /// +/// /* primary nodes */ /// +/// [x] * UnaryExpr * UE -> O PE /// +/// [x] * BinaryExpr * BE -> UE BE' /// +/// BE' -> O UE BE' | ϵ /// +/// /// +/// /* core single associative */ /// +/// [x] * IdentExpr * ID -> T /// +/// [x] * LiteralExpr * LE -> L /// +/// /// +/// /* multi-associative */ /// +/// [x] * ScopePathExpr * SA -> ID '::' ID /// +/// [x] * DotPathExpr * DE -> PE '.' ID /// +/// [x] * PathExpr * PA -> SA | DE /// +/// /// +/// [x] * TernaryExpr * TE -> PE '?' E ':' E | PE 'if' E 'else' E /// +/// [x] * InstOfExpr * IE -> PE ( 'has' | 'derives' ) ID /// +/// [x] * CastExpr * CE -> PE 'as' E /// +/// /// +/// [x] * ArrayAccessExpr * AA -> PE '[' E ']' /// +/// [x] * FunctionCallExpr * FC -> PA GI? AL /// +/// /// +/// /* right associative recursive */ /// +/// [x] * ObjInitExpr * OI -> '{' ( KA ( ',' KA )* )? '}' /// +/// [x] * SetLiteralExpr * SE -> '{' E ( ',' E )* '}' /// +/// [x] * TupleLiteralExpr * TL -> '(' E ( ',' E )* ')' /// +/// [x] * ArrayLiteralExpr * AE -> '[' E ( ',' E )* ']' /// +/// [x] * ParenthesizedExpr * PAE -> '(' E? ')' /// +/// /// +/// [x] * AsyncExpr * AS -> ('spawn' | 'thread') E /// +/// [x] * AwaitExpr * AS -> 'await' E /// +/// [ ] * ContextManagerExpr * CM -> E 'as' ID Suite /// +/// [ ] * LambdaExpr * LE -> 'fn' TODO /// +/// /// +/// /* generics */ /// +/// [ ] * GenericInvokeExpr * GI -> '<' TY? ( ',' TY )* '>' /// +/// [ ] * GenericInvokePathExpr * PGE -> PE GI /// +/// /// +/// /// +/// [x] * Type * TY -> ID | PT /// +/// /// +/// /* complete parser */ /// +/// [x] * PE -> LE | ID | AE | SE | TL | OI | PA | PAE /// +/// [x] * E -> PE | UE | BE | TE | CE | IE | AA | FC /// +/// /// +/// TODO: big problem: the parser needs to be able to parse generics in the context of exprs, /// +/// since doing something like `foo` is a valid expression. This is not currently /// +/// supported. a better example would be: /// +/// /// +/// @code /// +/// const eval let PI: T = T(3.1415926535) requires ; /// +/// let x: int = PI; /// +/// @endcode /// +/// /// +/// this is a valid expression, but how do we parse it? /// +/// how can we parse the `PI` and not confuse it with a BinaryExpr like /// +/// `PI < int`? and the > becoming a syntax error? /// +/// /// +/// TODO: add support for async keywords, 'await', 'spawn', 'thread' /// +/// TODO: add support for 'match' expressions /// +/// /// +//===-----------------------------------------------------------------------------------------====// + +#include +#include +#include +#include + +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/config/AST_generate.hh" +#include "parser/ast/include/config/AST_modifiers.hh" +#include "parser/ast/include/config/case_types.def" +#include "parser/ast/include/core/AST_nodes.hh" +#include "parser/ast/include/nodes/AST_Expressions.hh" +#include "parser/ast/include/types/AST_jsonify_visitor.hh" +#include "parser/ast/include/types/AST_types.hh" +#include "token/include/generate.hh" + +// ---------------------------------------------------------------------------------------------- // + +bool is_excepted(const token::Token &tok, const std::unordered_set &tokens); +int get_precedence(const token::Token &tok); + +bool is_function_specifier(const token::Token &tok); +bool is_function_qualifier(const token::Token &tok); +bool is_storage_specifier(const token::Token &tok); +bool is_access_specifier(const token::Token &tok); +bool is_type_qualifier(const token::Token &tok); +bool is_ffi_specifier(const token::Token &tok); + +// ---------------------------------------------------------------------------------------------- // + +AST_BASE_IMPL(Expression, parse_primary) { // NOLINT(readability-function-cognitive-complexity) + IS_NOT_EMPTY; + + token::Token tok = CURRENT_TOK; + ParseResult<> node; + + if (is_excepted(tok, IS_LITERAL)) { + node = parse(); + } else if (is_excepted(tok, IS_IDENTIFIER)) { + node = parse(); + } else if (is_excepted(tok, IS_UNARY_OPERATOR)) { + node = parse(); + } else if (is_excepted(tok, IS_PUNCTUATION)) { + if (tok.token_kind() == + token::PUNCTUATION_OPEN_PAREN) { /// at this point we either have a tuple or a + /// parenthesized expression, so we need to do + /// further analysis to determine which one it + /// is + iter.advance(); /// skip '(' + ParseResult<> expr = parse(); + RETURN_IF_ERROR(expr); + + if (CURRENT_TOK == token::PUNCTUATION_COMMA) { /// if the next token is a + /// comma, then its a tuple + node = parse(expr); + } else { + node = parse(expr); + } + } else if (tok.token_kind() == token::PUNCTUATION_OPEN_BRACKET) { + node = parse(); + } else if (tok.token_kind() == token::PUNCTUATION_OPEN_BRACE) { + /// heres its either a set, a map or an object + /// initializer, to determine which one it is, its + /// quite simple we need to check if the next + /// token is a '.' which if it is, then its an + /// object initializer otherwise we parse E(1) and + /// check if the next token is a ':', if it is, + /// then its a map otherwise its a set + + iter.advance(); // skip '{' + + if (CURRENT_TOK == token::PUNCTUATION_DOT) { + node = parse(true); + } else { + ParseResult<> first = parse(); + RETURN_IF_ERROR(first); + + if (CURRENT_TOK == token::PUNCTUATION_COLON) { + node = parse(first); + } else { + node = parse(first); + } + } + } else { + if (tok.token_kind() != token::PUNCTUATION_SEMICOLON) { + return std::unexpected( + PARSE_ERROR_MSG("Expected an expression, but found nothing")); + } + } + } else if (is_excepted(tok, + {token::KEYWORD_THREAD, token::KEYWORD_SPAWN, token::KEYWORD_AWAIT})) { + node = parse(); + } else { + return std::unexpected( + PARSE_ERROR_MSG("Expected an expression, but found an unexpected token '" + + CURRENT_TOK.token_kind_repr() + "'")); + } + + return node; +} + +// ---------------------------------------------------------------------------------------------- // + +AST_BASE_IMPL(Expression, parse) { // NOLINT(readability-function-cognitive-complexity) + IS_NOT_EMPTY; /// simple macro to check if the iterator is empty, expands to: + /// if(iter.remaining_n() == 0) { return std::unexpected(...); } + + token::Token tok; + size_t iter_n = 0; + size_t n_max = iter.remaining_n() << 1; /// this is a way to approx the tokens to parse, and is + /// used to prevent the parser from going into an + /// infinite loop if the expression is malformed, this + /// is a simple way to prevent stack overflows and + /// memory exhaustion + bool continue_loop = true; + ParseResult<> expr = parse_primary(); /// E(1) - this is always the first expression in the + /// expression, we then build compound expressions from + /// this + + RETURN_IF_ERROR(expr); /// simple macro to return if the expression is an error expands to: + /// if (!expr.has_value()) { return std::unexpected(expr.error()); } + + /// parsed above, but now we need way to limit the number of times we can loop since if we have + /// a really really long expression, we could end up in an memory exhaustion situation or a + /// stack overflow situation. /* TODO */ + for (; iter_n < n_max && continue_loop; iter_n++) { /// this is a simple loop that will + /// continue to loop until we have parsed + /// all the tokens in the expression, the + /// expression + + tok = CURRENT_TOK; /// simple macro to get the current token expands to: + /// CURRENT_TOK + + switch (tok.token_kind()) { + // case token::PUNCTUATION_OPEN_ANGLE: /// what to do if its ident '<' parms + // /// '>' '(' args ')' its now either a + // /// function call w a generic or its a + // /// binary expression may god help me + // NOT_IMPLEMENTED; + // SOLUTION: 2 pass compiler + case token::PUNCTUATION_OPEN_PAREN: + expr = parse(expr); + RETURN_IF_ERROR(expr); + break; + + case token::PUNCTUATION_OPEN_BRACKET: + expr = parse(expr); + RETURN_IF_ERROR(expr); + break; + + case token::PUNCTUATION_DOT: + expr = parse(expr); + RETURN_IF_ERROR(expr); + break; + + case token::OPERATOR_SCOPE: + expr = parse(expr); + RETURN_IF_ERROR(expr); + break; + + case token::PUNCTUATION_OPEN_BRACE: + if (iter.peek().has_value() && + iter.peek().value().get().token_kind() != token::tokens::IDENTIFIER) { + continue_loop = false; + break; + } + + if (iter.peek(2).has_value() && + iter.peek(2).value().get().token_kind() != token::tokens::OPERATOR_ASSIGN) { + continue_loop = false; + break; + } + + expr = parse(false, expr); + RETURN_IF_ERROR(expr); + break; + + case token::KEYWORD_HAS: + case token::KEYWORD_DERIVES: + expr = parse(expr); + RETURN_IF_ERROR(expr); + break; + + case token::PUNCTUATION_QUESTION_MARK: + case token::KEYWORD_IF: + expr = parse(expr); + RETURN_IF_ERROR(expr); + break; + + case token::KEYWORD_AS: + expr = parse(expr); + RETURN_IF_ERROR(expr); + break; + + case token::LITERAL_CHAR: + case token::LITERAL_STRING: + expr = parse(expr); + RETURN_IF_ERROR(expr); + break; + + default: + if (is_excepted(tok, IS_BINARY_OPERATOR)) { + expr = parse(expr, get_precedence(tok)); + RETURN_IF_ERROR(expr); + } else if (is_excepted(tok, IS_UNARY_OPERATOR)) { + expr = parse(expr); + RETURN_IF_ERROR(expr); + } else if (tok == token::PUNCTUATION_OPEN_PAREN) { + iter.advance(); // skip '(' + expr = parse(expr); /// im not sure why this works, but + /// based on small tests, it seems + /// to work fine i'll find out soon + /// enough if it doesn't + RETURN_IF_ERROR(expr); + } else { + continue_loop = false; + } + } + } + + if (iter_n >= n_max) { + return std::unexpected(PARSE_ERROR_MSG("expression is too long")); + } + + return expr; +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, LiteralExpr, ParseResult<> str_concat) { + IS_NOT_EMPTY; + + token::Token tok = CURRENT_TOK; // get tokens[0] + iter.advance(); // pop tokens[0] + + LiteralExpr::LiteralType type{}; + + IS_NOT_NULL_RESULT(str_concat) { + if (str_concat.value()->getNodeType() != nodes::LiteralExpr || + std::static_pointer_cast(str_concat.value())->type != + LiteralExpr::LiteralType::String) { + return std::unexpected(PARSE_ERROR(tok, "expected a string literal")); + } + + NodeT str = std::static_pointer_cast(str_concat.value()); + + if (tok.token_kind() != token::LITERAL_STRING) { + return std::unexpected(PARSE_ERROR(tok, "expected a string literal")); + } + + str->value.set_value(str->value.value() + tok.value()); + return str; + } + + switch (tok.token_kind()) { + case token::LITERAL_INTEGER: + type = LiteralExpr::LiteralType::Integer; + break; + case token::LITERAL_FLOATING_POINT: + type = LiteralExpr::LiteralType::Float; + break; + case token::LITERAL_STRING: + type = LiteralExpr::LiteralType::String; + break; + case token::LITERAL_CHAR: + type = LiteralExpr::LiteralType::Char; + break; + case token::LITERAL_TRUE: + case token::LITERAL_FALSE: + type = LiteralExpr::LiteralType::Boolean; + break; + case token::LITERAL_NULL: + type = LiteralExpr::LiteralType::Null; + break; + default: + return std::unexpected( + PARSE_ERROR(tok, "expected a literal. but found: " + tok.token_kind_repr())); + } + + return make_node(tok, type); +} + +AST_NODE_IMPL_VISITOR(Jsonify, LiteralExpr) { + json.section("LiteralExpr").add("value", node.value).add("type", (int)node.getNodeType()); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, BinaryExpr, ParseResult<> lhs, int min_precedence) { + IS_NOT_EMPTY; + + // := E op E + // TODO if E(2) does not exist, check if its a & | * token, since if it is, + // then return a unary expression since its a pointer or reference type + + token::Token tok = CURRENT_TOK; + + while (is_excepted(tok, IS_BINARY_OPERATOR) && get_precedence(tok) >= min_precedence) { + int precedence = get_precedence(tok); + token::Token op = tok; + + iter.advance(); + + ParseResult<> rhs = parse_primary(); + RETURN_IF_ERROR(rhs); + + tok = CURRENT_TOK; + while (is_excepted(tok, IS_BINARY_OPERATOR) && get_precedence(tok) > precedence) { + rhs = parse(rhs, get_precedence(tok)); + RETURN_IF_ERROR(rhs); + tok = CURRENT_TOK; + } + + lhs = make_node(lhs.value(), rhs.value(), op); + } + + return std::static_pointer_cast(lhs.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, BinaryExpr) { + json.section("BinaryExpr") + .add("lhs", get_node_json(node.lhs)) + .add("op", node.op) + .add("rhs", get_node_json(node.rhs)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, UnaryExpr, ParseResult<> lhs) { + IS_NOT_EMPTY; + + // := op E | E op + + IS_IN_EXCEPTED_TOKENS(IS_UNARY_OPERATOR); + token::Token op = CURRENT_TOK; + iter.advance(); + + IS_NULL_RESULT(lhs) { + ParseResult<> rhs = parse(); + RETURN_IF_ERROR(rhs); + + return make_node(rhs.value(), op, UnaryExpr::PosType::PreFix); + } + + return make_node(lhs.value(), op, UnaryExpr::PosType::PostFix); +} + +AST_NODE_IMPL_VISITOR(Jsonify, UnaryExpr) { + json.section("UnaryExpr") + .add("operand", get_node_json(node.opd)) + .add("op", node.op) + .add("type", (int)node.type); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, IdentExpr) { + IS_NOT_EMPTY; + + // verify the current token is an identifier + token::Token tok = CURRENT_TOK; + bool is_reserved_primitive = false; + + IS_IN_EXCEPTED_TOKENS(IS_IDENTIFIER); + + if (tok.token_kind() != token::IDENTIFIER) { + is_reserved_primitive = true; + } + + iter.advance(); // pop the token + return make_node(tok, is_reserved_primitive); +} + +AST_NODE_IMPL_VISITOR(Jsonify, IdentExpr) { json.section("IdentExpr", node.name); } + +// ---------------------------------------------------------------------------------------------- // + +/* FIXME: use this method, if unused remove */ +// should not be called by `parse` directly as it is a helper function +AST_NODE_IMPL(Expression, NamedArgumentExpr, bool is_anonymous) { + IS_NOT_EMPTY; + + // := '.'? IdentExpr '=' E + if (is_anonymous) { + IS_EXCEPTED_TOKEN(token::PUNCTUATION_DOT); + iter.advance(); // skip '.' + } else { + IS_NOT_EXCEPTED_TOKEN(token::PUNCTUATION_DOT); + } + + ParseResult name = parse(); + RETURN_IF_ERROR(name); + + IS_EXCEPTED_TOKEN(token::OPERATOR_ASSIGN); + iter.advance(); // skip '=' + + ParseResult<> value = parse(); + RETURN_IF_ERROR(value); + + return make_node(name.value(), value.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, NamedArgumentExpr) { + json.section("NamedArgumentExpr") + .add("name", get_node_json(node.name)) + .add("value", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +// should not be called by `parse` directly as it is a helper function +AST_NODE_IMPL(Expression, ArgumentExpr) { + IS_NOT_EMPTY; + + NodeT result; + + ParseResult<> lhs = parse(); // E(1) + RETURN_IF_ERROR(lhs); + + NodeT<> lhs_node = lhs.value(); + + if (lhs_node->getNodeType() == nodes::BinaryExpr) { + NodeT bin_expr = std::static_pointer_cast(lhs_node); + + if (bin_expr->lhs->getNodeType() == nodes::IdentExpr && + bin_expr->op.token_kind() == token::OPERATOR_ASSIGN) { + + NodeT kwarg = make_node( + std::static_pointer_cast(bin_expr->lhs), bin_expr->rhs); + + result = make_node(kwarg); + result->type = ArgumentExpr::ArgumentType::Keyword; + + return result; + } + } + + result = make_node(lhs_node); + result->type = ArgumentExpr::ArgumentType::Positional; + + return result; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ArgumentExpr) { + json.section("ArgumentExpr") + .add("type", (int)node.type) + .add("value", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, ArgumentListExpr) { + IS_NOT_EMPTY; + + // := '(' ArgumentExpr (',' ArgumentExpr)* ')' + // in typical recursive descent fashion, we parse the first argument expression + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_PAREN); + iter.advance(); // skip '(' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_PAREN) { + iter.advance(); // skip ')' + return make_node(nullptr); + } + + ParseResult first = parse(); + RETURN_IF_ERROR(first); + + NodeT args = make_node(first.value()); + + while + CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA) { + iter.advance(); // skip ',' + + ParseResult arg = parse(); + RETURN_IF_ERROR(arg); + + args->args.push_back(arg.value()); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_PAREN); + iter.advance(); // skip ')' + + return args; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ArgumentListExpr) { + std::vector args; + + for (const auto &arg : node.args) { + args.push_back(get_node_json(arg)); + } + + json.section("ArgumentListExpr", args); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, GenericInvokeExpr) { + IS_NOT_EMPTY; + // := '<' GenericArgumentExpr (',' GenericArgumentExpr)* '>' + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_ANGLE); + iter.advance(); // skip '<' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_ANGLE) { + iter.advance(); // skip '>' + return make_node(nullptr); + } + + ParseResult first = parse(); + RETURN_IF_ERROR(first); + + NodeT generics = make_node(first.value()); + + while + CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA) { + iter.advance(); // skip ',' + + ParseResult arg = parse(); + RETURN_IF_ERROR(arg); + + generics->args.push_back(arg.value()); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_ANGLE); + iter.advance(); // skip '>' + + return generics; +} + +AST_NODE_IMPL_VISITOR(Jsonify, GenericInvokeExpr) { + std::vector args; + + for (const auto &arg : node.args) { + args.push_back(get_node_json(arg)); + } + + json.section("GenericInvokeExpr", args); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, GenericInvokePathExpr) { + IS_NOT_EMPTY; + NOT_IMPLEMENTED; +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, ScopePathExpr, ParseResult<> lhs) { + IS_NOT_EMPTY; + + // := E '::' E + + IS_NULL_RESULT(lhs) { + lhs = parse(); + RETURN_IF_ERROR(lhs); + } + + IS_EXCEPTED_TOKEN(token::OPERATOR_SCOPE); + iter.advance(); // skip '::' + + ParseResult<> rhs = parse(); + RETURN_IF_ERROR(rhs); + + return make_node(lhs.value(), rhs.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, ScopePathExpr) { + json.section("ScopePathExpr") + .add("lhs", get_node_json(node.lhs)) + .add("rhs", get_node_json(node.rhs)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, DotPathExpr, ParseResult<> lhs) { + IS_NOT_EMPTY; + + // := E '.' E + + IS_NULL_RESULT(lhs) { + lhs = parse(); + RETURN_IF_ERROR(lhs); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_DOT); + iter.advance(); // skip '.' + + ParseResult<> rhs = parse(); + RETURN_IF_ERROR(rhs); + + return make_node(lhs.value(), rhs.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, DotPathExpr) { + json.section("DotPathExpr") + .add("lhs", get_node_json(node.lhs)) + .add("rhs", get_node_json(node.rhs)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, ArrayAccessExpr, ParseResult<> lhs) { + IS_NOT_EMPTY; + + // := E '[' E ']' + + IS_NULL_RESULT(lhs) { + lhs = parse(); + RETURN_IF_ERROR(lhs); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_BRACKET); + iter.advance(); // skip '[' + + ParseResult<> index = parse(); + RETURN_IF_ERROR(index); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_BRACKET); + iter.advance(); // skip ']' + + return make_node(lhs.value(), index.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, ArrayAccessExpr) { + json.section("ArrayAccessExpr") + .add("array", get_node_json(node.lhs)) + .add("index", get_node_json(node.rhs)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, PathExpr, ParseResult<> simple_path) { + IS_NOT_EMPTY; + + // := IdentExpr | ScopePathExpr | DotPathExpr + + IS_NULL_RESULT(simple_path) { + simple_path = parse_primary(); + RETURN_IF_ERROR(simple_path); + } + + NodeT path = make_node(simple_path.value()); + switch (simple_path.value()->getNodeType()) { + case parser::ast::node::nodes::IdentExpr: + path->type = PathExpr::PathType::Identifier; + break; + + case parser::ast::node::nodes::ScopePathExpr: + path->type = PathExpr::PathType::Scope; + break; + + case parser::ast::node::nodes::DotPathExpr: + path->type = PathExpr::PathType::Dot; + break; + + default: + return std::unexpected( + PARSE_ERROR_MSG("expected a simple path expression, but found nothing")); + } + + return path; +} + +AST_NODE_IMPL_VISITOR(Jsonify, PathExpr) { + json.section("PathExpr").add("path", get_node_json(node.path)).add("type", (int)node.type); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, FunctionCallExpr, ParseResult<> lhs) { + IS_NOT_EMPTY; + + /* + FunctionCallExpr = { + NodeT + NodeT + NodeT + } + */ + + ParseResult path; + + IS_NULL_RESULT(lhs) { + lhs = parse(); + RETURN_IF_ERROR(lhs); + } + + path = parse(lhs.value()); + RETURN_IF_ERROR(path); + + // TODO: add support for generics + + ParseResult args = parse(); + RETURN_IF_ERROR(args); + + return make_node(path.value(), args.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, FunctionCallExpr) { + json.section("FunctionCallExpr") + .add("path", get_node_json(node.path)) + .add("args", get_node_json(node.args)) + .add("generics", get_node_json(node.generic)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, ArrayLiteralExpr) { + IS_NOT_EMPTY; + // := '[' E (',' E)* ']' + + // [1, 2, 3, ] + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_BRACKET); + iter.advance(); // skip '[' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_BRACKET) { + iter.advance(); // skip ']' + return std::unexpected(PARSE_ERROR_MSG("array literals must have at least one element")); + } + + ParseResult<> first = parse(); + + RETURN_IF_ERROR(first); + + NodeT array = make_node(first.value()); + + while + CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA) { + iter.advance(); // skip ',' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_BRACKET) { + break; + } + + ParseResult<> next = parse(); + RETURN_IF_ERROR(next); + + array->values.push_back(next.value()); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_BRACKET); + iter.advance(); // skip ']' + + return array; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ArrayLiteralExpr) { + std::vector values; + + for (const auto &value : node.values) { + values.push_back(get_node_json(value)); + } + + json.section("ArrayLiteralExpr", values); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, TupleLiteralExpr, ParseResult<> starting_element) { + IS_NOT_EMPTY; + // := '(' E (',' E)* ')' + + ParseResult<> first; + + IS_NULL_RESULT(starting_element) { // we dont have a starting element in this case + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_PAREN); + iter.advance(); // skip '(' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_PAREN) { + iter.advance(); // skip ')' + return std::unexpected( + PARSE_ERROR_MSG("tuple literals must have at least one element")); + } + + first = parse(); + RETURN_IF_ERROR(first); + } + else { + first = starting_element; + } + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_PAREN) { + iter.advance(); // skip ')' + return std::unexpected(PARSE_ERROR_MSG("tuple literals must have at least one element")); + } + + NodeT tuple = make_node(first.value()); + while + CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA) { + iter.advance(); // skip ',' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_PAREN) { + break; + } + + ParseResult<> next = parse(); + RETURN_IF_ERROR(next); + + tuple->values.push_back(next.value()); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_PAREN); + iter.advance(); // skip ')' + + return tuple; +} + +AST_NODE_IMPL_VISITOR(Jsonify, TupleLiteralExpr) { + std::vector values; + + for (const auto &value : node.values) { + values.push_back(get_node_json(value)); + } + + json.section("TupleLiteralExpr", values); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, SetLiteralExpr, ParseResult<> first) { + IS_NOT_EMPTY; + // := '{' E (',' E)* '}' + // {1} + // {1, 2, 3, } + + NodeT set; + + IS_NULL_RESULT(first) { + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_BRACE); + iter.advance(); // skip '{' + + first = parse(); + RETURN_IF_ERROR(first); + } + + set = make_node(first.value()); + + // we have parsed the '{' and the first E, so we need to check if the current token is ',' + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_BRACE) { + iter.advance(); // skip '}' + return set; + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_COMMA); // we expect a comma here + + while + CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA) { + iter.advance(); // skip ',' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_BRACE) { + break; + } + + ParseResult<> next = parse(); + RETURN_IF_ERROR(next); + + set->values.push_back(next.value()); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_BRACE); + iter.advance(); // skip '}' + + return set; +} + +AST_NODE_IMPL_VISITOR(Jsonify, SetLiteralExpr) { + std::vector values; + + for (const auto &value : node.values) { + values.push_back(get_node_json(value)); + } + + json.section("SetLiteralExpr", values); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, MapPairExpr) { + IS_NOT_EMPTY; + // := E ':' E + + ParseResult<> key = parse(); + RETURN_IF_ERROR(key); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_COLON); + iter.advance(); // skip ':' + + ParseResult<> value = parse(); + RETURN_IF_ERROR(value); + + return make_node(key.value(), value.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, MapPairExpr) { + json.section("MapPairExpr") + .add("key", get_node_json(node.key)) + .add("value", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, MapLiteralExpr, ParseResult<> key) { + IS_NOT_EMPTY; + + // := '{' E (':' E)* '}' + + NodeT pair; + + IS_NULL_RESULT(key) { + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_BRACE); + iter.advance(); // skip '{' + + ParseResult pair = parse(); + RETURN_IF_ERROR(pair); + + pair = pair.value(); + } + else { + // we have parsed the '{' and the first E, so we need to check if the current token is ':' + IS_EXCEPTED_TOKEN(token::PUNCTUATION_COLON); + iter.advance(); // skip ':' + + ParseResult<> value = parse(); + RETURN_IF_ERROR(value); + + pair = make_node(key.value(), value.value()); + } + + // := (',' E)* '}' is the remaining part of the map literal expression (there could be a + // trailing comma) + + NodeT map = make_node(pair); + + while + CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA) { + iter.advance(); // skip ',' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_BRACE) { + break; + } + + ParseResult next_pair = parse(); + RETURN_IF_ERROR(next_pair); + + map->values.push_back(next_pair.value()); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_BRACE); + iter.advance(); // skip '}' + + return map; +} + +AST_NODE_IMPL_VISITOR(Jsonify, MapLiteralExpr) { + std::vector values; + + for (const auto &value : node.values) { + values.push_back(get_node_json(value)); + } + + json.section("MapLiteralExpr", values); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, ObjInitExpr, bool skip_start_brace, ParseResult<> obj_path) { + IS_NOT_EMPTY; + + // := PATH? '{' (NamedArgumentExpr (',' NamedArgumentExpr)*)? '}' + + bool is_anonymous = true; + + IS_NOT_NULL_RESULT(obj_path) { is_anonymous = false; } + + if (!skip_start_brace) { + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_BRACE); + iter.advance(); // skip '{' + } + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_BRACE) { + return std::unexpected(PARSE_ERROR( + CURRENT_TOK, "expected a keyword argument, but got an empty object initializer")); + } + + ParseResult first = parse(is_anonymous); + RETURN_IF_ERROR(first); + + NodeT obj = make_node(first.value()); + + while + CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA) { + iter.advance(); // skip ',' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_BRACE) { + break; + } + + ParseResult next = parse(is_anonymous); + RETURN_IF_ERROR(next); + + obj->kwargs.push_back(next.value()); + } + + if (is_anonymous) { + obj->path = obj_path.value(); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_BRACE); + iter.advance(); // skip '}' + + return obj; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ObjInitExpr) { + std::vector kwargs; + + for (const auto &kwarg : node.kwargs) { + kwargs.push_back(get_node_json(kwarg)); + } + + json.section("ObjInitExpr").add("keyword_args", kwargs).add("path", get_node_json(node.path)); +} + +// ---------------------------------------------------------------------------------------------- // + +/* TODO: after Suite can be parsed */ +AST_NODE_IMPL(Expression, LambdaExpr) { + IS_NOT_EMPTY; + NOT_IMPLEMENTED; +} + +AST_NODE_IMPL_VISITOR(Jsonify, LambdaExpr) { + std::vector args; + + for (const auto &arg : node.args) { + args.push_back(get_node_json(arg)); + } + + json.section("LambdaExpr") + .add("args", args) + .add("body", get_node_json(node.body)) + .add("return_type", get_node_json(node.ret)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, TernaryExpr, ParseResult<> E1) { + IS_NOT_EMPTY; + + // := (E '?' E ':' E) | (E 'if' E 'else' E) + // true ? 1 : 0 | 1 if true else 0 + + IS_NULL_RESULT(E1) { + E1 = parse(); + RETURN_IF_ERROR(E1); + } + + if CURRENT_TOKEN_IS (token::PUNCTUATION_QUESTION_MARK) { + iter.advance(); // skip '?' + + ParseResult<> E2 = parse(); + RETURN_IF_ERROR(E2); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_COLON); + iter.advance(); // skip ':' + + ParseResult<> E3 = parse(); + RETURN_IF_ERROR(E3); + + return make_node(E1.value(), E2.value(), E3.value()); + } + + if CURRENT_TOKEN_IS (token::KEYWORD_IF) { + iter.advance(); // skip 'if' + + ParseResult<> E2 = parse(); + RETURN_IF_ERROR(E2); + + IS_EXCEPTED_TOKEN(token::KEYWORD_ELSE); + iter.advance(); // skip 'else' + + ParseResult<> E3 = parse(); + RETURN_IF_ERROR(E3); + + return make_node(E2.value(), E1.value(), E3.value()); + } + + return std::unexpected(PARSE_ERROR( + CURRENT_TOK, "expected '?' or 'if', but found: " + CURRENT_TOK.token_kind_repr())); +} + +AST_NODE_IMPL_VISITOR(Jsonify, TernaryExpr) { + json.section("TernaryExpr") + .add("condition", get_node_json(node.condition)) + .add("if_true", get_node_json(node.if_true)) + .add("if_false", get_node_json(node.if_false)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, ParenthesizedExpr, ParseResult<> expr) { + IS_NOT_EMPTY; + + // := '(' E ')' + + IS_NOT_NULL_RESULT(expr) { + // check if the current token is a ')' + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_PAREN); + iter.advance(); // skip ')' + + return make_node(expr.value()); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_PAREN); + iter.advance(); // skip '(' + + ParseResult<> inner = parse(); + RETURN_IF_ERROR(inner); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_PAREN); + iter.advance(); // skip ')' + + return make_node(inner.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, ParenthesizedExpr) { + json.section("ParenthesizedExpr", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, CastExpr, ParseResult<> lhs) { + IS_NOT_EMPTY; + + // := E 'as' E + + IS_NULL_RESULT(lhs) { + lhs = parse(); + RETURN_IF_ERROR(lhs); + } + + IS_EXCEPTED_TOKEN(token::KEYWORD_AS); + iter.advance(); // skip 'as' + + ParseResult<> rhs = parse(); + RETURN_IF_ERROR(rhs); + + return make_node(lhs.value(), rhs.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, CastExpr) { + json.section("CastExpr") + .add("value", get_node_json(node.value)) + .add("type", get_node_json(node.type)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, InstOfExpr, ParseResult<> lhs) { + IS_NOT_EMPTY; + // := E 'has' E | E 'derives' E + + InstOfExpr::InstanceType op = InstOfExpr::InstanceType::Derives; + + IS_NULL_RESULT(lhs) { + lhs = parse(); + RETURN_IF_ERROR(lhs); + } + +#define INST_OF_OPS {token::KEYWORD_HAS, token::KEYWORD_DERIVES} + IS_IN_EXCEPTED_TOKENS(INST_OF_OPS); +#undef INST_OF_OPS + + if CURRENT_TOKEN_IS (token::KEYWORD_HAS) + op = InstOfExpr::InstanceType::Has; + iter.advance(); // skip 'has' or 'derives' + + ParseResult<> rhs = parse(); + RETURN_IF_ERROR(rhs); + + return make_node(lhs.value(), rhs.value(), op); +} + +AST_NODE_IMPL_VISITOR(Jsonify, InstOfExpr) { + json.section("InstOfExpr") + .add("value", get_node_json(node.value)) + .add("type", get_node_json(node.type)) + .add("op", (int)node.op); +} + +// ---------------------------------------------------------------------------------------------- // + +/* DEPRECATED: a Type is deduced from context and at this stage is considered a Expression */ +AST_NODE_IMPL(Expression, Type) { // TODO - REMAKE using the new Modifiers and stricter rules, such + // as no types can contain a binary expression + // if E(2) does not exist, check if its a & | * token, since if it is, + // then return a unary expression since its a pointer or reference type + + // types are quite complex in helix since this is the gammer: + // Type := ('fn' '(' (Type ((',' Type)*)?)? ')' ('->' Type)?) + // | (TypePrefixes ((',' TypePrefixes)*)?)? PathExpr GenericInvocationExpr? + + // enums: StorageSpecifier, FFISpecifier, TypeQualifier, AccessSpecifier, FunctionSpecifier, + // FunctionQualifier + IS_NOT_EMPTY; + + Modifiers fn_specifiers(Modifiers::ExpectedModifier::FuncSpec); + NodeT node = make_node(true); + + if (CURRENT_TOKEN_IS(token::KEYWORD_FUNCTION)) { + iter.advance(); // skip 'fn' + NodeT lambda = make_node(iter.peek_back()->get()); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_PAREN); + iter.advance(); // skip '(' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_PAREN) { + iter.advance(); // skip ')' + return make_node(lambda); + } + + ParseResult<> first = parse(); + RETURN_IF_ERROR(first); + + lambda->args.push_back(first.value()); + + while + CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA) { + iter.advance(); // skip ',' + + if CURRENT_TOKEN_IS (token::PUNCTUATION_CLOSE_PAREN) { + break; + } + + ParseResult<> next = parse(); + RETURN_IF_ERROR(next); + + lambda->args.push_back(next.value()); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_CLOSE_PAREN); + iter.advance(); // skip ')' + + if CURRENT_TOKEN_IS (token::OPERATOR_ARROW) { + iter.advance(); // skip '->' + + ParseResult<> ret = parse(); + RETURN_IF_ERROR(ret); + + lambda->ret = ret.value(); + } + + return make_node(lambda); + } + + while (node->specifiers.find_add(CURRENT_TOK)) { + iter.advance(); // TODO: Handle 'ffi' ('class' | 'interface' | 'struct' | 'enum' | 'union' + // | 'type') + } + + ParseResult<> EXPR = parse_primary(); + RETURN_IF_ERROR(EXPR); + + bool continue_loop = true; + + while (continue_loop) { + const token::Token &tok = CURRENT_TOK; + + switch (tok.token_kind()) { + // case token::PUNCTUATION_OPEN_ANGLE: /// what to do if its ident '<' parms + // /// '>' '(' args ')' its now either a + // /// function call w a generic or its a + // /// binary expression may god help me + // NOT_IMPLEMENTED; + // SOLUTION: 2 pass compiler + case token::PUNCTUATION_OPEN_PAREN: + EXPR = parse(EXPR); + RETURN_IF_ERROR(EXPR); + break; + + case token::PUNCTUATION_OPEN_BRACKET: + EXPR = parse(EXPR); + RETURN_IF_ERROR(EXPR); + break; + + case token::OPERATOR_SCOPE: + EXPR = parse(EXPR); + RETURN_IF_ERROR(EXPR); + break; + + case token::KEYWORD_HAS: + case token::KEYWORD_DERIVES: + return std::unexpected( + PARSE_ERROR(tok, "expected a type, but found a 'has' or 'derives' keyword")); + + case token::PUNCTUATION_QUESTION_MARK: + case token::KEYWORD_IF: + EXPR = parse(EXPR); + RETURN_IF_ERROR(EXPR); + break; + + case token::KEYWORD_AS: + return std::unexpected( + PARSE_ERROR(tok, "expected a type, but found a 'as' keyword")); + case token::PUNCTUATION_OPEN_ANGLE: // generic lol + { + ParseResult generic = parse(); + RETURN_IF_ERROR(generic); + + node->generics = generic.value(); + continue_loop = false; + break; + } + + default: + if (is_excepted(tok, IS_UNARY_OPERATOR)) { + EXPR = parse(EXPR); + RETURN_IF_ERROR(EXPR); + } else if (tok == token::PUNCTUATION_OPEN_PAREN) { + iter.advance(); // skip '(' + EXPR = parse(EXPR); /// im not sure why this works, but + /// based on small tests, it seems + /// to work fine i'll find out soon + /// enough if it doesn't + RETURN_IF_ERROR(EXPR); + } else { + continue_loop = false; + } + } + } + + node->value = EXPR.value(); + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, Type) { + json.section("Type") + .add("value", get_node_json(node.value)) + .add("generics", get_node_json(node.generics)) + .add("specifiers", node.specifiers.to_json()); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Expression, AsyncThreading) { + IS_NOT_EMPTY; + // := ('await' | 'spawn' | 'thread') E + + token::Token tok = CURRENT_TOK; + +#define ASYNC_THREADING_OPS {token::KEYWORD_AWAIT, token::KEYWORD_SPAWN, token::KEYWORD_THREAD} + + IS_IN_EXCEPTED_TOKENS(ASYNC_THREADING_OPS); + iter.advance(); // skip 'await', 'spawn' or 'thread' + +#undef ASYNC_THREADING_OPS + + ParseResult<> expr = parse(); + RETURN_IF_ERROR(expr); + + return make_node(expr.value(), tok); +} + +AST_NODE_IMPL_VISITOR(Jsonify, AsyncThreading) { + json.section("AsyncThreading") + .add("value", get_node_json(node.value)) + .add("type", (int)node.type); +} + +// ---------------------------------------------------------------------------------------------- // + +bool is_excepted(const token::Token &tok, const std::unordered_set &tokens) { + return tokens.find(tok.token_kind()) != tokens.end(); +} + +int get_precedence(const token::Token &tok) { + switch (tok.token_kind()) { + case token::OPERATOR_MUL: + case token::OPERATOR_DIV: + case token::OPERATOR_MOD: + case token::OPERATOR_POW: + return 12; + + case token::OPERATOR_ADD: + case token::OPERATOR_SUB: + return 11; + + case token::OPERATOR_BITWISE_L_SHIFT: + case token::OPERATOR_BITWISE_R_SHIFT: + return 10; + + case token::OPERATOR_GREATER_THAN_EQUALS: + case token::OPERATOR_LESS_THAN_EQUALS: + case token::PUNCTUATION_OPEN_ANGLE: + case token::PUNCTUATION_CLOSE_ANGLE: + return 9; + + case token::OPERATOR_EQUAL: + case token::OPERATOR_NOT_EQUAL: + return 8; + + case token::OPERATOR_BITWISE_AND: + return 7; + case token::OPERATOR_BITWISE_XOR: + return 6; + case token::OPERATOR_BITWISE_OR: + return 5; + case token::OPERATOR_LOGICAL_AND: + return 4; + case token::OPERATOR_LOGICAL_OR: + // MISSING ?: + return 3; + case token::OPERATOR_RANGE_INCLUSIVE: + case token::OPERATOR_RANGE: + return 2; + + case token::OPERATOR_ADD_ASSIGN: + case token::OPERATOR_SUB_ASSIGN: + case token::OPERATOR_MUL_ASSIGN: + case token::OPERATOR_DIV_ASSIGN: + case token::OPERATOR_MOD_ASSIGN: + case token::OPERATOR_ASSIGN: + return 1; + + default: + return 0; // Return 0 for non-binary operators + } +} + +bool is_ffi_specifier(const token::Token &tok) { + return is_excepted(tok, + {token::KEYWORD_CLASS, + token::KEYWORD_INTERFACE, + token::KEYWORD_STRUCT, + token::KEYWORD_ENUM, + token::KEYWORD_UNION, + token::KEYWORD_TYPE}); +}; + +bool is_type_qualifier(const token::Token &tok) { + return is_excepted(tok, + {token::KEYWORD_CONST, + token::KEYWORD_MODULE, + token::KEYWORD_YIELD, + token::KEYWORD_ASYNC, + token::KEYWORD_FFI, + token::KEYWORD_STATIC, + token::KEYWORD_MACRO}); +}; + +bool is_access_specifier(const token::Token &tok) { + return is_excepted(tok, + {token::KEYWORD_PUBLIC, + token::KEYWORD_PRIVATE, + token::KEYWORD_PROTECTED, + token::KEYWORD_INTERNAL}); +}; + +bool is_function_specifier(const token::Token &tok) { + return is_excepted(tok, + {token::KEYWORD_INLINE, + token::KEYWORD_ASYNC, + token::KEYWORD_STATIC, + token::KEYWORD_CONST, + token::KEYWORD_EVAL}); +}; + +bool is_function_qualifier(const token::Token &tok) { + return is_excepted(tok, + {token::KEYWORD_DEFAULT, + token::KEYWORD_PANIC, + token::KEYWORD_DELETE, + token::KEYWORD_CONST}); +}; + +bool is_storage_specifier(const token::Token &tok) { + return is_excepted( + tok, + {token::KEYWORD_FFI, token::KEYWORD_STATIC, token::KEYWORD_ASYNC, token::KEYWORD_EVAL}); +}; \ No newline at end of file diff --git a/source/parser/ast/source/nodes/States.cc b/source/parser/ast/source/nodes/States.cc new file mode 100644 index 0000000..34b0751 --- /dev/null +++ b/source/parser/ast/source/nodes/States.cc @@ -0,0 +1,1279 @@ +//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). You // +// are allowed to use, modify, redistribute, and create derivative works, even for commercial // +// purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// +/// /// +/// @file States.cc /// +/// @brief This file contains the entire logic to parse statements using a recursive descent /// +/// parser. the parser adheres to an ll(1) grammar, which means it processes the input /// +/// left-to-right and constructs the leftmost derivation using one token of lookahead. /// +/// /// +/// The parser is implemented using the `parse` method, which is a recursive descent parser /// +/// that uses the token list to parse the Statement grammar. /// +/// /// +/// @code /// +/// Statement state(tokens); /// +/// ParseResult<> node = state.parse(); /// +/// /// +/// if (node.has_value()) { /// +/// NodeT<> ast = node.value(); /// +/// } else { /// +/// std::cerr << node.error().what() << std::endl; /// +/// } /// +/// @endcode /// +/// /// +/// By default, the parser will parse the entire statement, but you can also parse a specific /// +/// statement by calling the specific parse method. or get a specific node by calling parse /// +/// and then passing a template argument to the method. /// +/// /// +/// @code /// +/// Statement state(tokens); /// +/// ParseResult node = state.parse(); /// +/// @endcode /// +/// /// +/// The parser is implemented using the following grammar: /// +/// /// +/// STS * /* node types */ /// +/// [x] * Literal * L /// +/// [x] * Operator * O /// +/// [x] * Token * T /// +/// [x] * Statement * E /// +/// /// +/// STS * /* statement types */ /// +/// [x] * BreakState * 'break' ';' /// +/// [x] * ContinueState * 'continue' ';' /// +/// [x] * ExprState * E ';' /// +/// [x] * BlockState * '{' Statement* '}' /// +/// [x] * SuiteState * BlockState | (':' Statement) /// +/// [x] * ReturnState * 'return' E? ';' /// +/// /// +/// [x] * YieldState * 'yield' E ';' /// +/// [x] * DeleteState * 'delete' E ';' /// +/// [x] * IfState * ('if' | 'unless') E SuiteState (ElseState)? /// +/// [x] * ElseState * 'else' SuiteState /// +/// [x] * WhileState * 'while' E SuiteState /// +/// [x] * ForState * 'for' ForPyStatementCore | ForCStatementCore SuiteState /// +/// [x] * ForPyStatementCore * NamedVarSpecifier 'in' E SuiteState /// +/// [x] * ForCStatementCore * (E)? ';' (E)? ';' (E)? SuiteState /// +/// [x] * NamedVarSpecifier * Ident (':' E)? /// +/// [x] * NamedVarSpecifierList * NamedVarSpecifier (',' NamedVarSpecifier)* /// +/// [x] * SwitchState * 'switch' E '{' SwitchCaseState* '}' /// +/// [x] * SwitchCaseState * 'case' E SuiteState | 'default' SuiteState /// +/// [x] * TryState * 'try' SuiteState (CatchState) (FinallyState)? /// +/// [x] * CatchState * 'catch' (NamedVarSpecifier (',' NamedVarSpecifier)*)? SuiteState /// +/// (CatchState | FinallyState)? /// +/// [x] * FinallyState * 'finally' SuiteState /// +/// [x] * PanicState * 'panic' ';' /// +/// /// +/// [ ] * ImportState * 'import' (SingleImportState | MultiImportState) /// +/// [ ] * AliasState * Ident 'as' Ident ';' /// +/// [ ] * SingleImportState * Ident (',' Ident)* /// +/// [ ] * MultiImportState * Ident 'as' Ident (',' Ident 'as' Ident)* /// +/// /// +//===-----------------------------------------------------------------------------------------====// + +// if import is passed, as soon as its been parsed spwan a new thread to parse the import ast and +// get symbols store symbols to to global symbols vec, while parsing set 'found import ...' (so if +// the parser comes accross the same import it can skip it) and also set 'being parsed to true' so +// that when we get to symbol resolution we can wait for the thread to finish or timeout + +/** GPT response for the above comment: +### Objective: +- When an `import` statement is encountered during parsing, you want to process it in a separate +thread to: + 1. Parse the AST (Abstract Syntax Tree) of the imported module. + 2. Extract the symbols (e.g., functions, variables, types) from the imported module. + 3. Store the imported symbols in a global symbol table for use in the main parsing process. + +- The system needs to handle the import efficiently by tracking which imports have already been +processed and managing potential race conditions with symbol resolution. + +### Detailed Explanation: + +1. **Import Parsing**: + - When the parser encounters an `import` statement, it immediately spawns a new thread to process +that import. + - This separate thread will: + 1. Parse the imported module's source code into its own AST. + 2. Extract the relevant symbols (functions, variables, etc.) from the AST. + 3. Add those symbols to a global symbol table so the main parser can reference them. + +2. **Global Symbol Table**: + - The global symbol table is a shared resource that stores symbols from all imported modules. + - This table will help avoid redundant imports (i.e., if the same module is imported multiple +times, it is parsed only once). + - The symbols from the import need to be safely added to this global table by the thread handling +the import. + +3. **Handling Duplicates**: + - You want to keep track of imports that are in progress or already completed: + - **Tracking Imports**: When an `import` statement is encountered, the parser checks a list (or +map) of imports to see if the module has already been imported. + - **Skipping Duplicate Imports**: If the module has already been imported or is currently being +processed in another thread, the parser can skip creating a new thread and move on. + - **Marking Imports**: As soon as an import starts processing, mark it as `being parsed` to +prevent other threads or the main parser from redundantly processing the same import. + +4. **Concurrency with Threads**: + - Since the parsing of imports is done in parallel (in separate threads), it's crucial to manage +these threads: + - **Waiting for Threads**: When the main parser reaches the symbol resolution stage (i.e., when +it needs to use symbols from the imported module), it should check if the thread parsing the import +has finished. If not, it waits for the thread to finish or times out after a certain period. + - **Timeout Mechanism**: The timeout ensures that if an import takes too long to parse (due to +errors or large files), the main parser doesn’t hang indefinitely. + +### Steps Summary: + +1. **Encounter Import**: + - When an `import` statement is found, check if this module is already in the global symbol + table. + - If it is, skip it. + - If not, spawn a new thread to: + 1. Parse the module. + 2. Extract the symbols. + 3. Add those symbols to the global symbol table. + +2. **Track Import Status**: + - Maintain a data structure that tracks the status of each import: + - **Not Found**: The module hasn’t been parsed yet. + - **Being Parsed**: A thread is currently parsing the module. + - **Parsed**: The module has been fully parsed, and its symbols are available. + +3. **Symbol Resolution**: + - When the main parser needs to resolve symbols from an imported module, it checks if the parsing + thread for that module has finished: + - If the thread is still running, wait for it to finish or use a timeout to prevent deadlocks. + - If the thread has finished, use the symbols it has added to the global symbol table. + +### Example Scenario: + +- **Step 1**: The parser encounters `import my_module`. +- **Step 2**: It checks if `my_module` is already in the global symbol table or currently being + parsed. + - If it’s not being parsed, spawn a new thread to parse `my_module`. + - Mark `my_module` as `being parsed`. +- **Step 3**: The thread for `my_module` parses the module and extracts symbols like `my_func` and + `my_var`. + - These symbols are added to the global symbol table. + - Mark `my_module` as `parsed`. +- **Step 4**: When the parser later encounters a reference to `my_func` from `my_module`, it checks + the symbol table: + - If the `my_module` thread is still running, the parser waits or times out. + - If the thread has completed, the parser resolves `my_func` from the global symbol table. + +### Important Considerations: +- **Concurrency**: Since multiple threads may be accessing and modifying the global symbol table, + ensure thread-safe operations (e.g., using mutexes or locks). +- **Timeout**: You need to decide how long the main parser will wait for an import thread before + timing out. +- **Error Handling**: If the import thread fails (e.g., due to a syntax error in the imported + module), ensure that the parser can handle this gracefully, perhaps by + skipping the faulty module or logging an error. + +This design improves parsing performance by handling imports concurrently but also ensures that the +symbols from the imports are available when needed for resolution. + */ + +#include +#include +#include +#include +#include +#include + +#include "neo-pprint/include/hxpprint.hh" +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/config/AST_generate.hh" +#include "parser/ast/include/config/case_types.def" +#include "parser/ast/include/core/AST_nodes.hh" +#include "parser/ast/include/nodes/AST_Expressions.hh" +#include "parser/ast/include/nodes/AST_Statements.hh" +#include "parser/ast/include/types/AST_jsonify_visitor.hh" +#include "parser/ast/include/types/AST_types.hh" +#include "token/include/generate.hh" +#include "token/include/token.hh" +#include "token/include/token_list.hh" + +// ---------------------------------------------------------------------------------------------- // + +bool is_excepted(const token::Token &tok, const std::unordered_set &tokens); +std::vector get_modifiers(token::TokenList::TokenListIter &iter); +bool is_ffi_specifier(const token::Token &tok); +bool is_type_qualifier(const token::Token &tok); +bool is_access_specifier(const token::Token &tok); +bool is_function_specifier(const token::Token &tok); +bool is_function_qualifier(const token::Token &tok); +bool is_storage_specifier(const token::Token &tok); + +// ---------------------------------------------------------------------------------------------- // + +// REVALUATE: if a parse_primary is needed for statements or if it should be removed +// AST_BASE_IMPL(Statement, parse_primary) { // NOLINT(readability-function-cognitive-complexity) +// IS_NOT_EMPTY; +// NOT_IMPLEMENTED; +// } + +// ---------------------------------------------------------------------------------------------- // + +AST_BASE_IMPL(Statement, parse) { // NOLINT(readability-function-cognitive-complexity) + IS_NOT_EMPTY; /// simple macro to check if the iterator is empty, expands to: + /// if(iter.remaining_n() == 0) { return std::unexpected(...); } + + token::Token tok = CURRENT_TOK; /// get the current token from the iterator + // modifiers = get_modifiers(iter); /// get the modifiers for the statement + + switch (tok.token_kind()) { + // TODO: case token::KEYWORD_IMPORT + case token::KEYWORD_IF: + case token::KEYWORD_UNLESS: + return parse_IfState(); + + case token::KEYWORD_RETURN: + return parse_ReturnState(); + + case token::KEYWORD_FOR: + return parse_ForState(); + + case token::KEYWORD_WHILE: + return parse_WhileState(); + + case token::KEYWORD_BREAK: + return parse_BreakState(); + + case token::KEYWORD_CONTINUE: + return parse_ContinueState(); + + case token::KEYWORD_SWITCH: + return parse_SwitchState(); + + case token::KEYWORD_TRY: + return parse_TryState(); + + case token::KEYWORD_PANIC: + return parse_PanicState(); + + case token::KEYWORD_FINALLY: + return parse_FinallyState(); + + case token::KEYWORD_YIELD: + return parse_YieldState(); + + case token::KEYWORD_DELETE: + return parse_DeleteState(); + + case token::KEYWORD_ELSE: + return std::unexpected(PARSE_ERROR( + CURRENT_TOK, "found dangling 'else' without a matching 'if' or 'unless'")); + + case token::KEYWORD_CASE: + return std::unexpected( + PARSE_ERROR(CURRENT_TOK, "found dangling 'case' without a matching 'switch'")); + + case token::KEYWORD_DEFAULT: + return std::unexpected( + PARSE_ERROR(CURRENT_TOK, "found dangling 'default' without a matching 'switch'")); + + case token::KEYWORD_CATCH: + return std::unexpected( + PARSE_ERROR(CURRENT_TOK, "found dangling 'catch' without a matching 'try'")); + + default: + return parse_ExprState(); + } +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, NamedVarSpecifier, bool force_type) { + IS_NOT_EMPTY; + + // := Ident (':' Type)? + + ParseResult path = expr_parser.parse(); + RETURN_IF_ERROR(path); + + if (force_type) { + if (path.value()->name.value() == "self") { + return make_node(path.value()); + } + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_COLON); + } + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_COLON)) { + iter.advance(); // skip ':' + + ParseResult type = expr_parser.parse(); + RETURN_IF_ERROR(type); + + return make_node(path.value(), type.value()); + } + + return make_node(path.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, NamedVarSpecifier) { + json.section("NamedVarSpecifier") + .add("path", get_node_json(node.path)) + .add("type", get_node_json(node.type)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, NamedVarSpecifierList, bool force_type) { + IS_NOT_EMPTY; + + // := NamedVarSpecifier (',' NamedVarSpecifier)* + + NodeT node = make_node(true); + + if (CURRENT_TOKEN_IS_NOT(token::IDENTIFIER)) { + return std::unexpected( + PARSE_ERROR(CURRENT_TOK, + "expected an identifier for the variable name, but found: " + + CURRENT_TOK.token_kind_repr())); + } + + ParseResult var = parse(force_type); + RETURN_IF_ERROR(var); + + node->vars.emplace_back(var.value()); + + while (CURRENT_TOKEN_IS(token::PUNCTUATION_COMMA)) { + iter.advance(); // skip ',' + + ParseResult next_var = parse(force_type); + RETURN_IF_ERROR(next_var); + + node->vars.emplace_back(next_var.value()); + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, NamedVarSpecifierList) { + std::vector vars; + + for (const auto &var : node.vars) { + vars.push_back(get_node_json(var)); + } + + json.section("NamedVarSpecifierList", vars); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, ForPyStatementCore, bool skip_start) { + IS_NOT_EMPTY; + // := NamedVarSpecifier* 'in' E SuiteState + + bool except_closing_paren = false; + token::Token starting_tok; + NodeT node = make_node(true); + + if (!skip_start) { + IS_EXCEPTED_TOKEN(token::KEYWORD_FOR); + iter.advance(); // skip 'for' + } + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_OPEN_PAREN)) { + except_closing_paren = true; + starting_tok = CURRENT_TOK; + iter.advance(); // skip '(' + } + + // vars can be untyped + ParseResult vars = parse(false); + RETURN_IF_ERROR(vars); + + node->vars = vars.value(); + + IS_EXCEPTED_TOKEN(token::KEYWORD_IN); + node->in_marker = CURRENT_TOK; + iter.advance(); // skip 'in' + + ParseResult<> range = expr_parser.parse(); + RETURN_IF_ERROR(range); + + if (except_closing_paren) { + if (CURRENT_TOKEN_IS_NOT(token::PUNCTUATION_CLOSE_PAREN)) { + return std::unexpected(PARSE_ERROR(starting_tok, + "expected ')' to close the for loop, but found: " + + CURRENT_TOK.token_kind_repr())); + } + + iter.advance(); // skip ')' + } + + ParseResult body = parse(); + RETURN_IF_ERROR(body); + + node->range = range.value(); + node->body = body.value(); + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ForPyStatementCore) { + json.section("ForPyStatementCore") + .add("range", get_node_json(node.range)) + .add("body", get_node_json(node.body)) + .add("in_marker", node.in_marker) + .add("vars", get_node_json(node.vars)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, ForCStatementCore, bool skip_start) { + IS_NOT_EMPTY; + // := (S)? ';' (E)? ';' (E)? SuiteState + + bool except_closing_paren = false; + + token::Token starting_tok; + NodeT node = make_node(true); + + if (!skip_start) { + if (CURRENT_TOKEN_IS(token::KEYWORD_FOR)) { + iter.advance(); // skip 'for' + } + } + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_OPEN_PAREN)) { // '(' + except_closing_paren = true; + starting_tok = CURRENT_TOK; + iter.advance(); // skip '(' + } + + if (CURRENT_TOKEN_IS_NOT(token::PUNCTUATION_SEMICOLON)) { + ParseResult<> init = parse(); + RETURN_IF_ERROR(init); + + node->init = init.value(); // next semi colon has been skipped + } else { + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); // skip ';' + } + + // first semi colon is skipped + + if (CURRENT_TOKEN_IS_NOT(token::PUNCTUATION_SEMICOLON)) { + ParseResult<> condition = expr_parser.parse(); + RETURN_IF_ERROR(condition); + + node->condition = condition.value(); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); // skip ';' - 2 + } else { + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); // skip ';' - 2 + } + + if (CURRENT_TOKEN_IS_NOT(token::PUNCTUATION_OPEN_BRACE) && + CURRENT_TOKEN_IS_NOT(token::PUNCTUATION_COLON)) { + // update condition + ParseResult<> update = expr_parser.parse(); + RETURN_IF_ERROR(update); + + node->update = update.value(); + } // no semicolon after this + + if (except_closing_paren) { + if (CURRENT_TOKEN_IS_NOT(token::PUNCTUATION_CLOSE_PAREN)) { + return std::unexpected(PARSE_ERROR(starting_tok, + "expected ')' to close the for loop, but found: " + + CURRENT_TOK.token_kind_repr())); + } + + iter.advance(); // skip ')' + } + + ParseResult body = parse(); + RETURN_IF_ERROR(body); + + node->body = body.value(); + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ForCStatementCore) { + json.section("ForCStatementCore") + .add("init", get_node_json(node.init)) + .add("condition", get_node_json(node.condition)) + .add("update", get_node_json(node.update)) + .add("body", get_node_json(node.body)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, ForState) { + IS_NOT_EMPTY; + + // := 'for' ForPyStatementCore | ForCStatementCore SuiteState + + bool except_closing_paren = false; + + IS_EXCEPTED_TOKEN(token::KEYWORD_FOR); + iter.advance(); // skip 'for' + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_OPEN_PAREN)) { + except_closing_paren = true; + iter.advance(); // skip '(' + } + + /// here we can do a few checs now to see if we are parsing a python or c style for loop + /// if the curent token is not a ident we are in a c style loop + /// if the token is a ident then parse a NamedVarSpecifier* then if theres 'in' then its a + /// python style loop + + if (CURRENT_TOKEN_IS_NOT(token::IDENTIFIER)) { + c_style_for: + if (except_closing_paren) { + iter.reverse(); // go back to the '(' + } + + ParseResult c_for = parse(true); + RETURN_IF_ERROR(c_for); + + return make_node(c_for.value(), ForState::ForType::C); + } + + // if we dont have (',' | ':' | 'in') then we are in a c style loop + if (iter.peek().has_value() && (NEXT_TOK.token_kind() != token::PUNCTUATION_COMMA && + NEXT_TOK.token_kind() != token::PUNCTUATION_COLON && + NEXT_TOK.token_kind() != token::KEYWORD_IN)) { + goto c_style_for; + } + + if (except_closing_paren) { + iter.reverse(); // go back to the '(' + } + + ParseResult py_for = parse(true); + RETURN_IF_ERROR(py_for); + + return make_node(py_for.value(), ForState::ForType::Python); +} + +AST_NODE_IMPL_VISITOR(Jsonify, ForState) { + json.section("ForState").add("core", get_node_json(node.core)).add("type", (int)node.type); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, WhileState) { + IS_NOT_EMPTY; + // := 'while' E SuiteState + + IS_EXCEPTED_TOKEN(token::KEYWORD_WHILE); + iter.advance(); // skip 'while' + + ParseResult<> condition = expr_parser.parse(); + RETURN_IF_ERROR(condition); + + ParseResult body = parse(); + RETURN_IF_ERROR(body); + + return make_node(condition.value(), body.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, WhileState) { + json.section("WhileState") + .add("condition", get_node_json(node.condition)) + .add("body", get_node_json(node.body)); +} + +// ---------------------------------------------------------------------------------------------- // + +/* TODO: REFACTOR */ +AST_NODE_IMPL(Statement, ElseState) { + IS_NOT_EMPTY; + + // := ('else' Suite) | ('else' ('if' | 'unless') E Suite) + + NodeT node = make_node(true); + + IS_EXCEPTED_TOKEN(token::KEYWORD_ELSE); + iter.advance(); // skip 'else' + + if (CURRENT_TOKEN_IS(token::KEYWORD_IF) || CURRENT_TOKEN_IS(token::KEYWORD_UNLESS)) { + node->type = CURRENT_TOKEN_IS(token::KEYWORD_IF) ? ElseState::ElseType::ElseIf + : ElseState::ElseType::ElseUnless; + iter.advance(); // skip 'if' | 'unless' + + ParseResult<> expr = expr_parser.parse(); + RETURN_IF_ERROR(expr); + + node->condition = expr.value(); + } + + ParseResult body = parse(); + RETURN_IF_ERROR(body); + + node->body = body.value(); + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ElseState) { + json.section("ElseState") + .add("condition", get_node_json(node.condition)) + .add("body", get_node_json(node.body)) + .add("type", (int)node.type); +} + +// ---------------------------------------------------------------------------------------------- // + +/* TODO: REFACTOR */ +AST_NODE_IMPL(Statement, IfState) { + IS_NOT_EMPTY; + + // := ('if' | 'unless') E SuiteState (ElseState*)? + + NodeT node; + bool is_unless = false; + +#define IF_UNLESS_TOKENS {token::KEYWORD_IF, token::KEYWORD_UNLESS} + IS_IN_EXCEPTED_TOKENS(IF_UNLESS_TOKENS); + if (CURRENT_TOKEN_IS(token::KEYWORD_UNLESS)) { + is_unless = true; + } + + iter.advance(); // skip 'if' or 'unless' +#undef IF_UNLESS_TOKENS + + ParseResult<> condition = expr_parser.parse(); + RETURN_IF_ERROR(condition); + + node = make_node(condition.value()); + + if (is_unless) { + node->type = IfState::IfType::Unless; + } + + ParseResult body = parse(); + RETURN_IF_ERROR(body); + + node->body = body.value(); + + if CURRENT_TOKEN_IS (token::KEYWORD_ELSE) { + bool captured_final_else = false; + token::Token starting_else; + + ParseResult else_body = parse(); + RETURN_IF_ERROR(else_body); + + node->else_body.emplace_back(else_body.value()); + + if (else_body.value()->type == ElseState::ElseType::Else) { + captured_final_else = true; + } + + while (CURRENT_TOKEN_IS(token::KEYWORD_ELSE)) { + starting_else = CURRENT_TOK; + + else_body = parse(); + RETURN_IF_ERROR(else_body); + + node->else_body.emplace_back(else_body.value()); + + if (else_body.value()->type == ElseState::ElseType::Else) { + if (captured_final_else) { + return std::unexpected( + PARSE_ERROR(starting_else, "redefinition of captured else block")); + } + + captured_final_else = true; + } + } + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, IfState) { + std::vector else_body; + + for (const auto &else_state : node.else_body) { + else_body.push_back(get_node_json(else_state)); + } + + json.section("IfState") + .add("condition", get_node_json(node.condition)) + .add("body", get_node_json(node.body)) + .add("else_body", else_body) + .add("type", (int)node.type); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, SwitchCaseState) { + IS_NOT_EMPTY; + // := ('case' E SuiteState) | 'default' SuiteState + + token::Token marker; + + if (CURRENT_TOKEN_IS(token::KEYWORD_CASE)) { + marker = CURRENT_TOK; + iter.advance(); // skip 'case' + + ParseResult<> expr = expr_parser.parse(); + RETURN_IF_ERROR(expr); + + // if thres a fallthorugh + if (CURRENT_TOKEN_IS(token::PUNCTUATION_COLON)) { + if (iter.peek().has_value() && NEXT_TOK.token_kind() == token::KEYWORD_CASE) { + iter.advance(); // skip ':' + return make_node( + expr.value(), nullptr, SwitchCaseState::CaseType::Fallthrough, marker); + } + } + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_OPEN_BRACE)) { + if (iter.peek().has_value() && + NEXT_TOK.token_kind() == token::PUNCTUATION_CLOSE_BRACE) { + return std::unexpected(PARSE_ERROR( + CURRENT_TOK, "mssing statement, if you want to fallthrough use ':'")); + } + } + + ParseResult body = parse(); + RETURN_IF_ERROR(body); + + return make_node( + expr.value(), body.value(), SwitchCaseState::CaseType::Case, marker); + } + + if (CURRENT_TOKEN_IS(token::KEYWORD_DEFAULT)) { + marker = CURRENT_TOK; + iter.advance(); // skip 'default' + + ParseResult body = parse(); + RETURN_IF_ERROR(body); + + return make_node( + nullptr, body.value(), SwitchCaseState::CaseType::Default, marker); + } + +#define DEFAULT_CASE_TOKENS {token::KEYWORD_CASE, token::KEYWORD_DEFAULT} + IS_IN_EXCEPTED_TOKENS(DEFAULT_CASE_TOKENS); +#undef DEFAULT_CASE_TOKENS + + return std::unexpected(PARSE_ERROR(CURRENT_TOK, + "should have never gotten this error, something is fucked." + + CURRENT_TOK.token_kind_repr())); +} + +AST_NODE_IMPL_VISITOR(Jsonify, SwitchCaseState) { + json.section("SwitchCaseState") + .add("condition", get_node_json(node.condition)) + .add("body", get_node_json(node.body)) + .add("type", (int)node.type) + .add("marker", node.marker); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, SwitchState) { + IS_NOT_EMPTY; + // := 'switch' expr (('{' SwitchCaseState* '}') | (':' SwitchCaseState*)) + + IS_EXCEPTED_TOKEN(token::KEYWORD_SWITCH); + iter.advance(); // skip 'switch' + + token::Token starting_token; // '(', ')' + token::Token first_token; // 'default' + bool expecting_brace_close = false; + bool found_default = false; + + ParseResult<> expr = expr_parser.parse(); + RETURN_IF_ERROR(expr); + +#define SUITE_TOKENS {token::PUNCTUATION_OPEN_BRACE, token::PUNCTUATION_COLON} + IS_IN_EXCEPTED_TOKENS(SUITE_TOKENS) +#undef SUITE_TOKENS + + if CURRENT_TOKEN_IS (token::PUNCTUATION_OPEN_BRACE) { + expecting_brace_close = true; + starting_token = CURRENT_TOK; + } + + iter.advance(); // skip '{' | ':' + + NodeT node = make_node(expr.value()); + + ParseResult case_state = parse(); + RETURN_IF_ERROR(case_state); + + node->cases.emplace_back(case_state.value()); + + if (case_state.value()->type == SwitchCaseState::CaseType::Default) { + found_default = true; + first_token = case_state.value()->marker; + } + + while (CURRENT_TOKEN_IS(token::KEYWORD_CASE) || CURRENT_TOKEN_IS(token::KEYWORD_DEFAULT)) { + case_state = parse(); + RETURN_IF_ERROR(case_state); + + if (case_state.value()->type == SwitchCaseState::CaseType::Default) { + if (found_default) { + return std::unexpected( + PARSE_ERROR(case_state.value()->marker, + "redefinition of default case" /* TODO: INCLUDE PREV LOC TOO */)); + } + + found_default = true; + } + + node->cases.emplace_back(case_state.value()); + } + + if (expecting_brace_close) { + if (iter.remaining_n() == 0 || iter.current().get() != token::PUNCTUATION_CLOSE_BRACE) { + return std::unexpected( + PARSE_ERROR(starting_token, "expected '}' to close the switch block")); + } + + iter.advance(); // skip '}' + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, SwitchState) { + std::vector cases; + + for (const auto &case_state : node.cases) { + cases.push_back(get_node_json(case_state)); + } + + json.section("SwitchState").add("condition", get_node_json(node.condition)).add("cases", cases); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, YieldState) { + IS_NOT_EMPTY; + + IS_EXCEPTED_TOKEN(token::KEYWORD_YIELD); + iter.advance(); + + ParseResult<> expr = expr_parser.parse(); + RETURN_IF_ERROR(expr); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); + + return make_node(expr.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, YieldState) { + json.section("YieldState", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, DeleteState) { + IS_NOT_EMPTY; + + IS_EXCEPTED_TOKEN(token::KEYWORD_DELETE); + iter.advance(); + + ParseResult<> expr = expr_parser.parse(); + RETURN_IF_ERROR(expr); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); + + return make_node(expr.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, DeleteState) { + json.section("DeleteState", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, AliasState) { + IS_NOT_EMPTY; + NOT_IMPLEMENTED; +} + +AST_NODE_IMPL_VISITOR(Jsonify, AliasState) { json.section("AliasState"); } + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, SingleImportState) { + IS_NOT_EMPTY; + NOT_IMPLEMENTED; +} + +AST_NODE_IMPL_VISITOR(Jsonify, SingleImportState) { json.section("SingleImportState"); } + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, MultiImportState) { + IS_NOT_EMPTY; + NOT_IMPLEMENTED; +} + +AST_NODE_IMPL_VISITOR(Jsonify, MultiImportState) { json.section("MultiImportState"); } + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, ImportState) { + IS_NOT_EMPTY; + NOT_IMPLEMENTED; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ImportState) { json.section("ImportState"); } + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, ReturnState) { + IS_NOT_EMPTY; + + IS_EXCEPTED_TOKEN(token::KEYWORD_RETURN); + iter.advance(); // skip 'return' + + ParseResult<> expr = expr_parser.parse(); + RETURN_IF_ERROR(expr); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); // skip ';' + + return make_node(expr.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, ReturnState) { + json.section("ReturnState", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, BreakState) { + IS_NOT_EMPTY; + + IS_EXCEPTED_TOKEN(token::KEYWORD_BREAK); + NodeT node = make_node(CURRENT_TOK); + + iter.advance(); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, BreakState) { + json.section("BreakState", node.marker); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, ContinueState) { + IS_NOT_EMPTY; + + IS_EXCEPTED_TOKEN(token::KEYWORD_CONTINUE); + NodeT node = make_node(CURRENT_TOK); + + iter.advance(); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, ContinueState) { + json.section("ContinueState", node.marker); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, ExprState) { + IS_NOT_EMPTY; + + ParseResult<> expr = expr_parser.parse(); + RETURN_IF_ERROR(expr); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); + + return make_node(expr.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, ExprState) { + json.section("ExprState", get_node_json(node.value)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, SuiteState) { + IS_NOT_EMPTY; + + // := BlockState | (':' Statement) + + if CURRENT_TOKEN_IS (token::PUNCTUATION_OPEN_BRACE) { + ParseResult block = parse(); + RETURN_IF_ERROR(block); + + return make_node(block.value()); + } + + if CURRENT_TOKEN_IS (token::PUNCTUATION_COLON) { + iter.advance(); // skip ':' + + Declaration decl_parser(iter); + + ParseResult<> decl = decl_parser.parse(); + RETURN_IF_ERROR(decl); + + + NodeT block = make_node(NodeV<>{decl.value()}); + return make_node(block); + } + + return std::unexpected( + PARSE_ERROR(CURRENT_TOK, + "expected a suite block or a single statement, '{' or ':', but found: " + + CURRENT_TOK.token_kind_repr())); +} + +AST_NODE_IMPL_VISITOR(Jsonify, SuiteState) { + json.section("SuiteState", get_node_json(node.body)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, BlockState) { + IS_NOT_EMPTY; + // := '{' Statement* '}' + + NodeV<> body; + token::Token starting_tok; + Declaration decl_parser(iter); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_OPEN_BRACE); + starting_tok = CURRENT_TOK; + iter.advance(); // skip '{' + + while (CURRENT_TOKEN_IS_NOT( + token::PUNCTUATION_CLOSE_BRACE)) { // TODO: implement this kind of bounds checks for all + // the pair token parsers '(', '[', '{'. + ParseResult<> decl = decl_parser.parse(); + RETURN_IF_ERROR(decl); + + body.push_back(decl.value()); + } + + if (iter.remaining_n() == 0) { + return std::unexpected( + PARSE_ERROR(starting_tok, "expected '}' to close the block, but found EOF")); + } + + iter.advance(); // skip '}' + return make_node(body); +} + +AST_NODE_IMPL_VISITOR(Jsonify, BlockState) { + std::vector body_json; + + for (const auto &node : node.body) { + body_json.push_back(get_node_json(node)); + } + + json.section("BlockState", body_json); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, TryState) { + IS_NOT_EMPTY; + + // := 'try' SuiteState (CatchState)* (FinallyState)? + + NodeT node; + + IS_EXCEPTED_TOKEN(token::KEYWORD_TRY); + iter.advance(); // skip 'try' + + ParseResult body = parse(); + RETURN_IF_ERROR(body); + + node = make_node(body.value()); + + if CURRENT_TOKEN_IS (token::KEYWORD_FINALLY) { + ParseResult finally_state = parse(); + RETURN_IF_ERROR(finally_state); + + node->no_catch = true; + node->finally_state = finally_state.value(); + + return node; + } + + IS_EXCEPTED_TOKEN(token::KEYWORD_CATCH); + + ParseResult catch_state = parse(); + RETURN_IF_ERROR(catch_state); + + node->catch_states.emplace_back(catch_state.value()); + + while + CURRENT_TOKEN_IS(token::KEYWORD_CATCH) { + ParseResult next_catch = parse(); + RETURN_IF_ERROR(next_catch); + + node->catch_states.emplace_back(next_catch.value()); + } + + if CURRENT_TOKEN_IS (token::KEYWORD_FINALLY) { + ParseResult finally_state = parse(); + RETURN_IF_ERROR(finally_state); + + node->finally_state = finally_state.value(); + } + + return node; +} + +AST_NODE_IMPL_VISITOR(Jsonify, TryState) { + std::vector catch_states; + + for (const auto &catch_state : node.catch_states) { + catch_states.push_back(get_node_json(catch_state)); + } + + json.section("TryState") + .add("body", get_node_json(node.body)) + .add("catches", catch_states) + .add("finally", get_node_json(node.finally_state)) + .add("no_catch", (int)node.no_catch); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, CatchState) { + IS_NOT_EMPTY; + + // := 'catch' (NamedVarSpecifier) SuiteState (CatchState)? + + token::Token starting_tok; + bool except_closing_paren = false; + + IS_EXCEPTED_TOKEN(token::KEYWORD_CATCH); + iter.advance(); // skip 'catch' + + if (CURRENT_TOKEN_IS(token::PUNCTUATION_OPEN_PAREN)) { + except_closing_paren = true; + starting_tok = CURRENT_TOK; + iter.advance(); // skip '(' + } + + ParseResult catch_state = parse(true); + RETURN_IF_ERROR(catch_state); + + if (except_closing_paren) { + if (CURRENT_TOKEN_IS_NOT(token::PUNCTUATION_CLOSE_PAREN)) { + return std::unexpected( + PARSE_ERROR(starting_tok, + "expected ')' to close the catch block, but found: " + + CURRENT_TOK.token_kind_repr())); + } + + iter.advance(); // skip ')' + } + + ParseResult body = parse(); + RETURN_IF_ERROR(body); + + return make_node(catch_state.value(), body.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, CatchState) { + json.section("CatchState") + .add("catch", get_node_json(node.catch_state)) + .add("body", get_node_json(node.body)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, PanicState) { + IS_NOT_EMPTY; + + // := 'panic' E ';' + + IS_EXCEPTED_TOKEN(token::KEYWORD_PANIC); + iter.advance(); // skip 'panic' + + ParseResult<> expr = expr_parser.parse(); + RETURN_IF_ERROR(expr); + + IS_EXCEPTED_TOKEN(token::PUNCTUATION_SEMICOLON); + iter.advance(); // skip ';' + + return make_node(expr.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, PanicState) { + json.section("PanicState",get_node_json(node.expr)); +} + +// ---------------------------------------------------------------------------------------------- // + +AST_NODE_IMPL(Statement, FinallyState) { + IS_NOT_EMPTY; + + // := 'finally' SuiteState + + IS_EXCEPTED_TOKEN(token::KEYWORD_FINALLY); + iter.advance(); // skip 'finally' + + ParseResult body = parse(); + RETURN_IF_ERROR(body); + + return make_node(body.value()); +} + +AST_NODE_IMPL_VISITOR(Jsonify, FinallyState) { + json.section("FinallyState", get_node_json(node.body)); +} + +// ---------------------------------------------------------------------------------------------- // + +std::vector get_modifiers(token::TokenList::TokenListIter &iter) { + std::vector modifiers; + + while (iter.remaining_n() > 0) { + switch (iter->token_kind()) { + case token::KEYWORD_INLINE: + case token::KEYWORD_STATIC: + case token::KEYWORD_ASYNC: + case token::KEYWORD_EVAL: + case token::KEYWORD_PRIVATE: + case token::KEYWORD_CONST: + case token::KEYWORD_UNSAFE: + case token::KEYWORD_PUBLIC: + case token::KEYWORD_PROTECTED: + case token::KEYWORD_INTERNAL: + case token::LITERAL_COMPLIER_DIRECTIVE: + modifiers.push_back(CURRENT_TOK); + iter.advance(); + break; + default: + goto exit_loop; + } + } + +exit_loop: + return modifiers; +} \ No newline at end of file diff --git a/source/parser/ast/source/statements/AST_Assignment.cc b/source/parser/ast/source/statements/AST_Assignment.cc deleted file mode 100644 index 3d575df..0000000 --- a/source/parser/ast/source/statements/AST_Assignment.cc +++ /dev/null @@ -1,35 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -// Assignemnt := identifier = expresion; - -namespace parser::ast::node { -ParseResult Assignment::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool Assignment::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void Assignment::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_BreakStatement.cc b/source/parser/ast/source/statements/AST_BreakStatement.cc deleted file mode 100644 index d0c8dd7..0000000 --- a/source/parser/ast/source/statements/AST_BreakStatement.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult BreakStatement::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool BreakStatement::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void BreakStatement::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_ConditionalStatement.cc b/source/parser/ast/source/statements/AST_ConditionalStatement.cc deleted file mode 100644 index 70ff084..0000000 --- a/source/parser/ast/source/statements/AST_ConditionalStatement.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult ConditionalStatement::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool ConditionalStatement::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void ConditionalStatement::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_ContinueStatement.cc b/source/parser/ast/source/statements/AST_ContinueStatement.cc deleted file mode 100644 index 8f2b12f..0000000 --- a/source/parser/ast/source/statements/AST_ContinueStatement.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult ContinueStatement::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool ContinueStatement::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void ContinueStatement::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_ElseIfStatement.cc b/source/parser/ast/source/statements/AST_ElseIfStatement.cc deleted file mode 100644 index d6ec7b3..0000000 --- a/source/parser/ast/source/statements/AST_ElseIfStatement.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult ElseIfStatement::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool ElseIfStatement::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void ElseIfStatement::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_ElseStatement.cc b/source/parser/ast/source/statements/AST_ElseStatement.cc deleted file mode 100644 index c1e86a3..0000000 --- a/source/parser/ast/source/statements/AST_ElseStatement.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult ElseStatement::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool ElseStatement::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void ElseStatement::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_ForLoop.cc b/source/parser/ast/source/statements/AST_ForLoop.cc deleted file mode 100644 index d57d923..0000000 --- a/source/parser/ast/source/statements/AST_ForLoop.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult ForLoop::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool ForLoop::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void ForLoop::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_IfStatement.cc b/source/parser/ast/source/statements/AST_IfStatement.cc deleted file mode 100644 index 671c9d0..0000000 --- a/source/parser/ast/source/statements/AST_IfStatement.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult IfStatement::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool IfStatement::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void IfStatement::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_RangeLoop.cc b/source/parser/ast/source/statements/AST_RangeLoop.cc deleted file mode 100644 index 345164f..0000000 --- a/source/parser/ast/source/statements/AST_RangeLoop.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult RangeLoop::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool RangeLoop::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void RangeLoop::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_ReturnStatement.cc b/source/parser/ast/source/statements/AST_ReturnStatement.cc deleted file mode 100644 index 8e29f27..0000000 --- a/source/parser/ast/source/statements/AST_ReturnStatement.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult ReturnStatement::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool ReturnStatement::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void ReturnStatement::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_WhileLoop.cc b/source/parser/ast/source/statements/AST_WhileLoop.cc deleted file mode 100644 index e0adf77..0000000 --- a/source/parser/ast/source/statements/AST_WhileLoop.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult WhileLoop::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool WhileLoop::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void WhileLoop::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/AST_YieldStatement.cc b/source/parser/ast/source/statements/AST_YieldStatement.cc deleted file mode 100644 index 980e148..0000000 --- a/source/parser/ast/source/statements/AST_YieldStatement.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -namespace parser::ast::node { -ParseResult YieldStatement::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } - - return 0; -} - -bool YieldStatement::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void YieldStatement::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node diff --git a/source/parser/ast/source/statements/Statement.cc b/source/parser/ast/source/statements/Statement.cc deleted file mode 100644 index 96d7569..0000000 --- a/source/parser/ast/source/statements/Statement.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// // -//===-----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -#include "parser/ast/include/case_types.def" -#include "token/include/token_list.hh" - -namespace parser::ast { - -NodeT get_Statement(token::TokenList &tokens) { - for (auto &token : tokens) {} - - return nullptr; -} - -Statement::Statement() = default; -Statement::Statement(token::TokenList &tokens) - : Node(tokens) - , tokens(&tokens) {} -} // namespace __AST_BEGIN diff --git a/source/parser/ast/source/types/Type.cc b/source/parser/ast/source/types/Type.cc deleted file mode 100644 index a5316fa..0000000 --- a/source/parser/ast/source/types/Type.cc +++ /dev/null @@ -1,33 +0,0 @@ -//===------------------------------------------ C++ ------------------------------------------====// -// // -// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // -// You are allowed to use, modify, redistribute, and create derivative works, even for // -// commercial purposes, provided that you give appropriate credit, and indicate if changes // -// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // -// // -// SPDX-License-Identifier: CC-BY-4.0 // -// Copyright (c) 2024 (CC BY 4.0) // -// // -//====----------------------------------------------------------------------------------------====// -// // -// // -//===-----------------------------------------------------------------------------------------====// - -#include "parser/ast/include/AST.hh" - -#include "parser/ast/include/case_types.def" -#include "token/include/token_list.hh" - -namespace parser::ast { - -NodeT get_Type(token::TokenList &tokens) { - for (auto &token : tokens) {} - - return nullptr; -} - -Type::Type() = default; -Type::Type(token::TokenList &tokens) - : Node(tokens) - , tokens(&tokens) {} -} // namespace __AST_BEGIN diff --git a/source/parser/ast/source/expressions/AST_Cast.cc b/source/parser/ast/source/visitors/JsonifyVisitor.cc similarity index 74% rename from source/parser/ast/source/expressions/AST_Cast.cc rename to source/parser/ast/source/visitors/JsonifyVisitor.cc index 25d142e..018d68c 100644 --- a/source/parser/ast/source/expressions/AST_Cast.cc +++ b/source/parser/ast/source/visitors/JsonifyVisitor.cc @@ -10,24 +10,11 @@ // // //====----------------------------------------------------------------------------------------====// -#include "parser/ast/include/AST.hh" +#include "neo-json/include/json.hh" +#include "parser/ast/include/config/AST_config.def" +#include "parser/ast/include/types/AST_jsonify_visitor.hh" -namespace parser::ast::node { -ParseResult Cast::parse() { - if (tokens->empty()) [[unlikely]] { - return 0; - } +__AST_VISITOR_BEGIN { + void Jsonify::visit(const parser ::ast ::node ::GenericInvokePathExpr & /*unused*/) {} - return 0; -} - -bool Cast::test() { - if (tokens->empty()) [[unlikely]] { - return false; - } - return false; -} - -void Cast::accept(Visitor &visitor) const { visitor.visit(*this); } - -} // namespace __AST_BEGIN::node +} // namespace __AST_BEGIN diff --git a/source/parser/cpp/makefiles.py b/source/parser/cpp/makefiles.py new file mode 100644 index 0000000..7268fc7 --- /dev/null +++ b/source/parser/cpp/makefiles.py @@ -0,0 +1,75 @@ +exprs = [ + +] + +states = [ + +] + +annos = [ + +] + + + +data_to_write = ( +"""//===------------------------------------------ C++ ------------------------------------------====// +// // +// Part of the Helix Project, under the Attribution 4.0 International license (CC BY 4.0). // +// You are allowed to use, modify, redistribute, and create derivative works, even for // +// commercial purposes, provided that you give appropriate credit, and indicate if changes // +// were made. For more information, please visit: https://creativecommons.org/licenses/by/4.0/ // +// // +// SPDX-License-Identifier: CC-BY-4.0 // +// Copyright (c) 2024 (CC BY 4.0) // +// // +//====----------------------------------------------------------------------------------------====// + +#include "parser/ast/include/core/AST.hh" +#include "parser/ast/include/config/AST_config.def" + +__AST_NODE_BEGIN { +PARSE_SIG(\0REPLACE\0) { + if (tokens == nullptr || tokens->empty()) [[unlikely]] { + return 0; + } + + return 0; +} + +TEST_SIG(\0REPLACE\0) { + if (tokens == nullptr || tokens->empty()) [[unlikely]] { + return false; + } + return false; +} + +VISITOR_IMPL(\0REPLACE\0); +} // namespace __AST_NODE_BEGIN +""") + +import os + + +os.makedirs("expressions", exist_ok=True) +os.makedirs("statements", exist_ok=True) +os.makedirs("annotations", exist_ok=True) +os.makedirs("types", exist_ok=True) +os.makedirs("declarations", exist_ok=True) + +for file in exprs: + with open(f"expressions/AST_{file}.cc", "w") as f: + f.write(data_to_write.replace("\0REPLACE\0", file)) + print(f"Created file: {file}.cc") + +for file in states: + with open(f"statements/AST_{file}.cc", "w") as f: + f.write(data_to_write.replace("\0REPLACE\0", file)) + print(f"Created file: {file}.cc") + +for file in annos: + with open(f"annotations/AST_{file}.cc", "w") as f: + f.write(data_to_write.replace("\0REPLACE\0", file)) + print(f"Created file: {file}.cc") + +print("Done!") diff --git a/source/parser/ast/readme b/source/parser/cpp/readme similarity index 100% rename from source/parser/ast/readme rename to source/parser/cpp/readme diff --git a/source/token/enums/keywords.def b/source/token/enums/keywords.def index 515bd47..b132ef2 100644 --- a/source/token/enums/keywords.def +++ b/source/token/enums/keywords.def @@ -11,61 +11,74 @@ // //===------------------------------------------------------------------------------------------===// - #ifndef __KEYWORDS_DEF__ #define __KEYWORDS_DEF__ -#define KEYWORD_TOKENS_COUNT 47 +#define KEYWORD_TOKENS_COUNT 51 -#define KEYWORD_TOKENS(GENERATE) \ - GENERATE(KEYWORD_IF, "if" ) \ - GENERATE(KEYWORD_ELSE, "else" ) \ - GENERATE(KEYWORD_UNLESS, "unless" ) \ - GENERATE(KEYWORD_MACRO, "macro" ) \ - GENERATE(KEYWORD_DEFINE, "define" ) \ - GENERATE(KEYWORD_FUNCTION, "fn" ) \ - GENERATE(KEYWORD_OPERATOR, "op" ) \ - GENERATE(KEYWORD_INLINE, "inline" ) \ - GENERATE(KEYWORD_RETURN, "return" ) \ - GENERATE(KEYWORD_ENCLOSING, "enclosing") \ - GENERATE(KEYWORD_ASYNC, "async" ) \ - GENERATE(KEYWORD_SPAWN, "spawn" ) \ - GENERATE(KEYWORD_AWAIT, "await" ) \ - GENERATE(KEYWORD_THREAD, "thread" ) \ - GENERATE(KEYWORD_FOR, "for" ) \ - GENERATE(KEYWORD_WHILE, "while" ) \ - GENERATE(KEYWORD_BREAK, "break" ) \ - GENERATE(KEYWORD_CONTINUE, "continue" ) \ - GENERATE(KEYWORD_CASE, "case" ) \ - GENERATE(KEYWORD_MATCH, "match" ) \ - GENERATE(KEYWORD_SWITCH, "switch" ) \ - GENERATE(KEYWORD_DEFAULT, "default" ) \ - GENERATE(KEYWORD_ENUM, "enum" ) \ - GENERATE(KEYWORD_TYPE, "type" ) \ - GENERATE(KEYWORD_CLASS, "class" ) \ - GENERATE(KEYWORD_UNION, "union" ) \ - GENERATE(KEYWORD_STRUCT, "struct" ) \ - GENERATE(KEYWORD_ABSTRACT, "abstract" ) \ - GENERATE(KEYWORD_INTERFACE, "interface") \ - GENERATE(KEYWORD_IS, "is" ) \ - GENERATE(KEYWORD_TRY, "try" ) \ - GENERATE(KEYWORD_PANIC, "panic" ) \ - GENERATE(KEYWORD_CATCH, "catch" ) \ - GENERATE(KEYWORD_FINALLY, "finally" ) \ - GENERATE(KEYWORD_LET, "let" ) \ - GENERATE(KEYWORD_PRIVATE, "priv" ) \ - GENERATE(KEYWORD_AUTO, "auto" ) \ - GENERATE(KEYWORD_CONST, "const" ) \ - GENERATE(KEYWORD_GLOBAL, "global" ) \ - GENERATE(KEYWORD_FROM, "from" ) \ - GENERATE(KEYWORD_FFI, "ffi" ) \ - GENERATE(KEYWORD_IMPORT, "import" ) \ - GENERATE(KEYWORD_EXTERN, "extern" ) \ - GENERATE(KEYWORD_YIELD, "yield" ) \ - GENERATE(KEYWORD_AS, "as" ) \ - GENERATE(KEYWORD_DERIVES, "derives" ) \ - GENERATE(KEYWORD_MODULE, "module" ) +/// Key: Val +/// M : Modifier +/// S : Statement +/// D : Declaration +/// H : Helper +/// E : Expression +/// P : Preprocessor -// NOTE: IF THIS GENERATION IS CHANGED DO NOT FORGET TO UPDATE COUNT +/* TODO determine if is needs to be removed */ +#define KEYWORD_TOKENS(GENERATE) \ + /* S */ GENERATE(KEYWORD_IF, "if") \ + /* S */ GENERATE(KEYWORD_ELSE, "else") \ + /* S */ GENERATE(KEYWORD_UNLESS, "unless") \ + /*---- P ----*/ GENERATE(KEYWORD_MACRO, "macro") \ + /*---- P ----*/ GENERATE(KEYWORD_DEFINE, "define") \ + /* D */ GENERATE(KEYWORD_FUNCTION, "fn") \ + /* D */ GENERATE(KEYWORD_OPERATOR, "op") \ + /* M */ GENERATE(KEYWORD_INLINE, "inline") \ + /* M */ GENERATE(KEYWORD_STATIC, "static") \ + /* S */ GENERATE(KEYWORD_RETURN, "return") \ + /* M */ GENERATE(KEYWORD_ASYNC, "async") \ + /* E */ GENERATE(KEYWORD_SPAWN, "spawn") \ + /* E */ GENERATE(KEYWORD_AWAIT, "await") \ + /* E */ GENERATE(KEYWORD_THREAD, "thread") \ + /* S */ GENERATE(KEYWORD_FOR, "for") \ + /* S */ GENERATE(KEYWORD_WHILE, "while") \ + /* S */ GENERATE(KEYWORD_BREAK, "break") \ + /* S */ GENERATE(KEYWORD_CONTINUE, "continue") \ + /* H */ GENERATE(KEYWORD_CASE, "case") \ + /* S */ GENERATE(KEYWORD_MATCH, "match") \ + /* S */ GENERATE(KEYWORD_SWITCH, "switch") \ + /* H */ GENERATE(KEYWORD_DEFAULT, "default") \ + /* H */ GENERATE(KEYWORD_ENUM, "enum") \ + /* D */ GENERATE(KEYWORD_TYPE, "type") \ + /* M */ GENERATE(KEYWORD_EVAL, "eval") \ + /* D */ GENERATE(KEYWORD_CLASS, "class") \ + /* D */ GENERATE(KEYWORD_UNION, "union") \ + /* D */ GENERATE(KEYWORD_STRUCT, "struct") \ + /* D */ GENERATE(KEYWORD_INTERFACE, "interface") \ + /* H */ GENERATE(KEYWORD_HAS, "has") \ + /* S */ GENERATE(KEYWORD_TRY, "try") \ + /* S */ GENERATE(KEYWORD_PANIC, "panic") \ + /* S */ GENERATE(KEYWORD_CATCH, "catch") \ + /* S */ GENERATE(KEYWORD_FINALLY, "finally") \ + /* D */ GENERATE(KEYWORD_LET, "let") \ + /* M */ GENERATE(KEYWORD_PRIVATE, "priv") \ + /* M */ GENERATE(KEYWORD_PUBLIC, "pub") \ + /* M */ GENERATE(KEYWORD_PROTECTED, "prot") \ + /* M */ GENERATE(KEYWORD_INTERNAL, "intl") \ + /* M */ GENERATE(KEYWORD_CONST, "const") \ + /*---- S ----*/ GENERATE(KEYWORD_GLOBAL, "global") \ + /* D */ GENERATE(KEYWORD_FFI, "ffi") \ + /* S */ GENERATE(KEYWORD_IMPORT, "import") \ + /* S */ GENERATE(KEYWORD_YIELD, "yield") \ + /* S */ GENERATE(KEYWORD_DELETE, "delete") \ + /* H */ GENERATE(KEYWORD_AS, "as") \ + /* H */ GENERATE(KEYWORD_IN, "in") \ + /* H */ GENERATE(KEYWORD_DERIVES, "derives") \ + /* D */ GENERATE(KEYWORD_MODULE, "module") \ + /* H */ GENERATE(KEYWORD_REQUIRES, "requires") \ + /*---- M ----*/ GENERATE(KEYWORD_UNSAFE, "unsafe") + +// NOTE: IF THIS GENERATION IS CHANGED DO NOT FORGET TO UPDATE COUNT +// TODO: change 'in' to a operator #endif // __KEYWORDS_DEF__ \ No newline at end of file diff --git a/source/token/enums/literals.def b/source/token/enums/literals.def index accc0ad..23306e1 100644 --- a/source/token/enums/literals.def +++ b/source/token/enums/literals.def @@ -17,15 +17,15 @@ #define LITERAL_TOKENS_COUNT 8 -#define LITERAL_TOKENS(GENERATE) \ - GENERATE(LITERAL_TRUE, "true" ) \ - GENERATE(LITERAL_FALSE, "false" ) \ - GENERATE(LITERAL_INTEGER, "" ) \ - GENERATE(LITERAL_COMPLIER_DIRECTIVE, "") \ - GENERATE(LITERAL_FLOATING_POINT, "" ) \ - GENERATE(LITERAL_STRING, "" ) \ - GENERATE(LITERAL_CHAR, "" ) \ - GENERATE(LITERAL_NULL, "null" ) +#define LITERAL_TOKENS(GENERATE) \ + GENERATE(LITERAL_COMPLIER_DIRECTIVE, "/* complier_directive */") \ + GENERATE(LITERAL_STRING, "/* string */" ) \ + GENERATE(LITERAL_FLOATING_POINT, "/* float */" ) \ + GENERATE(LITERAL_CHAR, "/* char */" ) \ + GENERATE(LITERAL_INTEGER, "/* int */" ) \ + GENERATE(LITERAL_TRUE, "true" ) \ + GENERATE(LITERAL_FALSE, "false" ) \ + GENERATE(LITERAL_NULL, "null" ) // NOTE: IF THIS GENERATION IS CHANGED DO NOT FORGET TO UPDATE COUNT diff --git a/source/token/enums/others.def b/source/token/enums/others.def index d86feb1..f3295e1 100644 --- a/source/token/enums/others.def +++ b/source/token/enums/others.def @@ -18,8 +18,8 @@ #define OTHER_TOKENS_COUNT 4 #define OTHER_TOKENS(GENERATE) \ - GENERATE(IDENTIFIER, "" ) \ - GENERATE(WHITESPACE, "< >" ) \ + GENERATE(IDENTIFIER, "_" ) \ + GENERATE(WHITESPACE, " " ) \ GENERATE(OTHERS, "") \ GENERATE(EOF_TOKEN, "" ) diff --git a/source/token/enums/primitives.def b/source/token/enums/primitives.def index fa2a0c1..10e64c9 100644 --- a/source/token/enums/primitives.def +++ b/source/token/enums/primitives.def @@ -15,14 +15,13 @@ #ifndef __PRIMITIVES_DEF__ #define __PRIMITIVES_DEF__ -#define PRIMITIVE_TOKENS_COUNT 26 +#define PRIMITIVE_TOKENS_COUNT 16 #define PRIMITIVE_TOKENS(GENERATE) \ GENERATE(PRIMITIVE_VOID, "void" ) \ GENERATE(PRIMITIVE_BOOL, "bool" ) \ GENERATE(PRIMITIVE_BYTE, "byte" ) \ GENERATE(PRIMITIVE_CHAR, "char" ) \ - GENERATE(PRIMITIVE_POINTER, "ptr" ) \ GENERATE(PRIMITIVE_I8, "i8" ) \ GENERATE(PRIMITIVE_U8, "u8" ) \ GENERATE(PRIMITIVE_I16, "i16" ) \ @@ -33,17 +32,8 @@ GENERATE(PRIMITIVE_I64, "i64" ) \ GENERATE(PRIMITIVE_U64, "u64" ) \ GENERATE(PRIMITIVE_F64, "f64" ) \ - GENERATE(PRIMITIVE_FLOAT, "float" ) \ GENERATE(PRIMITIVE_I128, "i128" ) \ - GENERATE(PRIMITIVE_U128, "u128" ) \ - GENERATE(PRIMITIVE_INT, "int" ) \ - GENERATE(PRIMITIVE_DECIMAL, "decimal") \ - GENERATE(PRIMITIVE_STRING, "string" ) \ - GENERATE(PRIMITIVE_LIST, "list" ) \ - GENERATE(PRIMITIVE_TUPLE, "tuple" ) \ - GENERATE(PRIMITIVE_SET, "set" ) \ - GENERATE(PRIMITIVE_MAP, "map" ) \ - GENERATE(PRIMITIVE_ANY, "any" ) + GENERATE(PRIMITIVE_U128, "u128" ) // NOTE: IF THIS GENERATION IS CHANGED DO NOT FORGET TO UPDATE COUNT diff --git a/source/token/include/generate.hh b/source/token/include/generate.hh index 4eb0876..d168a80 100644 --- a/source/token/include/generate.hh +++ b/source/token/include/generate.hh @@ -24,6 +24,7 @@ #include "token/enums/punctuation.def" #include "token/types/mapping.hh" + #define MAKE_TOKEN(name, string) name, #define MAKE_TOKEN_PAIR(name, string) std::pair{name, string}, #define MAKE_TOKEN_CLASS(name, string) \ @@ -61,50 +62,50 @@ TOKENS(MAKE_TOKEN_CLASS) \ } -#define GENERATE_RESERVED_ENUM_AND_MAPPING() \ - \ - enum reserved { RESERVED(MAKE_TOKEN) }; \ - \ +#define GENERATE_RESERVED_ENUM_AND_MAPPING() \ + \ + enum reserved { RESERVED(MAKE_TOKEN) }; \ + \ constexpr token::Mapping reserved{{RESERVED(MAKE_TOKEN_PAIR)}}; \ - \ - namespace classes { \ - RESERVED(MAKE_TOKEN_CLASS) \ + \ + namespace classes { \ + RESERVED(MAKE_TOKEN_CLASS) \ } namespace abi { - GENERATE_RESERVED_ENUM_AND_MAPPING() +GENERATE_RESERVED_ENUM_AND_MAPPING() - #undef GENERATE_RESERVED_ENUM_AND_MAPPING +#undef GENERATE_RESERVED_ENUM_AND_MAPPING - #undef RESERVED_ABI_COUNT +#undef RESERVED_ABI_COUNT - #undef RESERVED_ABI +#undef RESERVED_ABI } // namespace abi namespace token { - GENERATE_TOKENS_ENUM_AND_MAPPING() // generate enum and maps for all tokens - - // undefine the macros to prevent global namespace pollution - #undef MAKE_TOKEN - #undef MAKE_TOKEN_PAIR - #undef GENERATE_TOKENS_ENUM_AND_MAPPING - - #undef KEYWORD_TOKENS_COUNT - #undef DELIMITER_TOKENS_COUNT - #undef LITERAL_TOKENS_COUNT - #undef OPERATOR_TOKENS_COUNT - #undef OTHER_TOKENS_COUNT - #undef PRIMITIVE_TOKENS_COUNT - #undef PUNCTUATION_TOKENS_COUNT - - #undef TOKENS - #undef KEYWORD_TOKENS - #undef DELIMITER_TOKENS - #undef LITERAL_TOKENS - #undef OPERATOR_TOKENS - #undef OTHER_TOKENS - #undef PRIMITIVE_TOKENS - #undef PUNCTUATION_TOKENS +GENERATE_TOKENS_ENUM_AND_MAPPING() // generate enum and maps for all tokens + +// undefine the macros to prevent global namespace pollution +#undef MAKE_TOKEN +#undef MAKE_TOKEN_PAIR +#undef GENERATE_TOKENS_ENUM_AND_MAPPING + +#undef KEYWORD_TOKENS_COUNT +#undef DELIMITER_TOKENS_COUNT +#undef LITERAL_TOKENS_COUNT +#undef OPERATOR_TOKENS_COUNT +#undef OTHER_TOKENS_COUNT +#undef PRIMITIVE_TOKENS_COUNT +#undef PUNCTUATION_TOKENS_COUNT + +#undef TOKENS +#undef KEYWORD_TOKENS +#undef DELIMITER_TOKENS +#undef LITERAL_TOKENS +#undef OPERATOR_TOKENS +#undef OTHER_TOKENS +#undef PRIMITIVE_TOKENS +#undef PUNCTUATION_TOKENS } // namespace token #endif // __TOKENS_HH__ \ No newline at end of file diff --git a/source/token/include/token_list.hh b/source/token/include/token_list.hh index a5f3863..e4196c0 100644 --- a/source/token/include/token_list.hh +++ b/source/token/include/token_list.hh @@ -62,14 +62,16 @@ class TokenList : public std::vector { bool operator==(const TokenListIter &other) const; Token *operator->(); // TODO: Change if a shared ptr is needed TokenListIter &operator*(); + const Token &operator*() const; std::reference_wrapper operator--(); std::reference_wrapper operator++(); - std::reference_wrapper advance(const std::int32_t n = 1); - std::reference_wrapper reverse(const std::int32_t n = 1); - std::optional> peek(const std::int32_t n = 1) const; - std::optional> peek_back(const std::int32_t n = 1) const; + std::reference_wrapper advance(const i32 n = 1); + std::reference_wrapper reverse(const i32 n = 1); + std::optional> peek(const i32 n = 1) const; + std::optional> peek_back(const i32 n = 1) const; std::reference_wrapper current() const; TokenList remaining(); + u64 remaining_n() const { return end - cursor_position; } u64 position() const { return cursor_position; } }; @@ -126,10 +128,10 @@ class TokenList : public std::vector { void remove_left(); void reset(); - TokenList raw_slice(const std::uint64_t start, const std::int64_t end) const; - TokenList&& slice(std::uint64_t start, std::int64_t end = -1); - std::pair split_at(const std::uint64_t i) const; - TokenList pop(const std::uint64_t offset = 1); + [[nodiscard]] TokenList raw_slice(const u64 start, const i64 end) const; + [[nodiscard]] TokenList slice(u64 start, i64 end = -1); + std::pair split_at(const u64 i) const; + TokenList pop(const u64 offset = 1); const Token &pop_front(); TO_NEO_JSON_IMPL { neo::json token_list_json("TokenList"); @@ -141,6 +143,8 @@ class TokenList : public std::vector { void insert_remove(TokenList &tokens, u64 start, u64 end); bool operator==(const TokenList &rhs) const; + // impl the [] operator + Token &operator[](u64 index) const { return const_cast(TokenVec::operator[](index)); } }; void print_tokens(token::TokenList &tokens); diff --git a/source/token/source/token_list.cc b/source/token/source/token_list.cc index 199f8f1..ca819b8 100644 --- a/source/token/source/token_list.cc +++ b/source/token/source/token_list.cc @@ -48,26 +48,34 @@ void TokenList::reset() { it = this->cbegin(); } const std::string &TokenList::file_name() const { return filename; } -TokenList&& TokenList::slice(const std::uint64_t start, std::int64_t end) { - if (end < 0) { - end = static_cast(this->size()); // - (-end); +TokenList TokenList::slice(const u64 start, i64 end) { + if (start > static_cast(std::numeric_limits::max())) [[unlikely]] { + throw std::out_of_range("start is greater than the maximum value of i64."); } - if (end > static_cast(this->size())) { - end = static_cast(this->size()); + + if (end < 0) [[likely]] { + end = static_cast(this->size()); + } + + if (end > static_cast(this->size())) [[unlikely]] { + end = static_cast(this->size()); + } + + if (start > static_cast(std::numeric_limits::max())) [[unlikely]] { + throw std::out_of_range("start of slice is greater than allowable range."); } - if (start > end) { - throw std::out_of_range("Start of slice is greater than range."); + if (static_cast(start) > end) [[unlikely]] { + throw std::out_of_range("start of slice is greater than end."); } - difference_type start_index = start; - difference_type end_index = end; + auto start_index = static_cast(start); + difference_type end_index = end; return {this->filename, this->cbegin() + start_index, this->cbegin() + end_index}; } -TokenList TokenList::raw_slice(const std::uint64_t start, const std::int64_t end) const { - +TokenList TokenList::raw_slice(const u64 start, const i64 end) const { auto start_index = static_cast(start); auto end_index = static_cast(end); @@ -77,14 +85,14 @@ TokenList TokenList::raw_slice(const std::uint64_t start, const std::int64_t end /// @brief /// @param i Inclusive split /// @return first is the left side of the split and the second is the right -std::pair TokenList::split_at(const std::uint64_t i) const { +std::pair TokenList::split_at(const u64 i) const { auto start_idx = static_cast(i); TokenList first{this->filename, this->cbegin(), cbegin() + start_idx}; TokenList second{this->filename, this->cbegin() + start_idx, this->cend()}; return {first, second}; } -TokenList TokenList::pop(const std::uint64_t offset) { +TokenList TokenList::pop(const u64 offset) { auto diff = static_cast(offset); *this = {this->filename, this->cbegin() + diff + 1, this->cend()}; @@ -195,6 +203,10 @@ Token *TokenList::TokenListIter::operator->() { TokenList::TokenListIter &TokenList::TokenListIter::operator*() { return *this; } +const Token &TokenList::TokenListIter::operator*() const { + return tokens.get()[cursor_position]; +} + std::reference_wrapper TokenList::TokenListIter::operator--() { if ((cursor_position - 1) >= 0) { --cursor_position; @@ -213,7 +225,7 @@ std::reference_wrapper TokenList::TokenListIter::opera throw std::out_of_range("access to token in token list is out of bounds"); } -std::reference_wrapper TokenList::TokenListIter::advance(const std::int32_t n) { +std::reference_wrapper TokenList::TokenListIter::advance(const i32 n) { if ((cursor_position + n) <= end + 1) { ++cursor_position; } @@ -225,7 +237,7 @@ std::reference_wrapper TokenList::TokenListIter::advance(const std::int32 return tokens.get()[cursor_position]; } -std::reference_wrapper TokenList::TokenListIter::reverse(const std::int32_t n) { +std::reference_wrapper TokenList::TokenListIter::reverse(const i32 n) { if ((cursor_position - n) >= 0) { --cursor_position; } @@ -238,7 +250,7 @@ std::reference_wrapper TokenList::TokenListIter::reverse(const std::int32 } std::optional> -TokenList::TokenListIter::peek(const std::int32_t n) const { +TokenList::TokenListIter::peek(const i32 n) const { if ((cursor_position + n) <= end) { return tokens.get()[cursor_position + n]; } @@ -247,7 +259,7 @@ TokenList::TokenListIter::peek(const std::int32_t n) const { } std::optional> -TokenList::TokenListIter::peek_back(const std::int32_t n) const { +TokenList::TokenListIter::peek_back(const i32 n) const { if ((cursor_position - n) >= 0) { return tokens.get()[cursor_position - n]; } diff --git a/source/token/types/mapping.hh b/source/token/types/mapping.hh index fddff98..b41c303 100644 --- a/source/token/types/mapping.hh +++ b/source/token/types/mapping.hh @@ -17,8 +17,8 @@ #include #include #include -#include #include +#include #include using std::string; diff --git a/tests/ast_test.json b/tests/ast_test.json new file mode 100644 index 0000000..1ec3d95 --- /dev/null +++ b/tests/ast_test.json @@ -0,0 +1,1188 @@ +{ + "ast": { + "Decls": [ + { + "FuncDecl": { + "body": { + "SuiteState": { + "BlockState": [ + { + "ExprState": { + "FunctionCallExpr": { + "args": { + "ArgumentListExpr": [ + { + "ArgumentExpr": { + "type": 0, + "value": { + "LiteralExpr": { + "type": 0, + "value": { + "kind": "/* string */", + "length": 16, + "loc": { + "column_number": 10, + "filename": "tests/main.hlx", + "line_number": 2, + "offset": 37 + }, + "value": "\"THIS IS A TEST\"" + } + } + } + } + } + ] + }, + "generics": {}, + "path": { + "PathExpr": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 5, + "loc": { + "column_number": 4, + "filename": "tests/main.hlx", + "line_number": 2, + "offset": 20 + }, + "value": "print" + } + }, + "type": 2 + } + } + } + } + } + ] + } + }, + "generics": {}, + "modifiers": { + "modifiers": {} + }, + "name": { + "PathExpr": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 4, + "loc": { + "column_number": 3, + "filename": "tests/main.hlx", + "line_number": 1, + "offset": 7 + }, + "value": "main" + } + }, + "type": 2 + } + }, + "params": {}, + "qualifiers": { + "modifiers": {} + }, + "returns": {} + } + }, + { + "FuncDecl": { + "body": { + "SuiteState": { + "BlockState": [ + { + "ReturnState": { + "LiteralExpr": { + "type": 0, + "value": { + "kind": "/* int */", + "length": 1, + "loc": { + "column_number": 11, + "filename": "tests/main.hlx", + "line_number": 6, + "offset": 73 + }, + "value": "0" + } + } + } + } + ] + } + }, + "generics": {}, + "modifiers": { + "modifiers": {} + }, + "name": { + "PathExpr": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 7, + "loc": { + "column_number": 3, + "filename": "tests/main.hlx", + "line_number": 5, + "offset": 50 + }, + "value": "test_fn" + } + }, + "type": 2 + } + }, + "params": {}, + "qualifiers": { + "modifiers": {} + }, + "returns": { + "Type": { + "generics": {}, + "specifiers": { + "modifiers": {} + }, + "value": { + "IdentExpr": { + "kind": "i32", + "length": 3, + "loc": { + "column_number": 16, + "filename": "tests/main.hlx", + "line_number": 5, + "offset": 59 + }, + "value": "i32" + } + } + } + } + } + }, + { + "ClassDecl": { + "body": { + "SuiteState": { + "BlockState": [ + { + "LetDecl": { + "modifiers": { + "modifiers": {} + }, + "vars": [ + { + "VarDecl": { + "value": {}, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 8, + "filename": "tests/main.hlx", + "line_number": 10, + "offset": 117 + }, + "value": "x" + } + }, + "type": { + "Type": { + "generics": {}, + "specifiers": { + "modifiers": {} + }, + "value": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 11, + "filename": "tests/main.hlx", + "line_number": 10, + "offset": 120 + }, + "value": "T" + } + } + } + } + } + } + } + } + ], + "vis": { + "modifiers": {} + } + } + }, + { + "LetDecl": { + "modifiers": { + "modifiers": [ + { + "marker": { + "kind": "static", + "length": 6, + "loc": { + "column_number": 8, + "filename": "tests/main.hlx", + "line_number": 11, + "offset": 135 + }, + "value": "static" + }, + "type": 2 + } + ] + }, + "vars": [ + { + "VarDecl": { + "value": {}, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 15, + "filename": "tests/main.hlx", + "line_number": 11, + "offset": 137 + }, + "value": "y" + } + }, + "type": { + "Type": { + "generics": {}, + "specifiers": { + "modifiers": {} + }, + "value": { + "IdentExpr": { + "kind": "i32", + "length": 3, + "loc": { + "column_number": 18, + "filename": "tests/main.hlx", + "line_number": 11, + "offset": 142 + }, + "value": "i32" + } + } + } + } + } + } + } + } + ], + "vis": { + "modifiers": {} + } + } + }, + { + "FuncDecl": { + "body": { + "SuiteState": { + "BlockState": [ + { + "ExprState": { + "DotPathExpr": { + "lhs": { + "IdentExpr": { + "kind": "_", + "length": 4, + "loc": { + "column_number": 8, + "filename": "tests/main.hlx", + "line_number": 14, + "offset": 182 + }, + "value": "self" + } + }, + "rhs": { + "BinaryExpr": { + "lhs": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 13, + "filename": "tests/main.hlx", + "line_number": 14, + "offset": 184 + }, + "value": "x" + } + }, + "op": { + "kind": "=", + "length": 1, + "loc": { + "column_number": 15, + "filename": "tests/main.hlx", + "line_number": 14, + "offset": 186 + }, + "value": "=" + }, + "rhs": { + "LiteralExpr": { + "type": 0, + "value": { + "kind": "/* int */", + "length": 1, + "loc": { + "column_number": 17, + "filename": "tests/main.hlx", + "line_number": 14, + "offset": 188 + }, + "value": "0" + } + } + } + } + } + } + } + }, + { + "ExprState": { + "ScopePathExpr": { + "lhs": { + "IdentExpr": { + "kind": "_", + "length": 12, + "loc": { + "column_number": 8, + "filename": "tests/main.hlx", + "line_number": 15, + "offset": 209 + }, + "value": "WithGenerics" + } + }, + "rhs": { + "BinaryExpr": { + "lhs": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 22, + "filename": "tests/main.hlx", + "line_number": 15, + "offset": 212 + }, + "value": "y" + } + }, + "op": { + "kind": "=", + "length": 1, + "loc": { + "column_number": 24, + "filename": "tests/main.hlx", + "line_number": 15, + "offset": 214 + }, + "value": "=" + }, + "rhs": { + "LiteralExpr": { + "type": 0, + "value": { + "kind": "/* int */", + "length": 1, + "loc": { + "column_number": 26, + "filename": "tests/main.hlx", + "line_number": 15, + "offset": 216 + }, + "value": "0" + } + } + } + } + } + } + } + } + ] + } + }, + "generics": {}, + "modifiers": { + "modifiers": {} + }, + "name": { + "PathExpr": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 12, + "loc": { + "column_number": 7, + "filename": "tests/main.hlx", + "line_number": 13, + "offset": 162 + }, + "value": "WithGenerics" + } + }, + "type": 2 + } + }, + "params": [ + { + "VarDecl": { + "value": {}, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 4, + "loc": { + "column_number": 20, + "filename": "tests/main.hlx", + "line_number": 13, + "offset": 167 + }, + "value": "self" + } + }, + "type": {} + } + } + } + } + ], + "qualifiers": { + "modifiers": {} + }, + "returns": {} + } + } + ] + } + }, + "derives": {}, + "generics": { + "RequiresDecl": { + "bounds": {}, + "params": { + "RequiresParamList": [ + { + "RequiresParamDecl": { + "is_const": "false", + "value": {}, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 29, + "filename": "tests/main.hlx", + "line_number": 9, + "offset": 105 + }, + "value": "T" + } + }, + "type": {} + } + } + } + } + ] + } + } + }, + "modifiers": { + "modifiers": {} + }, + "name": { + "IdentExpr": { + "kind": "_", + "length": 12, + "loc": { + "column_number": 6, + "filename": "tests/main.hlx", + "line_number": 9, + "offset": 93 + }, + "value": "WithGenerics" + } + } + } + }, + { + "ClassDecl": { + "body": { + "SuiteState": { + "BlockState": [ + { + "LetDecl": { + "modifiers": { + "modifiers": {} + }, + "vars": [ + { + "VarDecl": { + "value": {}, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 12, + "filename": "tests/main.hlx", + "line_number": 20, + "offset": 290 + }, + "value": "x" + } + }, + "type": { + "Type": { + "generics": {}, + "specifiers": { + "modifiers": {} + }, + "value": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 15, + "filename": "tests/main.hlx", + "line_number": 20, + "offset": 293 + }, + "value": "T" + } + } + } + } + } + } + } + } + ], + "vis": { + "modifiers": [ + { + "marker": { + "kind": "pub", + "length": 3, + "loc": { + "column_number": 4, + "filename": "tests/main.hlx", + "line_number": 20, + "offset": 284 + }, + "value": "pub" + }, + "type": 0 + } + ] + } + } + }, + { + "LetDecl": { + "modifiers": { + "modifiers": {} + }, + "vars": [ + { + "VarDecl": { + "value": {}, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 12, + "filename": "tests/main.hlx", + "line_number": 21, + "offset": 307 + }, + "value": "y" + } + }, + "type": { + "Type": { + "generics": {}, + "specifiers": { + "modifiers": {} + }, + "value": { + "IdentExpr": { + "kind": "i32", + "length": 3, + "loc": { + "column_number": 15, + "filename": "tests/main.hlx", + "line_number": 21, + "offset": 312 + }, + "value": "i32" + } + } + } + } + } + } + } + } + ], + "vis": { + "modifiers": [ + { + "marker": { + "kind": "pub", + "length": 3, + "loc": { + "column_number": 4, + "filename": "tests/main.hlx", + "line_number": 21, + "offset": 301 + }, + "value": "pub" + }, + "type": 0 + } + ] + } + } + }, + { + "FuncDecl": { + "body": { + "SuiteState": { + "BlockState": [ + { + "ExprState": { + "DotPathExpr": { + "lhs": { + "IdentExpr": { + "kind": "_", + "length": 4, + "loc": { + "column_number": 8, + "filename": "tests/main.hlx", + "line_number": 24, + "offset": 357 + }, + "value": "self" + } + }, + "rhs": { + "BinaryExpr": { + "lhs": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 13, + "filename": "tests/main.hlx", + "line_number": 24, + "offset": 359 + }, + "value": "x" + } + }, + "op": { + "kind": "=", + "length": 1, + "loc": { + "column_number": 15, + "filename": "tests/main.hlx", + "line_number": 24, + "offset": 361 + }, + "value": "=" + }, + "rhs": { + "LiteralExpr": { + "type": 0, + "value": { + "kind": "/* int */", + "length": 1, + "loc": { + "column_number": 17, + "filename": "tests/main.hlx", + "line_number": 24, + "offset": 363 + }, + "value": "0" + } + } + } + } + } + } + } + }, + { + "ExprState": { + "ScopePathExpr": { + "lhs": { + "IdentExpr": { + "kind": "_", + "length": 17, + "loc": { + "column_number": 8, + "filename": "tests/main.hlx", + "line_number": 25, + "offset": 389 + }, + "value": "WithGenericsBound" + } + }, + "rhs": { + "BinaryExpr": { + "lhs": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 27, + "filename": "tests/main.hlx", + "line_number": 25, + "offset": 392 + }, + "value": "y" + } + }, + "op": { + "kind": "=", + "length": 1, + "loc": { + "column_number": 29, + "filename": "tests/main.hlx", + "line_number": 25, + "offset": 394 + }, + "value": "=" + }, + "rhs": { + "LiteralExpr": { + "type": 0, + "value": { + "kind": "/* int */", + "length": 1, + "loc": { + "column_number": 31, + "filename": "tests/main.hlx", + "line_number": 25, + "offset": 396 + }, + "value": "0" + } + } + } + } + } + } + } + } + ] + } + }, + "generics": {}, + "modifiers": { + "modifiers": {} + }, + "name": { + "PathExpr": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 17, + "loc": { + "column_number": 7, + "filename": "tests/main.hlx", + "line_number": 23, + "offset": 337 + }, + "value": "WithGenericsBound" + } + }, + "type": 2 + } + }, + "params": [ + { + "VarDecl": { + "value": {}, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 4, + "loc": { + "column_number": 25, + "filename": "tests/main.hlx", + "line_number": 23, + "offset": 342 + }, + "value": "self" + } + }, + "type": {} + } + } + } + } + ], + "qualifiers": { + "modifiers": {} + }, + "returns": {} + } + }, + { + "FuncDecl": { + "body": { + "SuiteState": { + "BlockState": [ + { + "ExprState": { + "FunctionCallExpr": { + "args": { + "ArgumentListExpr": [ + { + "ArgumentExpr": { + "type": 0, + "value": { + "LiteralExpr": { + "type": 0, + "value": { + "kind": "/* string */", + "length": 15, + "loc": { + "column_number": 14, + "filename": "tests/main.hlx", + "line_number": 29, + "offset": 485 + }, + "value": "\"Hello, World!\"" + } + } + } + } + } + ] + }, + "generics": {}, + "path": { + "PathExpr": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 5, + "loc": { + "column_number": 8, + "filename": "tests/main.hlx", + "line_number": 29, + "offset": 469 + }, + "value": "print" + } + }, + "type": 2 + } + } + } + } + } + ] + } + }, + "generics": {}, + "modifiers": { + "modifiers": [ + { + "marker": { + "kind": "pub", + "length": 3, + "loc": { + "column_number": 4, + "filename": "tests/main.hlx", + "line_number": 28, + "offset": 409 + }, + "value": "pub" + }, + "type": 0 + } + ] + }, + "name": { + "PathExpr": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 9, + "loc": { + "column_number": 11, + "filename": "tests/main.hlx", + "line_number": 28, + "offset": 422 + }, + "value": "something" + } + }, + "type": 2 + } + }, + "params": [ + { + "VarDecl": { + "value": {}, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 4, + "loc": { + "column_number": 21, + "filename": "tests/main.hlx", + "line_number": 28, + "offset": 427 + }, + "value": "self" + } + }, + "type": {} + } + } + } + }, + { + "VarDecl": { + "value": {}, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 27, + "filename": "tests/main.hlx", + "line_number": 28, + "offset": 430 + }, + "value": "a" + } + }, + "type": { + "Type": { + "generics": {}, + "specifiers": { + "modifiers": {} + }, + "value": { + "IdentExpr": { + "kind": "_", + "length": 3, + "loc": { + "column_number": 30, + "filename": "tests/main.hlx", + "line_number": 28, + "offset": 435 + }, + "value": "int" + } + } + } + } + } + } + } + }, + { + "VarDecl": { + "value": { + "LiteralExpr": { + "type": 0, + "value": { + "kind": "/* float */", + "length": 5, + "loc": { + "column_number": 46, + "filename": "tests/main.hlx", + "line_number": 28, + "offset": 453 + }, + "value": "19.21" + } + } + }, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 35, + "filename": "tests/main.hlx", + "line_number": 28, + "offset": 438 + }, + "value": "y" + } + }, + "type": { + "Type": { + "generics": {}, + "specifiers": { + "modifiers": {} + }, + "value": { + "IdentExpr": { + "kind": "_", + "length": 5, + "loc": { + "column_number": 38, + "filename": "tests/main.hlx", + "line_number": 28, + "offset": 445 + }, + "value": "float" + } + } + } + } + } + } + } + } + ], + "qualifiers": { + "modifiers": {} + }, + "returns": {} + } + } + ] + } + }, + "derives": {}, + "generics": { + "RequiresDecl": { + "bounds": { + "TypeBoundList": [ + { + "InstOfExpr": { + "op": 0, + "type": { + "IdentExpr": { + "kind": "_", + "length": 6, + "loc": { + "column_number": 46, + "filename": "tests/main.hlx", + "line_number": 19, + "offset": 275 + }, + "value": "Number" + } + }, + "value": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 40, + "filename": "tests/main.hlx", + "line_number": 19, + "offset": 264 + }, + "value": "T" + } + } + } + } + ] + }, + "params": { + "RequiresParamList": [ + { + "RequiresParamDecl": { + "is_const": "false", + "value": {}, + "var": { + "NamedVarSpecifier": { + "path": { + "IdentExpr": { + "kind": "_", + "length": 1, + "loc": { + "column_number": 34, + "filename": "tests/main.hlx", + "line_number": 19, + "offset": 258 + }, + "value": "T" + } + }, + "type": {} + } + } + } + } + ] + } + } + }, + "modifiers": { + "modifiers": {} + }, + "name": { + "IdentExpr": { + "kind": "_", + "length": 17, + "loc": { + "column_number": 6, + "filename": "tests/main.hlx", + "line_number": 19, + "offset": 246 + }, + "value": "WithGenericsBound" + } + } + } + } + ] + } +} \ No newline at end of file diff --git a/tests/expr_tests.hlx b/tests/expr_tests.hlx new file mode 100644 index 0000000..1532cec --- /dev/null +++ b/tests/expr_tests.hlx @@ -0,0 +1,147 @@ +/// literal expressions + 1; + 3.14; + 0x10; + 0b1010; + 0o123; + 1.2e3; + 1.2e-3; + "hello"; + f"hello {name}"; + r"hello"; + b"hello"; + u"hello"; + true; + false; + null; + 'c'; + r'c'; + b'c'; + u'c'; + f'{v}'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + \ No newline at end of file diff --git a/tests/large_test.hlx b/tests/large_test.hlx new file mode 100644 index 0000000..a27c751 --- /dev/null +++ b/tests/large_test.hlx @@ -0,0 +1,245701 @@ + /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } /// test cases for primitive values + 1; + 3.14; + "hello"; + true; + false; + null; + 'c'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } \ No newline at end of file diff --git a/tests/main.hlx b/tests/main.hlx index 22be798..3dacc9c 100644 --- a/tests/main.hlx +++ b/tests/main.hlx @@ -1 +1,31 @@ -this_is_a_fn_call(1, 2, 3); \ No newline at end of file +fn main() { + print("THIS IS A TEST"); +} + +fn test_fn() -> i32 { + return 0; +} + +class WithGenerics requires { + let x: T; + let static y: i32; + + fn WithGenerics(self) { + self.x = 0; + WithGenerics::y = 0; + } +} + +class WithGenericsBound requires if T has Number { + pub let x: T; + pub let y: i32; + + fn WithGenericsBound(self) { + self.x = 0; + WithGenericsBound::y = 0; + } + + pub fn something(self, a: int, y: float = 19.21) { + print("Hello, World!"); + } +} \ No newline at end of file diff --git a/tests/mixed_tests.hlx b/tests/mixed_tests.hlx new file mode 100644 index 0000000..89413d4 --- /dev/null +++ b/tests/mixed_tests.hlx @@ -0,0 +1,269 @@ + /// literal expressions + 1; + 3.14; + 0x10; + 0b1010; + 0o123; + 1.2e3; + 1.2e-3; + "hello"; + f"hello {name}"; + r"hello"; + b"hello"; + u"hello"; + true; + false; + null; + 'c'; + r'c'; + b'c'; + u'c'; + f'{v}'; + + /// unary expressions + -5; + !true; + ~0; + ++x; + --y; + &z; + *z; + *z++; + *z--; + + /// testing binary operators + foo + 10; + bar - 20; + baz * 30; + qux / 40; + foo % 50; + foo & 60; + bar | 70; + baz ^ 80; + qux << 90; + foo >> 100; + bar = 1; + baz += 2; + qux -= 3; + foo *= 4; + bar /= 5; + baz %= 6; + qux &= 7; + foo |= 8; + bar ^= 9; + + /// variable references + foo; + bar; + baz; + qux; + + /// function calls with positional and named arguments + parse_args(foo); + parse_args(1, 2); + parse_NArgs(x = 10, y = 20); + parse_mixed_args(12, 34, y = 50); + /* FIXME: add support for packing and unpacking arguments (e.g. ...args and args...) */ + + /// object initialization (implicit object creation) + initialize_obj({ // defined: `fn initialize_obj(obj: Point)` + .x = 10, + .y = 20 + }); + + /// object initialization (explicit object creation) + PointObject { + x = 10, + y = 20 + }; + + /// map initialization - no trailing comma + { 1: "one", 2: "two" }; + + /// map initialization - with trailing comma + { 1: "one", 2: "two", }; + + /// set initialization - no trailing comma + {1, 2, 3, 4, 5}; + + /// set initialization - with trailing comma + {1, 2, 3, 4, 5,}; + + /// list initialization - no trailing comma + [1, 2, 3, 4, 5]; + + /// list initialization - with trailing comma + [1, 2, 3, 4, 5,]; + + /// tuple initialization - no trailing comma + (1, 2, 3, 4, 5); + + /// tuple initialization - with trailing comma + (1, 2, 3, 4, 5,); + + /// namespace and class method calls + namespace::Class::method(); + foo::bar::method(); + object.property; + instance.method(); + + /// ternary and conditional expressions + x ? 1 : 2; + x == 0 ? "zero" : "non-zero"; + "hello" if x == 0 else "world"; + + /// array and matrix access + array[0]; + matrix[1][2]; + + /// arithmetic expressions with parentheses + (1 + 2) * 3; + 7 - (1 * 4); + (foo - bar) * 2; + + /// chained method and property access + namespace::Class::method().chain().property; + namespace::Class::method().chain().property[0]; + namespace::Class::method().chain().property[xy + 1 if x == 0 else 2]; + + /// type casting + foo as int; + bar as *float; + bar as char*; + // TODO: add support for all the types of casting + // bas as const char*; + + /// arithmetic with different operator precedence + foo * bar / baz; + foo * (bar / baz); + + /// concurrency and control flow + spawn some_function; + await some_function; + thread another_function; + yield result; + delete foo; + return 1; + + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + finally: + finalize(); + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } \ No newline at end of file diff --git a/tests/state_tests.hlx b/tests/state_tests.hlx new file mode 100644 index 0000000..8de2ad6 --- /dev/null +++ b/tests/state_tests.hlx @@ -0,0 +1,119 @@ + /// for loop iterator based + for (i = 0; i < 10; i++) { + print(i); + } + + for i = 0; i < 10; i++ { + print(i); + } + + for ; i < 10; i++ { + print(i); + } + + for ;; i++ { + print(i); + } + + for ;; { + print(i); + } + + // for loop with range + for element in collection { + process(element); + } + + for element: int in collection { + process(element); + } + + for element: int, f, y: float in collection { + process(element); + } + + /// switch case + switch x { + case 12 { + break; + } + case 11: + case 15: + handle_case(); + default: + handle_default(); + // default: + // handle_default(); + // SYNTAX ERROR: + } + + /// while loop example + while condition { + print("looping..."); + } + + /// conditional statements with 'if', 'else', 'unless' + if foo == 12 { + print("foo is 12"); + } else if bar == 14 { + print("bar is 14"); + } else unless foo == 10 { + print("foo is not 10"); + } else { + print("neither condition met"); + } + + unless foo == 10 { + print("foo is not 10"); + } + + /// try-catch-finally block example + try { + execute_code(); + } catch e: SomeError { + handle_error(e); + } finally { + finalize(); + } + + panic RuntimeError("error message"); + + /// advanced expressions and mixed control flow + /// Ternary expressions with nested conditions + (foo + bar) ? baz * 2 : qux / 3; + (foo > bar) ? ("equal" if baz == qux else "not equal") : (foo == bar ? "foo and bar are equal" : "neither condition met"); + + /// Ternary expressions with arithmetic and logical operators + (foo == 0) ? (bar * 2 + 3) : (baz - qux / 2); + x ? (y + 10) : (z == 20 ? z * 3 : z - 4); + + /// Mixed control flow with chained method calls + object.method1().method2(foo ? "foo_value" : "bar_value").method3(); + + /// Nested conditional expressions + if foo == bar { + return (baz > qux) ? "baz is greater" : "qux is greater"; + } else if (baz < 10) { + return "baz is less than 10"; + } else unless (qux == 0) { + return "qux is not zero"; + } else { + return "default case"; + } + + /// Combining ternary expressions and loops + for i = 0; i < 10; i++ { + print((i % 2 == 0) ? "even" : "odd"); + } + + /// Complex arithmetic with type casting and precedence + /* let logical_expr = */ (foo && bar) || !(baz || qux); + /* let complex_result = */ ((foo * bar + 3) as float) / ((baz - qux) * 2); + /* let mixed_operations = */ (foo * 2 + (bar - 1)) / ((baz % 5) * (qux / 4)); + + /// Logical expressions with multiple conditions + if foo && bar || baz { + print("Complex logical condition met"); + } else unless foo || qux { + print("Alternative condition met"); + } \ No newline at end of file diff --git a/xmake.lua b/xmake.lua index a347c68..8cf6b3f 100644 --- a/xmake.lua +++ b/xmake.lua @@ -70,6 +70,7 @@ function setup_windows() add_linkdirs(".\\libs\\llvm-18.1.9-src\\llvm\\lib") add_includedirs(".\\libs\\llvm-18.1.9-src\\clang\\include") add_linkdirs(".\\libs\\llvm-18.1.9-src\\clang\\lib") + end function setup_linux() @@ -104,7 +105,7 @@ function setup_debug() set_symbols ("debug") -- Generate debug symbols set_optimize("none") -- Disable optimization add_defines ("DEBUG") -- Define DEBUG macro - set_warnings("all") + set_warnings("all", "extra") end function setup_release() @@ -170,6 +171,8 @@ local function helix_src_setup() add_headerfiles("libs/neo-pprint/**.hh") -- add all files in the neo-json directory add_headerfiles("libs/neo-types/**.hh") -- add all files in the neo-json directory + add_headerfiles("libs/PEGTL/**.hpp") -- add all files in the neo-json directory + add_files("libs/neo-panic/**.cc") -- add all files in the neo-json directory end