# zForth **Source:** https://github.com/zevv/zForth GitHub - zevv/zForth: zForth: tiny, embeddable, flexible, compact Forth scripting language for embedded systems [Skip to content](#start-of-content) ## Navigation Menu Toggle navigation [Sign in](/login?return_to=https%3A%2F%2Fgithub.com%2Fzevv%2FzForth) Appearance settings * Platform + AI CODE CREATION - [GitHub CopilotWrite better code with AI](https://github.com/features/copilot) - [GitHub SparkBuild and deploy intelligent apps](https://github.com/features/spark) - [GitHub ModelsManage and compare prompts](https://github.com/features/models) - [MCP RegistryNewIntegrate external tools](https://github.com/mcp) + DEVELOPER WORKFLOWS - [ActionsAutomate any workflow](https://github.com/features/actions) - [CodespacesInstant dev environments](https://github.com/features/codespaces) - [IssuesPlan and track work](https://github.com/features/issues) - [Code ReviewManage code changes](https://github.com/features/code-review) + APPLICATION SECURITY - [GitHub Advanced SecurityFind and fix vulnerabilities](https://github.com/security/advanced-security) - [Code securitySecure your code as you build](https://github.com/security/advanced-security/code-security) - [Secret protectionStop leaks before they start](https://github.com/security/advanced-security/secret-protection) + EXPLORE - [Why GitHub](https://github.com/why-github) - [Documentation](https://docs.github.com) - [Blog](https://github.blog) - [Changelog](https://github.blog/changelog) - [Marketplace](https://github.com/marketplace) [View all features](https://github.com/features) * Solutions + BY COMPANY SIZE - [Enterprises](https://github.com/enterprise) - [Small and medium teams](https://github.com/team) - [Startups](https://github.com/enterprise/startups) - [Nonprofits](https://github.com/solutions/industry/nonprofits) + BY USE CASE - [App Modernization](https://github.com/solutions/use-case/app-modernization) - [DevSecOps](https://github.com/solutions/use-case/devsecops) - [DevOps](https://github.com/solutions/use-case/devops) - [CI/CD](https://github.com/solutions/use-case/ci-cd) - [View all use cases](https://github.com/solutions/use-case) + BY INDUSTRY - [Healthcare](https://github.com/solutions/industry/healthcare) - [Financial services](https://github.com/solutions/industry/financial-services) - [Manufacturing](https://github.com/solutions/industry/manufacturing) - [Government](https://github.com/solutions/industry/government) - [View all industries](https://github.com/solutions/industry) [View all solutions](https://github.com/solutions) * Resources + EXPLORE BY TOPIC - [AI](https://github.com/resources/articles?topic=ai) - [Software Development](https://github.com/resources/articles?topic=software-development) - [DevOps](https://github.com/resources/articles?topic=devops) - [Security](https://github.com/resources/articles?topic=security) - [View all topics](https://github.com/resources/articles) + EXPLORE BY TYPE - [Customer stories](https://github.com/customer-stories) - [Events & webinars](https://github.com/resources/events) - [Ebooks & reports](https://github.com/resources/whitepapers) - [Business insights](https://github.com/solutions/executive-insights) - [GitHub Skills](https://skills.github.com) + SUPPORT & SERVICES - [Documentation](https://docs.github.com) - [Customer support](https://support.github.com) - [Community forum](https://github.com/orgs/community/discussions) - [Trust center](https://github.com/trust-center) - [Partners](https://github.com/partners) * Open Source + COMMUNITY - [GitHub SponsorsFund open source developers](https://github.com/sponsors) + PROGRAMS - [Security Lab](https://securitylab.github.com) - [Maintainer Community](https://maintainers.github.com) - [Accelerator](https://github.com/accelerator) - [Archive Program](https://archiveprogram.github.com) + REPOSITORIES - [Topics](https://github.com/topics) - [Trending](https://github.com/trending) - [Collections](https://github.com/collections) * Enterprise + ENTERPRISE SOLUTIONS - [Enterprise platformAI-powered developer platform](https://github.com/enterprise) + AVAILABLE ADD-ONS - [GitHub Advanced SecurityEnterprise-grade security features](https://github.com/security/advanced-security) - [Copilot for BusinessEnterprise-grade AI features](https://github.com/features/copilot/copilot-business) - [Premium SupportEnterprise-grade 24/7 support](https://github.com/premium-support) * [Pricing](https://github.com/pricing) Search or jump to... # Search code, repositories, users, issues, pull requests... Search Clear [Search syntax tips](https://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax) # Provide feedback We read every piece of feedback, and take your input very seriously. Include my email address so I can be contacted Cancel Submit feedback # Saved searches ## Use saved searches to filter your results more quickly Name Query To see all available qualifiers, see our [documentation](https://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax). Cancel Create saved search [Sign in](/login?return_to=https%3A%2F%2Fgithub.com%2Fzevv%2FzForth) [Sign up](/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E&source=header-repo&source_repo=zevv%2FzForth) Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} [zevv](/zevv) / **[zForth](/zevv/zForth)** Public * [Notifications](/login?return_to=%2Fzevv%2FzForth) You must be signed in to change notification settings * [Fork 57](/login?return_to=%2Fzevv%2FzForth) * [Star 408](/login?return_to=%2Fzevv%2FzForth) zForth: tiny, embeddable, flexible, compact Forth scripting language for embedded systems ### License [MIT license](/zevv/zForth/blob/master/LICENSE) [408 stars](/zevv/zForth/stargazers) [57 forks](/zevv/zForth/forks) [Branches](/zevv/zForth/branches) [Tags](/zevv/zForth/tags) [Activity](/zevv/zForth/activity) [Star](/login?return_to=%2Fzevv%2FzForth) [Notifications](/login?return_to=%2Fzevv%2FzForth) You must be signed in to change notification settings * [Code](/zevv/zForth) * [Issues 1](/zevv/zForth/issues) * [Pull requests 2](/zevv/zForth/pulls) * [Actions](/zevv/zForth/actions) * [Projects 0](/zevv/zForth/projects) * [Security 0](/zevv/zForth/security) * [Insights](/zevv/zForth/pulse) Additional navigation options * [Code](/zevv/zForth) * [Issues](/zevv/zForth/issues) * [Pull requests](/zevv/zForth/pulls) * [Actions](/zevv/zForth/actions) * [Projects](/zevv/zForth/projects) * [Security](/zevv/zForth/security) * [Insights](/zevv/zForth/pulse) # zevv/zForth master [Branches](/zevv/zForth/branches)[Tags](/zevv/zForth/tags) Go to file Code Open more actions menu ## Folders and files | Name | | Name | Last commit message | Last commit date | | --- | --- | --- | --- | --- | | Latest commit History[141 Commits](/zevv/zForth/commits/master/) 141 Commits | | | | [.github/workflows](/zevv/zForth/tree/master/.github/workflows "This path skips through empty directories") | | [.github/workflows](/zevv/zForth/tree/master/.github/workflows "This path skips through empty directories") | | | | [forth](/zevv/zForth/tree/master/forth "forth") | | [forth](/zevv/zForth/tree/master/forth "forth") | | | | [src](/zevv/zForth/tree/master/src "src") | | [src](/zevv/zForth/tree/master/src "src") | | | | [.gitattributes](/zevv/zForth/blob/master/.gitattributes ".gitattributes") | | [.gitattributes](/zevv/zForth/blob/master/.gitattributes ".gitattributes") | | | | [.gitignore](/zevv/zForth/blob/master/.gitignore ".gitignore") | | [.gitignore](/zevv/zForth/blob/master/.gitignore ".gitignore") | | | | [LICENSE](/zevv/zForth/blob/master/LICENSE "LICENSE") | | [LICENSE](/zevv/zForth/blob/master/LICENSE "LICENSE") | | | | [Makefile](/zevv/zForth/blob/master/Makefile "Makefile") | | [Makefile](/zevv/zForth/blob/master/Makefile "Makefile") | | | | [README.md](/zevv/zForth/blob/master/README.md "README.md") | | [README.md](/zevv/zForth/blob/master/README.md "README.md") | | | | [zforth.png](/zevv/zForth/blob/master/zforth.png "zforth.png") | | [zforth.png](/zevv/zForth/blob/master/zforth.png "zforth.png") | | | | View all files | | | ## Repository files navigation * [README](#) * [MIT license](#) [![zForth](/zevv/zForth/raw/master/zforth.png)](/zevv/zForth/blob/master/zforth.png) # zForth From Wikipedia: *A Forth environment combines the compiler with an interactive shell, where the user defines and runs subroutines called words. Words can be tested, redefined, and debugged as the source is entered without recompiling or restarting the whole program. All syntactic elements, including variables and basic operators are defined as words. Forth environments vary in how the resulting program is stored, but ideally running the program has the same effect as manually re-entering the source.* zForth is yet another Forth, but with some special features not found in most other forths. Note that zForth was written for engineers, not for language purists or Forth aficionados. Its main intention is to be a lightweight scripting language for extending embedded applications on small microprocessors. It is not particularly fast, but should be easy to integrate on any platform with a few kB's of ROM and RAM. Also note that zForth is just *a* forth, but does not specifically implement or care about any of the standards like ANS Forth - the kernel might or might not behave as the standard, and the current standard library is rather limited. For a lot of programmers Forth seems to belong to the domain of alien languages: it does not look like any mainstream language most people encounter, and is built on a number of philosophies that takes some time to get used to. Still, it is one of the more efficient ways of bringing a interpreter and compiler to a platform with restricted resources. Some of zForth's highlights: * **Small dictionary**: instead of relying on a fixed cell size, the dictionary is written in variable length cells: small and common numbers take less space then larger, resulting in 30% to 50% space saving * **Portable**: zForth is written in 100% ANSI C, and runs on virtually all operating systems and all architectures. Tested on x86 Linux/Win32/MS-DOS (Turbo-C 1.0!), x86\_64, ARM, ARM thumb, MIPS, Atmel AVR and the 8051. * **Small footprint**: the kernel C code compiles to about 3 or 4 kB of machine code, depending on the architecture and chosen cell data types. * **Support for multiple instances**: The compiler and VM state is stored in a struct, allowing multiple instances of zForth to run in parallel. * **Tracing**: zForth is able to show a nice trace of what it is doing under the hood, see below for an example. * **VM**: Implemented as a small virtual machine: not the fastest, but safe and flexible. Instead of having direct access to host memory, the forth VM memory is abstracted, allowing proper boundary checking on memory accesses and stack operations. * **Flexible data types**: at compile time the user is free to choose what C data type should be used for the dictionary and the stacks. zForth supports signed integer sizes from 16 to 128 bit, but also works seamlessly with floating point types like float and double (or even the C99 'complex' type!) * **Ease interfacing**: calling C code from forth is easy through a host system call primitive, and code has access to the stack for exchanging data between Forth and C. Calling forth from C is easy, just one function to evaluate forth code. # Source layout ``` ./forth : core zforth library and various snippets and examples ./src/zforth : zfort core source; embed these into your program ./src/linux : example linux application ./src/atmega8 : example AVR atmega8 application ``` # Usage zForth consists of only two files: zforth.c and zforth.h. Add both to your project and call `zf_init()` and `zf_bootstrap()` during initialisation. Read forth statements from a file or terminal and pass the strings to `zf_eval()` to interpret, compile and run the code. Check the embedded documentation in `zforth.h` for details. `zforth.c` depends on a number preprocessor constants for configuration which you can choose to fit your needs. Documentation is included in the file `zfconf.h`. A demo application for running zForth in linux is provided here, simply run `make` to build. To start zForth and load the core forth code, run: ``` ./src/linux/zforth forth/core.zf ``` And zForth will welcome you with the startup message: ``` Welcome to zForth, 786 bytes used ``` zForth is now ready to use. Try some of the following: Adding one and one or calculate the 144 squared: ``` 1 1 + . 144 dup * . ``` Print the sine of 10 numbers between 0 and PI ``` : pi 3.141592654 ; : demo pi 0 do i sin . pi 10 / loop+ ; demo ``` Load and run the demo Mandelbrot fractal: ``` include forth/mandel.zf .........................----..................... .....................----+--...................... .......................--*-....................... ........................- --.....--............... ...........----........--%---------............... ............-------------#---------............... .............------------ ---------............... .............------------ ---------............... ..............---------o o--------.............. ..............---------o =---------------------- .............----o-oo =o-=--------------.. ...........-------# *------------..... ........--------=-= o-=--------....... ....--------------= =---------........ ......-------------+ +---------......... .......-------------=# %=-----------........ ........--------=- -=--------....... .......------= =------------ .....---o = = =------- --------- -------- ---------o+ +o-------- ---------o =-------- ---=#=# = = #=#=-- ---= =-- -=- + + == o---oo*== -=*=o--- ---------= =-------- ---------#= =#-------- -----------% %------.... ---...----= =% - #= =----..... .......---=o----* =+*---------*+- *----o=----..... ........--------------------------------------.... ``` # Tracing zForth can write verbose traces of the code it is compiling and running. To enable tracing, run `./zforth` with the `-t` argument. Tracing can be enabled at run time by writing `1` in the `trace` variable: ``` 1 trace ! ``` Make sure the feature ZF\_ENABLE\_TRACING is enabled in zfconf.h to compile in tracing support. The following symbols are used: * stack operations are prefixed with a double arrow, `«` means pop, `»` means push. for operations on the return stack the arrow is prefixed with an `r` * the current word being executed is shown in square brackets, the format is `[/
]` * lines starting with a + show values being added to the dictionary * lines starting with a space show the current line being executed, format `
` * lines starting with `===` show the creation of a new word ``` : square dup * ; : test 5 square . ; test ``` Executing the word `test`: ``` test r»0 [test/0326] 0326 0001 ┊ (lit) »5 0328 031c ┊ square/031c r»810 031c 000b ┊ ┊ (dup) «5 »5 »5 031d 0007 ┊ ┊ (*) «5 «5 »25 031e 0000 ┊ ┊ (exit) r«810 032a 0133 ┊ ./0133 r»812 0133 0001 ┊ ┊ (lit) »1 0135 0019 ┊ ┊ (sys) «1 «25 0136 0000 ┊ ┊ (exit) r«812 032c 0000 ┊ (exit) r«0 25 ``` This is the trace of the definition of the `square` and `test` words ``` : square dup * ; r»0 [:/002c] 002c 0003 ┊ (:) 002c 0003 ┊ (:) === create 'square' +0313 0006 ¹ +0314 02eb ² +0316 0000 s 'square' === 002d 0000 ┊ (exit) r«0 +031c 000b ¹ +dup +031d 0007 ¹ +*r»0 [;/0031] 0031 0004 ┊ (;) +031e 0000 ¹ +exit === 0032 0000 ┊ (exit) r«0 : test 5 square . ; r»0 [:/002c] 002c 0003 ┊ (:) 002c 0003 ┊ (:) === create 'test' +031f 0004 ¹ +0320 0313 ² +0322 0000 s 'test' === 002d 0000 ┊ (exit) r«0 +0326 0001 ¹ +lit +0327 0005 ¹ +0328 031c ² +square +032a 0133 ² +.r»0 [;/0031] 0031 0004 ┊ (;) +032c 0000 ¹ +exit === 0032 0000 ┊ (exit) r«0 ``` ### Dependencies The zForth core itself has no external dependencies, the linux example depends on libreadline-dev. ## About zForth: tiny, embeddable, flexible, compact Forth scripting language for embedded systems ### Topics [scripting-language](/topics/scripting-language "Topic: scripting-language") [forth](/topics/forth "Topic: forth") ### Resources [Readme](#readme-ov-file) ### License [MIT license](#MIT-1-ov-file) ### Uh oh! There was an error while loading. Please reload this page. [Activity](/zevv/zForth/activity) ### Stars [**408** stars](/zevv/zForth/stargazers) ### Watchers [**21** watching](/zevv/zForth/watchers) ### Forks [**57** forks](/zevv/zForth/forks) [Report repository](/contact/report-content?content_url=https%3A%2F%2Fgithub.com%2Fzevv%2FzForth&report=zevv+%28user%29) ## [Releases](/zevv/zForth/releases) No releases published ## [Packages 0](/users/zevv/packages?repo_name=zForth) No packages published ### Uh oh! There was an error while loading. Please reload this page. ## [Contributors 14](/zevv/zForth/graphs/contributors) ### Uh oh! There was an error while loading. Please reload this page. ## Languages * [C 81.1%](/zevv/zForth/search?l=c) * [Forth 15.7%](/zevv/zForth/search?l=forth) * [Makefile 3.2%](/zevv/zForth/search?l=makefile) ## Footer © 2026 GitHub, Inc. ### Footer navigation * [Terms](https://docs.github.com/site-policy/github-terms/github-terms-of-service) * [Privacy](https://docs.github.com/site-policy/privacy-policies/github-privacy-statement) * [Security](https://github.com/security) * [Status](https://www.githubstatus.com/) * [Community](https://github.community/) * [Docs](https://docs.github.com/) * [Contact](https://support.github.com?tags=dotcom-footer) * Manage cookies * Do not share my personal information You can’t perform that action at this time.