Metadata-Version: 2.1
Name: fstep
Version: 0.2.0
Summary: python mock up pku-minic/first-step
Home-page: https://github.com/allegrofb/fstep
Author: jiang hongyong
Author-email: hongyong_jiang@hotmail.com
License: MIT
Project-URL: Bug Tracker, https://github.com/allegrofb/fstep/issues
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE

# fstep

This is my learning python project, mock up [pku-minic/first-step](https://github.com/pku-minic/first-step) with python.


## instal

```
$ pip install fstep
```

## example

```first-step
# 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

```ebnf
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};
```



