This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a TypeScript-based compiler and IDE for Java-- (a simplified version of Java). The project is organized as a monorepo with two main packages:
- compiler: Lexical analyzer, parser, intermediate code generator, and interpreter
- ide: Next.js-based web IDE with Monaco Editor integration
cd packages/compiler
# Run the compiler on input-code.java
npm run start
# Build TypeScript to JavaScript
npm run build
# Run the built output
npm run run-build
# Run tests with Vitest
npm run testcd packages/ide
# Start Next.js development server (runs on localhost:3001)
npm install && npm run dev
# Build for production
npm run build
# Start production server
npm start
# Lint the codebase
npm run lintThe root is a simple workspace manager. Install dependencies from the root or individual packages.
The compiler follows a multi-stage architecture:
-
Lexer (
packages/compiler/src/lexer/): Character-by-character tokenizationLexerclass scans source code and generates tokens- Scanner factory pattern (
scanners/factory.ts) dispatches to specialized scanners:comment.ts: Handles single-line (//) and multi-line (/* */) commentsidentifier.ts: Scans identifiers and keywordsnumber.ts: Parses integer and float literalsstring.ts: Processes string literals with escape sequencessymbol-and-operator.ts: Recognizes operators and symbols
-
Token System (
packages/compiler/src/token/):Tokenclass represents lexical units with type, lexeme, line, and columnTOKENSconstants define all token types (literals, operators, keywords, symbols)TokenIteratorwraps token array with parsing utilities (peek, next, consume, match)
-
Parser/Grammar (
packages/compiler/src/grammar/syntax/):- Recursive descent parser with one file per grammar production
- Each
*Stmt.tsfile corresponds to a non-terminal in the grammar - Entry point:
function-call.ts(expects<type> IDENT '(' ')' <block>) - Grammar productions are documented in their respective files via
@derivationcomments
-
Intermediate Code Generation (
packages/compiler/src/ir/):Emitterclass generates three-address code during parsing- Generates temporary variables (
__temp0,__temp1, ...) and labels (__label0,__label1, ...) - Instructions include: arithmetic ops, logical ops, relational ops, assignments, jumps, labels, function calls
-
Interpreter (
packages/compiler/src/interpreter/):Interpreterclass executes the intermediate code- Maintains symbol table (variables map), label table, and instruction pointer
- Supports system calls:
PRINTandSCANfor I/O - I/O operations are abstracted via
stdout/stdincallbacks passed to constructor
input-code.java → Lexer → Token[] → TokenIterator → Grammar/Parser (w/ Emitter) → Instruction[] → Interpreter → Output
The IDE is a Next.js (Pages Router) app using Tailwind CSS v4, shadcn/radix-ui components, and React 19.
Pages:
/— Home/landing page/login,/register— Auth pages/dashboard— User dashboard/exercises/workspace— Main IDE workspace (Monaco Editor)/exercises/[id],/classes/[id],/submissions/[id]— LMS entity pages
API Routes (src/pages/api/):
/api/lexer— Accepts source code + optional keyword map, returns token analysis/api/intermediator— Returns intermediate code instructions/api/auth/login,/api/auth/register,/api/auth/me— Auth (no password hashing; email lookup only for local dev)/api/classes/,/api/exercises/,/api/submissions/— LMS CRUD and/submissions/validate
Database: Backend uses SQLAlchemy async with Alembic migrations. IDE data access no longer depends on Prisma.
cd backend
uv run alembic upgrade head # Apply migrations (dev)
uv run alembic revision --autogenerate -m "describe change"React Contexts (src/contexts/) — All provided in _app.tsx:
EditorContext— Monaco editor instance, source code, file loading/saving, line markersKeywordContext— Customizable Java-- keywords (13 keywords remappable, persisted in localStorage);buildKeywordMap()returns the map sent to the lexer APITerminalContext— Terminal open/close stateThemeContext,ToastContext,RuntimeErrorContext
Hooks (src/hooks/):
useEditor— ConsumesEditorContextuseFileSystem— Client-side virtual file system backed bylocalStorage(key:files-storage)useEditorWithFileSystem— Combines editor + file systemuseLexerAnalyse,useIntermediatorCode— Compiler API callsuseExplorer,useSearch— Side explorer panel state
Component Structure:
src/components/ui/— shadcn-style base components (Button, Dialog, Tooltip, etc.)src/components/— Feature components (terminal, token-card, keyword-customizer, etc.)src/views/— Page-level layout compositions (IDE view, token views)
i18n: Next.js built-in i18n with locales pt-BR (default), pt-PT, es, en. Locale files under src/i18n/locales/<locale>/.
Monaco Language: Registered as java-mm via src/utils/compiler/editor/editor-language.ts. Themes editor-glass-dark and editor-glass-light are defined in EditorContext. Keywords update dynamically via KeywordContext.
- The IDE imports the compiler package directly as a local dependency (
@ts-compilator-for-java/compiler).
- Scanner Factory Pattern:
LexerScannerFactory.getInstance()returns appropriate scanner based on character - Recursive Descent Parsing: Each grammar rule is a function that calls other rule functions
- Three-Address Code: All intermediate instructions have at most one operator and three addresses
- Iterator Pattern:
TokenIteratorprovides safe navigation through token stream
The compiler reads from packages/compiler/src/resource/input-code.java by default. Edit this file to test different Java-- programs.
Tests are located in packages/compiler/src/tests/:
lexer/: Tests for individual scanner components (comments, numbers, strings)tokens/: Tests for token classification
When adding new language features:
- Add token definitions in
packages/compiler/src/token/constants/ - Create/update scanner in
packages/compiler/src/lexer/scanners/ - Add grammar production in
packages/compiler/src/grammar/syntax/ - Update emitter logic if new instruction types are needed
- Update interpreter to handle new instruction types
- Add test cases
The codebase has an issue system (packages/compiler/src/issue/):
IssueError: Compilation errors (thrown)IssueWarning: Non-fatal warnings (collected)IssueInfo: Informational messages All issues track line and column position.
- The language is called "Java--" (Java minus minus) - a simplified subset of Java
- Only single-parameter function declarations are currently supported:
<type> IDENT () { ... } - The interpreter is stack-less and uses direct variable lookup by name
- Labels are used for control flow (if/else, loops) instead of structured jumps