Skip to content

Latest commit

History

History
102 lines (77 loc) · 4.87 KB

File metadata and controls

102 lines (77 loc) · 4.87 KB

PyMini Language Design

1. Introduction

PyMini is a lightweight, interpreted programming language designed for simplicity and readability. It features a clean syntax and provides a robust foundation for building logic-heavy applications and algorithmic prototypes.

2. Core Features

PyMini supports the following fundamental programming features:

  • Variable Assignment: Declare and assign values to variables.
  • Basic Arithmetic Operations: Perform addition, subtraction, multiplication, division, and modulo (%).
  • Print Statement: Output values to the console.
  • Function Definitions: Define reusable blocks of code with parameters and return values.
  • Function Calls: Execute defined functions.
  • Conditional Statements: Control program flow based on conditions (if-else) with support for logical operators (and, or, !).
  • Looping Constructs: Repeat blocks of code (while loops).
  • Data Types: Support for Integers, Strings, Booleans, Lists, Bytes, and Dictionaries.
  • Web3 Integration: Native Solana support via Rust-based evaluator core.

3. Syntax Specification (BNF-like)

Below is a simplified Backus-Naur Form (BNF)-like specification for PyMini's syntax. Tokens are represented in uppercase, and keywords are enclosed in double quotes.

program ::= statement*
statement ::= assignment_statement
| print_statement
| function_definition
| if_statement
| while_statement
| for_statement
| return_statement
| expression_statement
assignment_statement ::= "let" IDENTIFIER "=" expression ";"
print_statement ::= "print" "(" expression ")" ";"
function_definition ::= "func" IDENTIFIER "(" (IDENTIFIER ("," IDENTIFIER)*)? ")" "{" statement* "}"
return_statement ::= "return" expression ";"
if_statement ::= "if" "(" expression ")" "{" statement* "}" ("else" "{" statement* "}")?
while_statement ::= "while" "(" expression ")" "{" statement* "}"
for_statement ::= c_for_statement | for_in_statement
c_for_statement ::= "for" "(" (assignment_statement | expression_statement | ";") expression? ";" expression? ")" statement
for_in_statement ::= "for" IDENTIFIER "in" expression statement
expression_statement ::= expression ";"
expression ::= equality
equality ::= comparison (("==" | "!=") comparison)*
comparison ::= term ((">" | ">=" | "<" | "<=") term)*
term ::= factor (("+" | "-") factor)*
factor ::= unary (("*" | "/") unary)*
unary ::= ("!" | "-") unary | primary
primary ::= NUMBER | STRING | "true" | "false" | "nil" | "(" expression ")" | IDENTIFIER | function_call | list | dict
list ::= "[" (expression ("," expression)*)? "]"
dict ::= "{" (STRING ":" expression ("," STRING ":" expression)*)? "}"
function_call ::= IDENTIFIER "(" (expression ("," expression)*)? ")"

4. Web3 & Rust Core Integration

PyMini leverages a Rust-based core (pymini_core) via PyO3 to handle performance-critical and Web3-specific tasks:

  • Solana RPC: Direct interaction with the Solana blockchain for balance and account data.
  • Borsh Deserialization: Efficient binary data handling for Solana accounts.
  • Performance: Evaluator offloads heavy computations to native Rust code.

5. Semantics

  • Variable Scope: PyMini supports lexical scoping, meaning variables are resolved based on where they are defined, allowing for proper function-level and block-level variable management, including closures.
  • Type System: PyMini will be dynamically typed. Type checking will occur at runtime.
  • Error Handling: Runtime errors (e.g., type mismatches, undefined variables) will result in clear error messages.

5. Lexical Tokens

PyMini will recognize the following token types:

  • Keywords:let, func, if, else, while, return, print, true, false, nil
  • Identifiers: Sequences of letters, digits, and underscores, starting with a letter or underscore.
  • Literals:
    • NUMBER: Integer literals (e.g., 123, 0).
    • STRING: String literals enclosed in double quotes (e.g., "hello").
  • Operators:+, -, *, /, =, ==, !=, >, >=, <, <=, !
  • Delimiters:(, ), {, }, ;, ,
  • Whitespace: Ignored during lexical analysis.
  • Comments: Single-line comments starting with // will be ignored.

6. Future Enhancements (Out of Scope for Initial Version)

  • Local variable scoping
  • Classes and objects
  • Modules and imports
  • More complex data structures (lists, dictionaries)
  • Standard library functions
  • Error recovery during parsing
  • Optimizations
  • Lists and Dictionaries
  • Standard Library Expansion