Skip to content

Expressions

Expressions are one of the most important parts of EasyLang.
They are the pieces of code that produce values, such as numbers, strings, lists, calculations, comparisons, method calls, and more.

This chapter explains every type of expression EasyLang supports.


What Is an Expression?

An expression is anything that evaluates to a value.

Examples:

10
"hello"
x plus 5
user.name
list.push(5)
a equals b

Expressions can appear:

  • on the right side of assignments
  • inside print statements
  • inside conditions
  • inside return statements
  • inside function calls
  • as standalone statements (method calls, etc.)

Types of Expressions

EasyLang supports these major categories:

  1. Literals
  2. Identifiers (variables)
  3. Unary Expressions
  4. Binary Expressions
  5. List & Dictionary Literals
  6. Attribute / Method Access
  7. Function Calls
  8. Parenthesized Expressions

Each one is described below.


1. Literal Expressions

Literals are raw values written directly in the code.

Number literals

10
3.14
0.001

String literals

"hello"
"EasyLang"

Boolean literals

true
false

Null (implicit)

If a function returns nothing, it returns an internal null value.

List literals

[1, 2, 3]
["a", "b", "c"]

Dictionary literals

{
"name": "GreenBugX",
"age": 16
}

Keys must be strings.


2. Identifiers (Variable Expressions)

Identifiers refer to variable names:

x
name
total
user.age

If an identifier is used before assignment, the interpreter raises a friendly runtime error.


3. Unary Expressions

Unary expressions affect a single value.

Supported unary operator: not <expression>

Examples:

not true
not x equals 10


4. Binary Expressions

Binary expressions combine two values:

a plus b
x minus 1
value mul 10
x div y

Binary operators follow natural English keywords (symbols also supported).


4.1. Arithmetic Operators

Operator Meaning
plus or + addition
minus or - subtraction
mul or * multiplication
div or / division

Examples:

x plus 10
price mul quantity
value / 2


4.2. Comparison Operators

Operator Meaning
equals / == equality
not equals / != inequality
less <
greater >
<= less or equal
>= greater or equal

Examples:

x equals 10
name not equals "John"
age greater 18


4.3. Logical Operators

Operator Meaning
and logical AND
or logical OR

Examples:

x greater 10 and x less 20
logged_in or is_admin


5. List & Dictionary Expressions

List access and methods

nums.push(5)
nums.len()

Dictionary key access

user.name
config.port

These use the attribute-access syntax described below.


6. Attribute Access (Dot Expressions)

EasyLang uses dot notation to access:

  • dictionary properties
  • module functions
  • built-in methods
  • Python module attributes

Example:

user.name
math.sqrt(25)
list.push(10)
str.upper("hello")

Grammar: expression '.' IDENTIFIER

This lets you chain calls: text.strip().upper()


7. Function Call Expressions

Function calls look like: name(arg1, arg2, ...)

Example: add(10, 20)

With method calls:

nums.push(5)
user.name.upper()

Argument list grammar:

(call) expression '(' (expression (',' expression)*)? ')'

Everything inside the parentheses is evaluated first.


8. Parenthesized Expressions

You can force evaluation order with: ( expression )

Example: so print (2 plus 3) mul 5 $ prints 25

Without parentheses: 2 plus 3 mul 5 $ prints 17 (3*5 = 15 -> 15+2 = 17)


Operator Precedence (Actual Parsing Order)

EasyLang respects this order:

  • Parentheses ( )
  • Dot expressions (obj.method)
  • Function calls
  • Unary operators (not)
  • Multiplication / Division
  • Addition / Subtraction
  • Comparisons (equals, <, >, etc.)
  • Logical AND
  • Logical OR

This is implemented through recursive descent parsing.


Complex Expression Examples

Nested Expressions x plus (y mul 3)

Mixed Logical + Comparison

if x greater 10 and y less 5 then [
    so print "valid"
]

Attribute chaining config.database.port

Function inside function so print add(sqrt(25), 10)


Summary

Expressions in EasyLang include:

  • literals
  • variables
  • calculations
  • comparisons
  • logical operations
  • lists and dictionaries
  • function calls
  • attribute access
  • parentheses

They can be combined freely to create powerful logic using simple English-like structure.


Next Steps

Continue to Variables & Scopes to learn how Variables & Scopes work in detail