Skip to content

EasyLang is an interpreted language with the aim to be as close as possible to clear, spoken, beginner-friendly English. All program structures explicitly use English words rather than symbols or cryptic keywords.

Notifications You must be signed in to change notification settings

greenbugx/EasyLang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyLang — Readable, English-like scripting for learning and prototyping

EasyLang is a compact educational scripting language whose syntax reads like English. It is optimized for clarity and teaching: you can write programs using short English phrases instead of dense punctuation.

This repository contains a minimal interpreter easy_lang.py and a test suite test.elang demonstrating language features.

Table of contents

  • Quick start
  • Language overview
  • Syntax & reference (with examples)
    • Variables and types
    • Expressions and operators
    • Printing and comments
    • Input and typed read
    • Control flow (if / else / else if)
    • Loops (while and for)
    • Functions and return
    • Scoping rules
    • Lists (arrays) — literals, indexing, methods, assignment
    • File I/O
    • Errors and debugging
  • Complete examples
  • Contributing and roadmap
  • License

Quick start

  1. Run the example test program shipped with this repository:
python .\easy_lang.py
  1. Edit test.elang or create your own .elang file and run the interpreter.

Language overview

EasyLang uses English-like keywords and phrases for common programming constructs. The interpreter currently supports:

  • Primitive types: int, float, text (string), boolean (true/false).
  • Arithmetic and string combination with both symbol operators and English word-forms.
  • Lexical (block) scoping for blocks and functions.
  • Native lists with literals, indexing, mutation, and methods (push, pop, length).
  • Functions with parameter lists and local scope, including recursion.
  • File I/O and typed input with validation.

Syntax & reference (with examples)

Each subsection includes example snippets you can copy into test.elang.

Variables and types

  • Declare or reassign with: we let <name> = <expression>

Examples:

we let a = 10
we let b = 3.5
we let name = "Alice"
we let flag = true

Expressions and operators

  • Numeric operators: +, -, *, / and word-forms mul, div.
  • Ambiguous word-forms: and, or, less, greater sometimes act as arithmetic or comparisons — the parser treats them as comparisons inside conditional contexts (like if) and as arithmetic/concatenation in plain expressions.

Examples:

we let x = 5 and 2        $ 5 + 2 => 7
we let s = "Hi" and "!"  $ string concatenation => "Hi!"
we let diff = x less 2     $ 5 - 2 => 3 (in expression context)

Printing and comments

  • Print: so print <expression>
  • Single-line comments: begin with $
  • Multi-line comments: $$ ... $$ (not nestable)

Examples:

so print "Hello, world"
we let msg = "Value: " and 5
so print msg
$ this is a comment
$$
This is a multi-line comment
spanning lines
$$

Input and typed read

  • read int <var> — read and validate integer input
  • read float <var>
  • read text <var> or read <var>
  • read boolean <var> — expects true or false

Example:

so print "Enter an integer:"
read int n
so print "You entered: " and n

Control flow (if / else / else if)

  • Syntax: if <condition> then [ ... ] else [ ... ]
  • else if supported.

Example:

we let score = 85
if score greater 90 then [
  so print "Grade: A"
] else if score greater 80 then [
  so print "Grade: B"
] else [
  so print "Lower grade"
]

Loops (while and for)

  • While: repeat while <condition>: do [ ... ]
  • For: repeat from <var> = <start> to <end>: do [ ... ] (inclusive)

Examples:

we let i = 3
repeat while i greater 0: do [
  so print i
  we let i = i less 1
]

repeat from j = 1 to 5: do [
  so print j
]

Functions and return

  • Define: define name(p1, p2): do [ ... ]
  • Use return <expr> inside functions to return a value. If no return executes, the function returns null/None.

Examples:

define add(x, y): do [
  return x and y
]
we let result = add(2, 3)
so print result

define fact(n): do [
  if n less 2 then [
    return 1
  ] else [
    we let sub = n less 1
    we let rec = fact(sub)
    return n mul rec
  ]
]
so print fact(5)

Scoping rules

  • Blocks and functions create inner (lexical) scopes. we let assigns in the current innermost scope; shadowing is supported.
  • Loop variables and declarations inside blocks do not leak to outer scopes.

Example:

we let outer = 1
if outer equals 1 then [
  we let outer = 10
  so print outer   $ prints 10 (inner)
]
so print outer       $ prints 1 (outer unchanged)

Lists (arrays) — literals, indexing, methods, assignment

  • List literal: [expr1, expr2, ...] (elements can be mixed types or lists)
  • Indexing: a[0] (zero-based)
  • Element assignment: a[1] = 42 (must be in bounds)
  • Methods: a.push(x), a.pop(), a.length()

Examples:

we let nums = [1, 2, 3]
so print nums            $ [1, 2, 3]
so print nums[0]         $ 1
nums.push(4)
so print nums            $ [1,2,3,4]
we let last = nums.pop()
so print last            $ 4
so print nums.length()   $ 3
nums[1] = 42
so print nums            $ [1, 42, 3]

we let nested = [1, [2,3], "hi"]
so print nested[1][0]   $ 2

Note: push modifies the list in place and returns None/null. pop returns the removed element.

Dictionaries (key-value mappings)

  • Dictionary literal: { key: value, ... } — keys may be unquoted identifiers (treated as strings), string literals, or numeric literals.
  • Indexing: d["key"] or d[identifier] — use bracket indexing for dictionary lookup.
  • Assignment: d["key"] = value updates or creates entries.
  • Methods: d.keys() → list of keys, d.values() → list of values, d.has(key) → boolean, d.length() → number of entries.

Examples:

we let person = { name: "Alice", age: 30 }
so print person
so print person["name"]
so print person["age"]
person["age"] = 31
so print person["age"]
so print person.keys()
so print person.values()
so print person.has("name")
so print person.has("email")

File I/O

  • open "path" as <handle> for read|write|append
  • writeline <handle> with <expression> — writes value and newline
  • readline <handle> into <var> — reads a single line (empty string on EOF)
  • close <handle>

Example:

open "tmp_test.txt" as fh for write
writeline fh with "Line1"
close fh
open "tmp_test.txt" as fh for read
readline fh into first
close fh
so print first

Errors and debugging

  • The interpreter reports SyntaxError with token and line information where available.
  • RuntimeError is raised for type or semantic errors (e.g., indexing non-list, invalid input conversion).
  • Validation for read int and read float is performed at runtime and will raise an error for invalid entries.

Complete examples

Below are full runnable examples you can copy into test.elang to exercise features end-to-end.

  1. Arithmetic, strings, and boolean mixing
we let x = 5
we let y = 3
we let name = "John"
so print x and y
so print name and " Doe"
so print true and false
  1. Loops and accumulation
we let sum = 0
repeat from i = 1 to 5: do [
  we let sum = sum and i
]
so print sum
  1. Lists and iteration
we let nums = [10, 20, 30]
nums.push(40)
so print nums
repeat from i = 0 to nums.length() less 1: do [
  so print nums[i]
]
  1. Functions and recursion
define fib(n): do [
  if n less 2 then [
    return n
  ] else [
    return fib(n less 1) and fib(n less 2)
  ]
]
so print fib(6)

Contributing and roadmap

  • The interpreter is intentionally small and educational. Suggested improvements:
    • Additional built-in list utilities and higher-order helpers
    • Module/import system
    • REPL mode
    • More data types and standard library functions

License

MIT — see repository for details.


About

EasyLang is an interpreted language with the aim to be as close as possible to clear, spoken, beginner-friendly English. All program structures explicitly use English words rather than symbols or cryptic keywords.

Topics

Resources

Stars

Watchers

Forks

Languages