Appendix — Full Grammar (EBNF)¶
This appendix provides a complete grammar summary of EasyLang in a simplified EBNF-like notation.
It reflects how the interpreter parses code internally using its recursive-descent parser.
This is not a rigid compiler-formal grammar, but a clean, human-readable representation of the rules EasyLang follows.
1. Program Structure¶
program = statement* ;
A program is a sequence of statements executed top-to-bottom.
2. Statements¶
statement = assignment
| print_statement
| if_statement
| repeat_while
| repeat_from
| function_definition
| return_statement
| bring_statement
| file_statement
| break_statement
| continue_statement
| expression_statement ;
3. Assignment¶
assignment = "we let" IDENT "=" expression ;
Examples:
we let x = 10
we let name = "GreenBugX"
4. Printing¶
print_statement = "so print" expression ;
Example:
so print x plus 1
5. Conditionals¶
if_statement = "if" expression "then" block
("else if" expression "then" block)*
("else" block)? ;
Example:
if x equals 10 then [
...
] else if x greater 20 then [
...
] else [
...
]
6. Loops¶
Repeat-While Loop¶
repeat_while = "repeat" "while" expression ":" "do" block ;
Repeat-From Loop¶
repeat_from = "repeat" "from" IDENT "=" expression
"to" expression ":" "do" block ;
7. Functions¶
Function Definition¶
function_definition = "define" IDENT "(" arglist ")" ":" "do" block ;
arglist = (IDENT ("," IDENT)*)? ;
Example:
define add(a, b): do [
return a plus b
]
8. Return¶
return_statement = "return" expression ;
9. Bring (Module Import)¶
bring_statement = "bring" (STRING | IDENT) "as" IDENT ;
Examples:
bring "math.elangh" as math
bring math as m
10. File Operations¶
file_statement = file_open
| file_writeline
| file_readline
| file_close ;
Open¶
file_open = "open" STRING "as" IDENT "for" ("read" | "write" | "append") ;
Write Line¶
file_writeline = "writeline" IDENT "with" expression ;
Read Line¶
file_readline = "readline" IDENT "into" IDENT ;
Close¶
file_close = "close" IDENT ;
11. Continue & Break¶
continue_statement = "continue" ;
break_statement = "break" ;
12. Blocks¶
block = "[" statement* "]" ;
Blocks create new scopes.
13. Expressions¶
EasyLang expressions follow a precedence hierarchy.
expression = logical_or ;
13.1 Logical OR¶
logical_or = logical_and ( "or" logical_and )* ;
13.2 Logical AND¶
logical_and = equality ( "and" equality )* ;
13.3 Equality¶
equality = comparison
(("equals" | "not equals" | "==" | "!=") comparison)* ;
13.4 Comparison¶
comparison = term
(("<" | ">" | "<=" | ">=" | "less" | "greater") term)* ;
13.5 Term (Addition / Subtraction)¶
term = factor
(("plus" | "minus" | "+" | "-") factor)* ;
13.6 Factor (Multiplication / Division)¶
factor = unary
(("mul" | "div" | "" | "/") unary) ;
13.7 Unary¶
unary = ("not") unary
| call ;
13.8 Function Calls & Attribute Access¶
call = primary
( "(" argument_list? ")" # function_call
| "." IDENT # attribute_access
)* ;
argument_list = expression ("," expression)* ;
Examples:
math.sqrt(25)
user.name.upper()
list.push(5)
13.9 Primary Expressions¶
primary = NUMBER
| STRING
| "true"
| "false"
| IDENT
| list_literal
| dict_literal
| "(" expression ")" ;
14. List Literals¶
list_literal = "[" (expression ("," expression)*)? "]" ;
Examples:
[1, 2, 3]
["a", "b", "c"]
15. Dictionary Literals¶
dict_literal = "{"
(STRING ":" expression
("," STRING ":" expression)*
)?
"}" ;
Example:
{
"name": "GreenBugX",
"age": 16
}
16. Tokens (Lexical Layer)¶
IDENT = letter (letter | digit | "_")* ;
NUMBER = digit+ ("." digit+)? ;
STRING = '"' (anything except '"')* '"' ;
KEYWORDS = many reserved words ("we let", "if", "repeat", ...)
For details, see Lexical Structure.
Summary¶
This appendix provides a full overview of the EasyLang grammar in EBNF form.
It summarizes:
- program structure
- all statement forms
- all expression types
- operator precedence
- function definitions and calls
- loops
- modules
- file operations
- literals
- lists and dictionaries
- full lexical details
Use this appendix as a quick reference when reading or writing EasyLang code, or when extending the interpreter itself.