Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CONST

A tiny interpreter in Elm that evaluates non-negative integer constants and establishes the interpreter structure reused throughout Tiny Interpreters.

Read CONST: The Structure of a Tiny Interpreter in Elm for a guided explanation of how it works.

flowchart TD
    A["123"] -->|parse| B["Program (Const 123)"]
    B -->|evaluate| C["VNumber 123"]
Loading

Usage

You’ll need Nix with flakes enabled.

Enter the development environment and start the Elm REPL:

nix develop
elm repl

Import the interpreter and run a program:

import CONST.Interpreter as I

I.run "123"
-- Ok (VNumber 123)

Language

CONST supports one kind of expression: a non-negative integer constant.

123

The parser converts the source text into an abstract syntax tree:

Program (Const 123)

The interpreter then evaluates the AST to a value:

VNumber 123

Interpreter structure

CONST introduces the structure that the later interpreters build on:

source text → AST → value

Although the language contains only constants, the project includes the same main parts that will remain as the language grows:

  • a grammar that describes valid programs
  • a lexer that recognizes non-negative integer literals
  • an AST that represents the program in Elm
  • a parser that turns source text into an AST
  • evaluation logic that turns the AST into a value
  • tests that describe the behaviour of the language

Tiny Interpreters

CONST is the first interpreter in Tiny Interpreters, a blog about learning how programming languages work by building tiny interpreters.

About

A tiny interpreter in Elm that evaluates non-negative integer constants and establishes the interpreter structure reused throughout Tiny Interpreters.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages