FlavorLang is a programming language designed with a cooking-inspired syntax, combining intuitive keywords with robust programming concepts. This document specifies the language's design, syntax, and grammar.
- Intuitive Syntax: Culinary-inspired keywords make the language approachable
- Clear Semantics: Each construct has unambiguous meaning
- Predictable Behavior: Operations produce consistent results
- Strong Type System: Type safety without excessive verbosity
- Error Handling: Comprehensive error management capabilities
Category | Keyword | Description | Example |
---|---|---|---|
Variable Declaration | let |
Mutable variable declaration | let x = 5; |
const |
Immutable constant declaration | const PI = 3.14; |
|
Control Flow | if |
Conditional execution | if condition { ... } |
elif |
Alternative condition | elif condition { ... } |
|
else |
Default condition | else { ... } |
|
for |
Loop iteration | for i in range { ... } |
|
while |
Conditional loop | while condition { ... } |
|
break |
Exit loop or switch | break; |
|
Pattern Matching | check |
Pattern matching construct | check value { ... } |
is |
Pattern case | is pattern: |
|
Functions | create |
Function declaration | create func() { ... } |
deliver |
Return value | deliver result; |
|
Error Handling | try |
Exception handling | try { ... } |
rescue |
Error catching | rescue { ... } |
|
finish |
Cleanup block | finish { ... } |
|
burn |
Raise error | burn "Error message"; |
|
I/O Operations | serve |
Output | serve("message"); |
sample |
Input | let input = sample("Enter a number:"); |
|
plate |
File write | plate_file(path, data); |
|
garnish |
File append | garnish_file(path, data); |
|
taste |
File read | taste_file(path); |
Type | Description | Internal Representation | Range/Precision |
---|---|---|---|
integer |
Whole numbers | 64-bit signed | ±9.2e18 |
float |
Decimal numbers | 64/128-bit | ±1.7e±308 (64-bit) |
string |
Text sequence | UTF-8 | Memory limited |
boolean |
Truth values | 1 byte | True /False |
array |
Ordered collection | Dynamic | Memory limited |
Category | Operators | Associativity |
---|---|---|
Arithmetic | + , - , * , / , ** , // , % |
Left to right |
Comparison | == , != , < , <= , > , >= |
Left to right |
Logical | ! , && , || |
Left to right |
Range | .. , ..= |
Left to right |
Assignment | = |
Right to left |
Operation | Syntax | Description |
---|---|---|
Access | array[index] |
Get element at index |
Append | array[^+] |
Add to end |
Prepend | array[+^] |
Add to start |
Remove Last | array[^-] |
Remove from end |
Remove First | array[-^] |
Remove from start |
Slice | array[start:end] |
Get subset |
Reverse | array[::-1] |
Reverse elements |
Step Slice | array[::step] |
Get elements with step |
EBNF Code
program ::= statement*
statement ::= declaration
| control_flow
| function_definition
| expression_statement
| error_handling
| pattern_matching
declaration ::= variable_declaration
| constant_declaration
IDENTIFIER ::= [a-zA-Z_][a-zA-Z0-9_]*
variable_declaration ::= "let" IDENTIFIER "=" expression ";"
constant_declaration ::= "const" IDENTIFIER "=" expression ";"
control_flow ::= if_statement
| loop_statement
| switch_statement
if_statement ::= "if" expression block
( "elif" expression block )*
( "else" block )?
loop_statement ::= while_loop | for_loop
while_loop ::= "while" expression block
for_loop ::= "for" IDENTIFIER "in" range block
range ::= expression range_operator expression
range_operator ::= ".." | "..="
switch_statement ::= "check" expression "{" pattern_case* default_case "}"
pattern_case ::= "is" pattern ":" block
default_case ::= "else" ":" block
pattern ::= literal | IDENTIFIER | array_expression
function_definition ::= "create" IDENTIFIER "(" parameter_list ")" block
parameter_list ::= ( IDENTIFIER ( "," IDENTIFIER )* )?
block ::= "{" statement* "}"
expression_statement ::= expression ";"
expression ::= literal
| IDENTIFIER
| binary_expression
| function_call
| array_expression
literal ::= NUMBER | STRING | BOOLEAN
binary_expression ::= expression operator expression
operator ::= "+" | "-" | "*" | "/" | "%"
| "**" | "//"
| "==" | "!=" | "<" | "<=" | ">" | ">="
| "&&" | "||" | "!"
function_call ::= IDENTIFIER "(" argument_list ")"
argument_list ::= ( expression ( "," expression )* )?
array_expression ::= "[" array_elements "]"
array_elements ::= ( expression ( "," expression )* )?
array_operation ::= "array" "[" operation "]"
operation ::= "^+" | "+^" | "^-" | "-^"
| "start:end" | "::step"
error_handling ::= "try" block "rescue" block ( "finish" block )?
try_block ::= "try" block
rescue_block ::= "rescue" block
finish_block ::= "finish" block
program:
program ::= statement*
statement:
statement
::= declaration
| control_flow
| function_definition
| expression_statement
| error_handling
| pattern_matching
referenced by:
- block
- program
declaration:
declaration
::= variable_declaration
| constant_declaration
referenced by:
- statement
IDENTIFIER:
IDENTIFIER
::= [a-zA-Z_] [a-zA-Z0-9_]*
referenced by:
- constant_declaration
- expression
- for_loop
- function_call
- function_definition
- parameter_list
- pattern
- variable_declaration
variable_declaration:
variable_declaration
::= 'let' IDENTIFIER '=' expression ';'
referenced by:
- declaration
constant_declaration:
constant_declaration
::= 'const' IDENTIFIER '=' expression ';'
referenced by:
- declaration
control_flow:
control_flow
::= if_statement
| loop_statement
| switch_statement
referenced by:
- statement
if_statement:
if_statement
::= 'if' expression block ( 'elif' expression block )* ( 'else' block )?
referenced by:
- control_flow
loop_statement:
loop_statement
::= while_loop
| for_loop
referenced by:
- control_flow
while_loop:
while_loop
::= 'while' expression block
referenced by:
- loop_statement
for_loop:
for_loop ::= 'for' IDENTIFIER 'in' range block
referenced by:
- loop_statement
range:
range ::= expression range_operator expression
referenced by:
- for_loop
range_operator:
range_operator
::= '..'
| '..='
referenced by:
- range
switch_statement:
switch_statement
::= 'check' expression '{' pattern_case* default_case '}'
referenced by:
- control_flow
pattern_case:
pattern_case
::= 'is' pattern ':' block
referenced by:
- switch_statement
default_case:
default_case
::= 'else' ':' block
referenced by:
- switch_statement
pattern:
pattern ::= literal
| IDENTIFIER
| array_expression
referenced by:
- pattern_case
function_definition:
function_definition
::= 'create' IDENTIFIER '(' parameter_list ')' block
referenced by:
- statement
parameter_list:
parameter_list
::= ( IDENTIFIER ( ',' IDENTIFIER )* )?
referenced by:
- function_definition
block:
block ::= '{' statement* '}'
referenced by:
- default_case
- error_handling
- finish_block
- for_loop
- function_definition
- if_statement
- pattern_case
- rescue_block
- try_block
- while_loop
expression_statement:
expression_statement
::= expression ';'
referenced by:
- statement
expression:
expression
::= literal
| IDENTIFIER
| binary_expression
| function_call
| array_expression
referenced by:
- argument_list
- array_elements
- binary_expression
- constant_declaration
- expression_statement
- if_statement
- range
- switch_statement
- variable_declaration
- while_loop
literal:
literal ::= NUMBER
| STRING
| BOOLEAN
referenced by:
- expression
- pattern
binary_expression:
binary_expression
::= expression operator expression
referenced by:
- expression
operator:
operator ::= '+'
| '-'
| '*'
| '/'
| '%'
| '**'
| '//'
| '=='
| '!='
| '<'
| '<='
| '>'
| '>='
| '&&'
| '||'
| '!'
referenced by:
- binary_expression
function_call:
function_call
::= IDENTIFIER '(' argument_list ')'
referenced by:
- expression
argument_list:
argument_list
::= ( expression ( ',' expression )* )?
referenced by:
- function_call
array_expression:
array_expression
::= '[' array_elements ']'
referenced by:
- expression
- pattern
array_elements:
array_elements
::= ( expression ( ',' expression )* )?
referenced by:
- array_expression
array_operation:
array_operation
::= 'array' '[' operation ']'
operation:
operation
::= '^+'
| '+^'
| '^-'
| '-^'
| 'start:end'
| '::step'
referenced by:
- array_operation
error_handling:
error_handling
::= 'try' block 'rescue' block ( 'finish' block )?
referenced by:
- statement
try_block:
try_block
::= 'try' block
rescue_block:
rescue_block
::= 'rescue' block
Note
Generated by [Railroad Diagram Generator][https://bottlecaps.de/rr/ui]
This project is licensed under the Apache 2.0 License — see the LICENSE file for details.
© 2024-2025 Kenneth Oliver. All rights reserved.