{"id":16627024,"url":"https://github.com/eatonphil/jsforth","last_synced_at":"2025-03-21T15:31:14.634Z","repository":{"id":29911133,"uuid":"33456962","full_name":"eatonphil/jsforth","owner":"eatonphil","description":"A Forth REPL in Javascript.","archived":false,"fork":false,"pushed_at":"2023-02-05T01:23:31.000Z","size":123,"stargazers_count":47,"open_issues_count":2,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T02:36:03.074Z","etag":null,"topics":["forth"],"latest_commit_sha":null,"homepage":"http://codepen.io/eatonphil/full/YPbWVN/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eatonphil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-05T22:11:13.000Z","updated_at":"2025-01-29T08:07:18.000Z","dependencies_parsed_at":"2023-02-19T13:15:29.163Z","dependency_job_id":null,"html_url":"https://github.com/eatonphil/jsforth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eatonphil%2Fjsforth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eatonphil%2Fjsforth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eatonphil%2Fjsforth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eatonphil%2Fjsforth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eatonphil","download_url":"https://codeload.github.com/eatonphil/jsforth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244822627,"owners_count":20516140,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["forth"],"created_at":"2024-10-12T04:13:02.151Z","updated_at":"2025-03-21T15:31:14.335Z","avatar_url":"https://github.com/eatonphil.png","language":"JavaScript","readme":"# JSForth\n\nThis is a micro-Forth implementation in Javascript. It is built around an HTML REPL.\n\nI wrote this two years ago during a PL course in college. The code is not the greatest; it only took a few hours to throw together. That said, it is pretty neat.\n\n# Try It Out\n\nA demonstration REPL is available via CodePen [here](http://codepen.io/eatonphil/full/YPbWVN/).\n\nAlternatively, it can be run locally by navigating to the provided index.html file.\n\n# Built-in Commands\n\n```\n+ - / * ^ \u003c \u003e \u003c= \u003e= = != \n    ex: a b + // displays: Stack: (a+b)  \n\n. - returns the top element of the Stack  \n    ex: a b . // displays: b; Stack: a  \n\n.s - displays the current Stack and the size  \n    ex: a b .s // displays: a b \u003c2\u003e; Stack: a b  \n\n.c - displays the top of the Stack as a character\n    ex: 0 97 .c // displays: a \u003cok\u003e; Stack: 0 97\n\ndrop - pops off the top element without returning it  \n    ex: a b drop // displays: nothing; Stack: a  \n\npick - puts a copy of the nth element on the top of the Stack  \n    ex: a b c 2 pick // displays: nothing; Stack: a b c a  \n\nrot - rotates the Stack clockwise\n    ex: a b c rot // displays: nothing; Stack: b c a\n\n-rot - rotates the Stack counter-clockwise\n    ex: a b c -rot // displays: nothing; Stack c a b\n\nswap - swaps the top two elements  \n    ex: a b // displays: nothing; Stack: b a  \n\nover - copies the second-to-last element to the top of the Stack  \n    ex: a b over // displays: nothing; Stack: a b a  \n\ndup - copies the top element  \n    ex: a b dup // displays: nothing; Stack: a b b  \n\nif ... then - executes what follows \"if\" if it evaluates true, continues on normally after optional \"then\"  \n    ex: a b \u003e if c then d // displays: nothing; Stack: a b c d //if a \u003e b; Stack: a b d //if a \u003c= b  \n\ndo ... [loop] - executes what is between \"do\" and \"loop\" or the end of the line  \n    ex: a b c do a + // displays: nothing; Stack: adds a to itself b times starting at c \n\ninvert - negates the top element of the Stack  \n    ex: a invert // displays: nothing; Stack: 0 //a != 0; Stack: 1 //a == 0  \n\nclear - empties the Stack  \n    ex: a b clear // displays: nothing; Stack:  \n\n: - creates a new custom (potentially recursive) definition  \n    ex: a b c : add2 + + ; add2 // displays: nothing; Stack: (a+b+c)  \n\nallocate - reallocates the max recursion for a single line of input  \n    ex: 10 allocate\n\ncls - clears the screen  \n\ndebug - toggles console debug mode\n```\n\n# Examples\n\n## Basics\n\n```\n\u003e\u003e\u003e 3 4 +\n    \u003cok\u003e\n\u003e\u003e\u003e .s\n    7 \u003cok\u003e\n\u003e\u003e\u003e 3 4 - .s\n    -1 \u003cok\u003e\n\u003e\u003e\u003e 3 4 \u003c .s\n    1 \u003cok\u003e\n\u003e\u003e\u003e 3 4 \u003e .s\n    0 \u003cok\u003e\n\u003e\u003e\u003e 3 dup .s\n    3 3 \u003cok\u003e\n\u003e\u003e\u003e = .s\n    1 \u003cok\u003e\n\u003e\u003e\u003e drop\n    \u003cok\u003e\n\u003e\u003e\u003e .s\n    \u003cok\u003e\n```\n\n## Conditions\n\n```\n\u003e\u003e\u003e 3 4 \u003c if 11 then 12\n    \u003cok\u003e\n\u003e\u003e\u003e .s\n    11 12 \u003cok\u003e\n\u003e\u003e\u003e 3 4 \u003e if 12 then 14 .s\n    14\n```\n\n## Functions\n\n```\n\u003e\u003e\u003e : plus + ;\n    \u003cok\u003e\n\u003e\u003e\u003e 2 3 plus\n    5 \u003cok\u003e\n```\n\n## Loops\n\n### Power Function\n\n```\n\u003e\u003e\u003e : pow over swap 1 do over * loop swap drop ;\n    \u003cok\u003e\n\u003e\u003e\u003e 2 3 pow .s\n    8 \u003cok\u003e\n```\n\n## Recursion\n\n### Fibonacci\n\n```\n\u003e\u003e\u003e : fib dup 1 \u003e if 1 - dup fib swap 1 - fib + then ;\n    \u003cok\u003e\n\u003e\u003e\u003e 6 fib .s\n    8 \u003cok\u003e\n```\n\n### Factorial\n\n```\n\u003e\u003e\u003e : fac dup 1 \u003e if dup 1 - fac * then dup 0 = if drop 1 then dup 1 = if drop 1 then ;\n    \u003cok\u003e\n\u003e\u003e\u003e 3 fac\n    6 \u003cok\u003e\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Featonphil%2Fjsforth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Featonphil%2Fjsforth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Featonphil%2Fjsforth/lists"}