{"id":16580220,"url":"https://github.com/davidedc/lw-toy-imperative-language","last_synced_at":"2026-04-17T22:31:02.812Z","repository":{"id":7786163,"uuid":"9156104","full_name":"davidedc/LW-toy-imperative-language","owner":"davidedc","description":"an interpreter (in Java) for the LW didactic imperative language, sometimes used to teach the fundamentals of parsing, static checking, execution of imperative languages.","archived":false,"fork":false,"pushed_at":"2013-05-06T20:20:18.000Z","size":120,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T23:45:07.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidedc.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-01T21:05:42.000Z","updated_at":"2014-01-07T05:49:04.000Z","dependencies_parsed_at":"2022-09-05T08:00:51.423Z","dependency_job_id":null,"html_url":"https://github.com/davidedc/LW-toy-imperative-language","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/davidedc/LW-toy-imperative-language","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedc%2FLW-toy-imperative-language","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedc%2FLW-toy-imperative-language/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedc%2FLW-toy-imperative-language/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedc%2FLW-toy-imperative-language/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidedc","download_url":"https://codeload.github.com/davidedc/LW-toy-imperative-language/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedc%2FLW-toy-imperative-language/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31948335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T22:24:19.928Z","updated_at":"2026-04-17T22:31:02.796Z","avatar_url":"https://github.com/davidedc.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"A small interpreter for the didactic (toy) LW imperative language.\n======\n\nLW is a minimal imperative language used in some universities to teach the basics of imperative languages, and the concepts of static analysis, basic parsing, handling scope, what a state is, the difference between an expression and a command, and how to walk an AST tree to do static checks and to run the program.\n\nI did this compact LW (and its older brother, LWPlus) interpreter at uni in 1998. Funnily enough, I couldn't find recent references to LW, so actually I had to reverse engineer the semantics of the language (and some examples) reading my very old undocumented code.\n\nThe language supports one type only (ints), it supports C-like block scoping rules and while loops. Programs read data from a file, and print out the calculated output. There is no support function definition / invocation.\n\nThere are two neat things about this: how compact the whole thing is (4 pages of code), and that the grammar for the language is actually not baked in the interpreter. Rather, it's read at runtime from a grammar file which is almost in BNF form, so one could tweak that a little, I thought that was quite cool, at the time :-). The semantics of the static checks and execution are baked in the interpreter though.\n\nTo build the interpreter:\n```\njavac LWInterpreter.java\n```\nUsage:\n```\njava LW grammarFileName progSourceName maxMem dataFile\n```\nTo run the examples program:\n```\njava LW LW.grammar examples/LW/minimal.lw 20 examples/data/nodata.data\njava LW LW.grammar examples/LW/basic.lw 20 examples/data/zero.data\njava LW LW.grammar examples/LW/factorial.lw 20 examples/data/one.data\njava LW LW.grammar examples/LW/factorial.lw 20 examples/data/two.data\njava LW LW.grammar examples/LW/factorial.lw 20 examples/data/three.data\njava LW LW.grammar examples/LW/factorial.lw 20 examples/data/four.data\n\njava LW LWPlus.grammar examples/LWPlus/minimal.lwplus 20 examples/data/nodata.data\njava LW LWPlus.grammar examples/LWPlus/basic.lwplus 20 examples/data/nodata.data\njava LW LWPlus.grammar examples/LWPlus/plus.lwplus 20 examples/data/one-one.data\njava LW LWPlus.grammar examples/LWPlus/factorial.lwplus 20 examples/data/one.data\njava LW LWPlus.grammar examples/LWPlus/factorial.lwplus 20 examples/data/two.data\njava LW LWPlus.grammar examples/LWPlus/factorial.lwplus 20 examples/data/three.data\njava LW LWPlus.grammar examples/LWPlus/factorial.lwplus 20 examples/data/four.data\n```\n\nExample program (in LWPlus) to calculate factorial:\n```\ndo\n  with PARTIAL begin\n    with COUNTER begin\n      read COUNTER ;\n      PARTIAL := 1 ;\n      while COUNTER \u003c\u003e 1 do\n        PARTIAL := prod PARTIAL COUNTER ;\n        COUNTER := sum COUNTER -1\n      endw ;\n      write PARTIAL\n    end\n  end\nendp\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidedc%2Flw-toy-imperative-language","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidedc%2Flw-toy-imperative-language","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidedc%2Flw-toy-imperative-language/lists"}