Prototype

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.

LayerImplementationSignal
GrammarEBNF-style grammar.txtThe language rules are inspectable.
LexerDFA-style maximal-munch tokenizerText scanning is separated from parsing.
ParserLL(1) recursive-descent methodsProductions map directly to code.
Selection setsExplicit FIRST/selection constantsBranching is deliberate, not guessed.
Static checksScoped definitions and function arityInvalid names fail before execution.
OutputYES. / 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.

Built with

Java 17LexerLL(1)Recursive descentContext-free grammar