A minimal implementation of the While language
Project description
Whilelang
Usage: python while.py source.while [...arguments]
Implemented grammar
The grammar implemented here is slightly different to the definitions of While that can be found online, largely for ease of implementation.
<suite> = EOF
| "(" <suite> ")"
| <statement> *(";" <statement>)
<statement> = "skip"
| "while" <expr_a> "do" <suite>
| "if" <expr_a> "then" <suite> ["else" <suite>]
| NAME ":=" <expr_a>
| <directive>
<directive> = "@" ("trace" | "exit" | "print" NAME)
<factor> = [("!" | "¬")] (NAME | NUMBER | BOOLEAN | "(" <expr_a> ")")
<expr_f> = <factor> [("*" | "/") <factor>]
<expr_e> = <expr_f> [("+" | "-") <expr_f>]
<expr_d> = <expr_e> [("<=" | "<" | ">=" | ">") <expr_e>]
<expr_c> = <expr_d> ["=" <expr_d>]
<expr_b> = <expr_c> ["&" <expr_c>]
<expr_a> = <expr_b> ["|" <expr_b>]
This logic can be seen implemented as code in parser.py
. Compared to the
simpler grammars often quoted, this grammar provides proper operator
precedence.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
whilelang-0.0.2.tar.gz
(8.1 kB
view hashes)
Built Distribution
Close
Hashes for whilelang-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2893dcdfa530728fd8225a37170a05785e8d4223da85e7eb35bd3df9d1dc26ff |
|
MD5 | a680f6b43bedbbd2201fecf50e5da448 |
|
BLAKE2b-256 | c7e18623d43d6071173d36ceca12b40f94681ce13c28cddb3a5788825ba7cee7 |