simplepy 1.2.1
simplepy: ^1.2.1 copied to clipboard
An interpreter for a subset of the Python language, written purely in Dart. It is intended for adding scripting capabilities to Dart projects and for educational purposes.
simplepy #
An interpreter for a subset of the Python language, written purely in Dart. It is intended for adding scripting capabilities to Dart projects and for educational purposes.
Features #
-
Available python features:
- Variable types:
int,float,bool,str,list,dict,set,tuple,NoneType
(somedictmethods with limitations) - f-strings:
{value:[[fill]align][sign][0][width][.precision][dfs]};#,and typesb/o/x/e/g/%are not yet supported. - arithmetic operators:
+ - * / // ** %and bitwise operators - assignments:
= += -= *= /= **= //= %= - comparisons:
== > >= < <= != - boolean operators:
and,or,not if,else,elif(newline after colon is required, in loops and function definitions as well)forloops,whileloops- functions (default arguments, *args, **kwargs are partially implemented),
lambdafunctions - some built-in functions:
print(),range(),len(),str(),repr(),int(),float(),bool(),type(),list(),dict(),set(),tuple(),abs(),round(),min(),max(),sum() - classes (no class attributes, no multiple inheritance)
Some more features might be added soon, but this will never become a full python interpreter.
- Variable types:
-
Missing python features:
intlimited to dart int: ±1<<63 native ; ±1<<53 in weblist.sort()not yet implementeddict.key(),dict.values(),dict.items()return list copies, not dynamic views as in Pythonstr.startswith(),str.endswith(): 1st argument can only be a single string for comparison, no tuple with alternatives- set operators
| & - ^ <= >= import- list comprehensions
- list or string slices
- file I/O
- exceptions
- decorators
- async functions, generators
input()and some other built-in functions- complex numbers
- anything else not mentioned as available
Usage #
import 'package:simplepy/simplepy.dart';
void main() {
String py = "print(3**4)";
final tokens = Lexer(py).scanTokens();
final stmts = Parser(tokens).parse();
Interpreter().interpret(stmts);
}
Additional information #
Please report any errors (except for missing features, that are not mentioned as available) at the issue tracker.