python mock up pku-minic/first-step
Project description
fstep
This is my learning python project, mock up pku-minic/first-step with python.
instal
$ pip install fstep
example
# calculate the nth term of the Fibonacci sequence
fib(n) {
if n <= 2 {
return 1
}
else {
return fib(n - 1) + fib(n - 2)
}
}
main() {
print(fib(input()))
return 0
}
You can evaluate this program using the interpreter by running:
$ fstep -s examples/fib.fstep -i
20
6765
0
Or compile it to RISC-V assembly:
$ fstep -s examples/fib.fstep -a
EBNF of first-step
Program ::= {FunctionDef};
FunctionDef ::= IDENT "(" [ArgsDef] ")" Block;
ArgsDef ::= IDENT {"," IDENT};
Block ::= "{" {Statement} "}";
Statement ::= IDENT ":=" Expression
| IDENT "=" Expression
| FunctionCall
| IfElse
| "return" Expression;
IfElse ::= "if" Expression Block ["else" (IfElse | Block)];
Expression ::= LOrExpr;
LOrExpr ::= LAndExpr {"||" LAndExpr};
LAndExpr ::= EqExpr {"&&" EqExpr};
EqExpr ::= RelExpr {("==" | "!=") RelExpr};
RelExpr ::= AddExpr {("<" | "<=") AddExpr};
AddExpr ::= MulExpr {("+" | "-") MulExpr};
MulExpr ::= UnaryExpr {("*" | "/" | "%") UnaryExpr};
UnaryExpr ::= ["-" | "!"] Value;
Value ::= INTEGER
| IDENT
| FunctionCall
| "(" Expression ")";
FunctionCall ::= IDENT "(" [Args] ")";
Args ::= Expression {"," Expression};
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
fstep-0.2.0.tar.gz
(12.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
fstep-0.2.0-py3-none-any.whl
(14.5 kB
view details)
File details
Details for the file fstep-0.2.0.tar.gz.
File metadata
- Download URL: fstep-0.2.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1aedf257ed09ca142eaeaf80350107e84c7ac35ee8984936bf72ee4b96962a0b
|
|
| MD5 |
1072f1ec1a5b3325b2150db214874f0f
|
|
| BLAKE2b-256 |
8d77a2374e9b9d14f59545bcbbaba29b0034fcff324b73ac996ffe7f22205080
|
File details
Details for the file fstep-0.2.0-py3-none-any.whl.
File metadata
- Download URL: fstep-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
476aefc808d5e84cbf6b609dc4a688af72ec8f4f4bd762e59beff7a339432ab4
|
|
| MD5 |
3839a5812bf96d95d96d43f109317a06
|
|
| BLAKE2b-256 |
36c1375abe5ab6317999f3b8f39884b8e861ff09885fac568373b208b4c051f5
|