A modern, Python-inspired procedural programming language with C-based syntax.
makemake test-allmake test-parsermake test-lexermake cleanEaC (easy) is a dynamically-typed programming language that combines:
- C-based operators (+, -, *, /, %, ^, |, ==, !=, etc.)
- Python-inspired syntax (clean, minimal, with significant indentation)
- Developer-friendly features (flexible variables, intuitive keywords)
- ✅ Dynamic Variables -
flexkeyword for mutable variables - ✅ Constants -
fixedkeyword for immutable values - ✅ Type Hints - Optional type annotations (int, float, str, bool, char)
- ✅ Control Flow -
when/elseconditionals,while/forloops - ✅ Functions - First-class function support
- ✅ Comments - Single-line (#) and multi-line (/* */) comments
- ✅ Noise Words - Readability keywords (
to,of,then,each,as) which are ignored by the parser.
The Lexer transforms raw source code into a stream of tokens.
Step-by-Step Execution:
- Initialization:
initLexer(source)sets up the lexer state, pointing to the start of the source string. - Scanning Loop: The main loop calls
scanToken()repeatedly.- Whitespace Handling:
scanTokenskips spaces. If it encounters a newline, it calculates indentation. - Indentation Tracking: The lexer maintains a stack of indentation levels. If indentation increases, it emits
TOKEN_INDENT. If it decreases, it emits one or moreTOKEN_DEDENTtokens. - State Machine: Characters are processed through a finite state machine (FSM) to identify tokens:
"triggers string state.- Digits trigger number state.
- Letters trigger identifier/keyword state.
- Keyword Matching: Identifiers are checked against a trie or hash map to determine if they are reserved keywords (e.g.,
flex,when).
- Whitespace Handling:
- Token Generation: valid lexemes are packaged into
Tokenstructs containing the type, lexeme string, line number, and column number.
The Parser consumes tokens to build an Abstract Syntax Tree (AST).
Step-by-Step Execution:
- Initialization:
initParser(lexer)prepares the parser. - Recursive Descent: The
parse()function callsstatements(), which recursively calls functions for specific grammar rules:statements()->statement()statement()parses specific constructs likeimpl_varDecl,impl_ifStmt, etc.
- Expression Parsing: Uses a precedence climbing algorithm (or similar) to handle operator precedence (e.g.,
*binds tighter than+). - Error Handling:
- If a syntax error occurs (e.g., missing expected token),
errorAt()is called. - The parser enters "panic mode" to suppress cascading errors.
synchronize()skips tokens until a statement boundary (newline/semicolon) is found to recover.- Statement Termination:
checkStatementEnd()ensures statements end with a newline or EOF, preventing malformed constructs from entering the AST.
- If a syntax error occurs (e.g., missing expected token),
- AST Construction: Successful parses create
ASTNodestructures (e.g.,AST_BINARY_OP,AST_VAR_DECL).
The project includes a robust test suite.
tests/demo/: Contains demonstration files (e.g.,test_main.eac,test_criteria_compliance.eac).tests/: Root tests for specific language features.
eac/
├── src/
│ ├── main.c # Entry point
│ ├── common/
│ │ └── token.h # Token definitions
│ ├── lexer/
│ │ ├── lexer.h # Lexer interface
│ │ └── lexer.c # Lexer implementation & FSM
│ ├── parser/ # Parser module
│ │ ├── parser.c # Recursive descent parser
│ │ ├── parser.h # Parser interface
│ │ ├── ast.c # AST node creation & printing
│ │ └── ast.h # AST structure definitions
├── tests/
│ ├── demo/ # Demo & compliance tests
│ │ ├── test_main.eac
│ │ └── test_criteria_compliance.eac
│ ├── parser/ # Parser-specific tests
│ └── ... # Other feature tests
├── output/ # Generated artifacts (symbol tables, AST dumps)
├── docs/ # Documentation
├── Makefile # Build system
└── README.md # This file
- ✅ Lexical Analyzer: Complete. accurate tokenization including complex indentation handling.
- ✅ Parser: Functional. Generates AST for declarations, expressions, control flow, and functions. Robust error handling implemented.
- ⏳ Semantic Analyzer: Planned.
- ⏳ Code Generator: Planned.
EaC Compiler Development Team