Karel-Lite parser
A Java 17 lexer and LL(1) recursive-descent parser for a Karel-style teaching language, with YES/NO validation and static-scope checks.
Karel-Lite is the smaller, stricter sibling to the robot DSL. It is not trying to be a full programming environment. Its value is narrower and cleaner: take a Karel-style teaching language, define its grammar, tokenize the source, and answer a precise compiler-front-end question.
Is this program valid?
The parser prints YES. when a source program satisfies the grammar and static
scope rules. It prints NO. <reason> when the failure is lexical, syntactic, or
semantic enough to catch before execution.
| Layer | Implementation | Signal |
|---|---|---|
| Grammar | EBNF-style grammar.txt | The language rules are inspectable. |
| Lexer | DFA-style maximal-munch tokenizer | Text scanning is separated from parsing. |
| Parser | LL(1) recursive-descent methods | Productions map directly to code. |
| Selection sets | Explicit FIRST/selection constants | Branching is deliberate, not guessed. |
| Static checks | Scoped definitions and function arity | Invalid names fail before execution. |
| Output | YES. / NO. <diagnostic> | The contract is simple and testable. |
The interesting part is the boundary between formal language theory and normal software structure. The grammar defines non-terminals like program, instruction list, command, control structure, condition, function definition, and function call. The Java parser then mirrors that grammar with one method per production, using selection sets to decide which branch is legal from the next token.
That makes the code easy to audit: when parsing fails, the error is not hidden inside a generator. You can inspect the token stream, the production being walked, and the scope rule that rejected the program.
This is useful portfolio material because it shows low-level clarity: no magic framework, no black-box parser generator, just language rules expressed directly in code. It belongs in the Lab rather than Work because it is a compact technical artifact, not a client case study.
Repository: karel-lite-parser.