Formal language rules (EBNF)
Purpose
This section defines the formal rules for the ARES language. These are the strict instructions that the compiler follows to understand your code. They ensure that every part of your script is interpreted exactly the same way every time.
Why it exists
Without strict rules, a language can be misunderstood. If you write a + b, the computer must know exactly which part to look at first. These rules provide a single source of truth for the entire system.
How it works
The system understands your code by breaking it into a tree. It starts with the whole program and breaks it down into individual statements. Then it breaks those statements into even smaller expressions.
Intuition
Think of these rules like a recipe. The top level tells you how to make the whole meal. The sub-rules tell you how to prepare each ingredient. Every step must follow the recipe exactly for the meal to turn out right.
Rules (EBNF)
ebnfprogram = { statement } ; statement = read_stmt | print_stmt | return_stmt | use_stmt | let_stmt | fn_stmt ; read_stmt = "read" IDENTIFIER [ "as" type_spec ] ; let_stmt = "let" IDENTIFIER [ ":" type_spec ] "=" expression ; is_stmt = [ type_spec ] IDENTIFIER "is" expression ; block = "{" { statement } "}" ;
Technical model
The grammar is a Context-Free Grammar. It is designed so the system can understand your intent in a single pass. It uses a specific pattern to avoid making the compiler choose between two different meanings for the same line.
Trace example
This is what happens when the system reads if x > 0 { print x }:
- It identifies the
ifcommand and starts a conditional check. - It processes the math step
x > 0. - It finds the opening brace and knows a new block of code is starting.
- It identifies the
printcommand inside that block. - It finds the closing brace and finishes the check.
Source attribution
- Standards: Follows the rules defined in ISO/IEC 14977.
- Logic files: The core rules are in
src/parser/parser.tsand the terminal labels are insrc/parser/lexer.ts.