Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vivekkdagar/xbasic

A Python-based, extended interpretation of the BASIC language, enriched with additional features and functionalities.
https://github.com/vivekkdagar/xbasic

basic-programming cli cli-app click compiler interpreter language lexer lexical-analysis parser project pypi python

Last synced: 1 day ago
JSON representation

A Python-based, extended interpretation of the BASIC language, enriched with additional features and functionalities.

Awesome Lists containing this project

README

        

logo

xbasic


A Python-based, extended interpretation of the BASIC language, enriched with additional features and functionalities.

ยท Documentation ยท Syntax Guide ยท Example program



## ๐Ÿช„ Project Feature Breakdown

**Parsing and Tokenization:**
- Utilizes a custom lexical analyzer or tokenizer (`Token`, `TokenList`) to break down source code into tokens (keywords, identifiers, operators, literals).
- Implements parsing logic using recursive descent parsing.
- Recognizes the structure of the input code based on defined grammar rules.

**Abstract Syntax Tree (AST):**
- Defines classes (`Value`, `String`, `NumberNode`, `BinOpNode`, etc.) to represent nodes in the abstract syntax tree (AST).
- Constructs the AST by recursively building nodes during parsing.

**Error Handling:**
- Provides a `ParseResult` class to manage parsing results and errors.
- Defines error classes like `InvalidSyntaxError` and `RTError` for reporting syntax and runtime errors.

**Execution Logic:**
- Implements an interpreter component responsible for executing parsed AST nodes.
- Traverses the AST and performs operations defined by language semantics.

**Language Features:**
- Supports variables with data types such as numbers, strings, and lists.
- Provides constructs for control flow (`if`, `for`, `while` loops) and flow control statements (`return`, `continue`, `break`).
- Allows defining and calling functions (`func-def`, `call`).

**Utilities:**
- Tracks position (line and column numbers) of tokens and nodes in the source code using utilities like `Position`.
- Handles contextual information during parsing and execution using the `Context` class.


# :notebook_with_decorative_cover: Table of Contents

- [Project Feature Breakdown](#-project-feature-breakdown)
- [Screenshots](#camera-screenshots)
- [Installation & Usage Guide](#toolbox-installation-from-pypi-or-build-from-source)
- [Contributing](#wave-contributing)
- [FAQ](#grey_question-faq)


## :star2: About the Project


### :camera: Screenshots


#### Executing a file within the shell

image


#### Using the interactive shell

image


#### Opening the github page

image


## :toolbox: Installation (from PyPI or Build from Source)

Install from PyPI

You can install the `xbasic` package directly from PyPI using the following command:

```bash
pip install xbasic
```


### Build from Source

Clone the repository

```bash
git clone https://github.com/vivekkdagar/xbasic
```

Go to the project directory
```bash
cd xbasic
```

Build the package:

```bash
python3 -m build
```

Install the package:

```bash
pip install dist/*gz
```


## :book: Usage Guide

Below is a guide on how to interact with xbasic:

1. **Open github page**
```bash
xbasic report
```

2. **Start an interactive shell**

```bash
xbasic shell
```

3. **Execute a file within the shell**

```bash
xbasic file -f path
```

- `-f`: Specify the path where the bsx file is.


## :wave: Contributing

Contributions are always welcome!

see [`contributing.md`](CONTRIBUTING.md) for ways to get started


## :grey_question: FAQ

**1. What is XBasic?**
- XBasic is a project aimed at developing an interpreter for a programming language called XBasic. It involves the creation of a parser, lexer, and executor for XBasic code, allowing users to write and execute XBasic programs.

**2. What features does XBasic offer?**
- XBasic aims to provide a range of features common to programming languages, including variable assignment, arithmetic operations, control flow statements (such as if-else, loops), function definitions, and function calls. It also supports data types like numbers, strings, and lists.

**3. How is XBasic implemented?**
- XBasic is implemented in Python. The project includes custom logic for lexical analysis (tokenization), parsing, and execution of XBasic code. It utilizes object-oriented programming principles to represent language constructs and manage program execution.

**5. How are errors handled in XBasic?**
- XBasic includes error handling mechanisms to report syntax errors during parsing and runtime errors during program execution. Custom error classes are used to provide informative messages, including error location and context, helping users debug their code effectively.

**6. How can I get started with XBasic?**
- To get started with XBasic, you can clone the project repository from GitHub and follow the setup instructions. Once set up, you can explore the codebase, contribute to development, or use the interpreter to write and execute XBasic programs. Additionally, documentation and examples are provided to guide users through usage and development processes.

**7. What file format does XBasic use?**
- XBasic uses the ".bsx" file format for XBasic source code files. Users can write XBasic code in files with the ".bsx" extension, and the XBasic interpreter can parse and execute these files. This file format helps organize and store XBasic programs efficiently.


## :warning: License

Distributed under the MIT License. See LICENSE for more information.