Git Product home page Git Product logo

emoscript's Introduction

emoscript

The emoscript is a simple stack-based programming language designed for fun and education. It aims to provide an engaging and visually appealing way to learn the basics of programming, especially for those who might be intimidated by traditional programming languages. The project uses emojis to represent various programming constructs and operations, making it more accessible and enjoyable.

Reason

The emoscript was created to explore the potential of using emojis in programming languages and to make learning to code more engaging and fun. The idea was to experiment with a different approach to writing and reading code, making it more visually appealing and interactive.

Future of emoscript

While it's unlikely that the emoscript will replace traditional programming languages, it serves as a unique and enjoyable way to learn programming concepts. It can be used as a stepping stone for beginners or as a way to experiment with language design. The project can be extended with new emojis and additional features, allowing for continued growth and improvement.

Technical Overview

The emoscript is implemented in Rust and uses a stack-based execution model. It consists of the following components:

  • Interpreter: The main structure containing the execution environment, including variables and the evaluation stack.

  • Token: An enum representing the different types of tokens, such as numbers, operations, and variables.

  • tokenize: A function to convert the input code into a list of tokens.

  • perform_operation: A function to perform arithmetic operations based on the provided operator and operands.

  • run: A function to execute the provided code.

How to use

  1. Clone the repository.

  2. Install Rust, if not already installed.

  3. Modify the input variable in the main function to represent the desired expression using emojis. For example, "2๏ธโƒฃ๐Ÿ—จ.๐Ÿ—จ0๏ธโƒฃ๐Ÿ—จ๐Ÿค”2๏ธโƒฃ"; represents "2.0 / 2".

  4. Run the code with cargo run.

Emoji Mapping

Emoji Operation Example
๐Ÿ™‚ + (Addition) 12๐Ÿ™‚34 (12 + 34)
๐Ÿ˜ข - (Subtraction) 12๐Ÿ˜ข34 (12 - 34)
๐Ÿ˜‚ * (Multiplication) 12๐Ÿ˜‚34 (12 * 34)
๐Ÿค” / (Division) 12๐Ÿค”34 (12 / 34)
๐Ÿ˜•๐Ÿ˜„๐Ÿ˜ž if-then-else ๐Ÿ˜•๐Ÿ˜„๐Ÿ™‚1๏ธโƒฃ๐Ÿ˜ž๐Ÿ™‚2๏ธโƒฃ (if then +1 else +2)
๐Ÿ”๐Ÿ”š loop 9๏ธโƒฃ๐Ÿ”๐Ÿ”š (๐Ÿ” - begin loop, ๐Ÿ”š - end loop)
[num1๐Ÿ”num2]๐Ÿ”š range-loop [0๐Ÿ”8]๐Ÿ”š
๐Ÿfunc_name expr๐Ÿšฉ function ๐Ÿf2๏ธโƒฃ๐Ÿ˜‚2๏ธโƒฃ๐Ÿšฉ
๐Ÿ“žfunc_name call function ๐Ÿ“žf

Example

fn main() {
    let input = "2๏ธโƒฃ๐Ÿ—จ.๐Ÿ—จ0๏ธโƒฃ๐Ÿ—จ๐Ÿค”2๏ธโƒฃ";
    let mut peekable_chars = PeekableChars::new(input);
    let tokens = peekable_chars.tokenize();

    let mut interpreter = EmojiInterpreter::new(tokens);
    let result = interpreter.evaluate();
    println!("Result: {}", result);
    // if then else
    let input = "2๏ธโƒฃ๐Ÿ—จ.๐Ÿ—จ5๏ธโƒฃ๐Ÿ—จ๐Ÿค”๐Ÿ˜„๐Ÿ™‚1๏ธโƒฃ๐Ÿ˜ž๐Ÿ™‚2๏ธโƒฃ"
}

How to run

Playground is here -> https://emoscript.onrender.com/

Designing an Emoji-based Programming Language: A Step-by-Step Guide with Rust

In this tutorial, we'll walk you through the process of designing and implementing an emoji-based programming language using Rust. By the end, you'll have a better understanding of language design principles and will be equipped with the knowledge needed to create your own unique programming language.

Step 1: Define the language structure and syntax

Choose the basic structure and syntax of your language. For this example, we'll use emojis to represent different language constructs like numbers, operations, and control flow. Here's an overview of the syntax:

  • Numbers: Use emojis like '2๏ธโƒฃ' and '๐Ÿ—จ' to represent digits and decimal points.

  • Operations: Use emojis like '๐Ÿ™‚', '๐Ÿ˜ข', '๐Ÿ˜‚', and '๐Ÿค”' to represent basic arithmetic operations (addition, subtraction, multiplication, and division).

  • Control Flow: Use emojis like '๐Ÿ˜•', '๐Ÿ˜„', '๐Ÿ˜ž', and '๐Ÿ˜ข' to represent control flow constructs like if, then, else, and endif.

  • Variables: Use the '๐Ÿ”ค' emoji followed by a number to represent a variable assignment.

Step 2: Create the tokenizer

Write a tokenizer (lexer) to transform the input code into a stream of tokens. The tokenizer should recognize the various emojis representing numbers, operations, and control flow constructs and emit corresponding tokens for each.

Create a PeekableChars struct that will be used to iterate through the input string and peek at the next character. Implement the Tokenize trait for PeekableChars with a tokenize() method that processes the input string and generates a vector of EmojiToken enums.

Step 3: Implement the interpreter

Create an EmojiInterpreter struct to process the stream of tokens generated by the tokenizer. The struct should have a new() method to initialize the interpreter with the tokens, as well as an evaluate() method to process the tokens and perform the specified operations.

Inside the evaluate() method, use a loop to iterate through the tokens and process them according to their type. The processing should include arithmetic operations, control flow constructs, and variable assignment. Handle any errors during execution gracefully.

Step 4: Test your language

Test your language using various code snippets to ensure it works correctly. Include edge cases and error conditions to verify the robustness of your implementation. For example:

let input = "2๏ธโƒฃ๐Ÿ—จ.๐Ÿ—จ0๏ธโƒฃ๐Ÿ—จ๐Ÿค”2๏ธโƒฃ";
let mut peekable_chars = PeekableChars::new(input);
let tokens = peekable_chars.tokenize();

let mut interpreter = EmojiInterpreter::new(tokens);
let result = interpreter.evaluate();
println!("Result: {}", result);

let input2 = "2๏ธโƒฃ๐Ÿ—จ.๐Ÿ—จ5๏ธโƒฃ๐Ÿ—จ๐Ÿ˜•๐Ÿ˜„๐Ÿ™‚1๏ธโƒฃ๐Ÿ˜ž๐Ÿ™‚2๏ธโƒฃ";
let mut peekable_chars2 = PeekableChars::new(input2);
let tokens2 = peekable_chars2.tokenize();

let mut interpreter2 = EmojiInterpreter::new(tokens2);
let result2 = interpreter2.evaluate();
println!("Result: {}", result2);

let input3 = "๐Ÿ”ค2๏ธโƒฃ๐Ÿ™‚2๏ธโƒฃ";
let mut peekable_chars3 = PeekableChars::new(input3);
let tokens3 = peekable_chars3.tokenize();

let mut interpreter3 = EmojiInterpreter::new(tokens3);
let result3 = interpreter3.evaluate();
println!("Result: {}", result3);

Step 5: Optimize and expand your language

Once you have verified that your language implementation works correctly, consider ways to optimize the performance, improve error handling, and expand the language with additional features. Some suggestions include:

  • Implement more advanced error handling and reporting to provide helpful feedback when users encounter issues with their code.

  • Add support for more advanced data structures, such as lists, maps, and objects.

  • Implement functions or procedures to allow users to create reusable pieces of code.

  • Add support for loops and other advanced control flow constructs.

  • Integrate external libraries to provide additional functionality.

Step 6: Document your language

Write clear and comprehensive documentation for your language, detailing its syntax, features, and usage. Include examples and tutorials to help users get started and to demonstrate the various features of your language. Make sure to cover any error messages or warnings that users might encounter, as well as any best practices for writing efficient and maintainable code in your language.

Step 7: Share your language with the community

Once you're satisfied with your language implementation and documentation, share your work with the community. This could include publishing the source code on a platform like GitHub, creating a website with documentation and examples, and promoting your language on social media, forums, or blog posts. Engage with users, gather feedback, and continually refine and expand your language based on their suggestions and needs.

Conclusion

Designing and implementing your own programming language can be a rewarding and educational experience. By following this step-by-step guide, you'll gain valuable insight into language design principles and learn how to create a unique and functional programming language using Rust. As you continue to refine and expand your language, you'll have the opportunity to contribute to the broader programming community and create a useful tool for others to use and enjoy.

Architecture perspective (designing)

soon

Technical solution

soon

emoscript's People

Contributors

ladroid avatar

Stargazers

Misha Kushka avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.