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>
<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.1.tar.gz
(6.1 kB
view hashes)
Built Distribution
Close
Hashes for whilelang-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d8b63a7f062e97faf42769f4c686d90a58e932ec9272a98c89bd147de2342be |
|
MD5 | 48f6d8e12f642dafe1b3f50b93dddb15 |
|
BLAKE2b-256 | 8048b6297e89e423dbeb6d0042ff930242166bc2ca05940045b5dad0ea636a8f |