• The Result Type

    The Result type is one of the main ways of handling errors in Rust. In Rust, the result of a function execution is usually encapsulated in the Result enumeration, which…

  • Rust Data Types: Unveiling the Mystique

    In the realm of Rust, data types are the magical elements that breathe life into your code. They define the nature of the data that can be stored and manipulated,…

  • Multithreading in Rust

    Imagine you’re organizing an expedition. You have a group of brave explorers ready and waiting for your command. In the world of Rust, these explorers are like threads, and you…

  • vitural machine design

    Virtual machine (VM) executes bytecode instructions. The VM is designed to work with a turtle graphics system, where a “turtle” moves around the screen drawing lines. Here’s a detailed breakdown…

  • Parase design

    This Rust code defines a ParseProto struct and its associated methods for parsing a language into bytecode. The ParseProto struct has four fields: The load function takes a File object as input, creates a new ParseProto object, and calls the chunk method…

  • lexer design

    Straight to the code. First of all, a general statement: the main function of this lexer is to classify the messy input file into several different categories, such as Name,…

  • LOGO Interpreter, High Dimensional Thought

    Programming: more precisely, this project is a LOGO language interpreter written in RUST language instead of a compiler. So the name of the blog will be changed to LOGO Interpreter…

  • RUST项目实战——LOGO编译(DAY1)

    程序设计:更准确地说,本项目是一个使用RUST语言编写的LOGO语言解释器而非编译器。所以以后的博客名称会更名为LOGO解释器。(大爷我可是相当严谨的) 设计参考:《使用Rust实现LUA解释器》 设计参考网址:https://wubingzheng.github.io/build-lua-in-rust/zh/PREFACE.html 参考作者github页面:https://github.com/WuBingzheng 解释器的主要任务是将源LOGO代码转换为可执行的Rust代码,原LOGO代码主要有以下部分组成: 先介绍两个基本概念:“字节码(bytecode)”与“值(value)” 字节码: 值: 直接开始项目,将项目分为几个大的部分: 程序入口已在start code中给出,具体代码和解释如下: 这里将源文件路径,生成图片的路径,图片的宽与高读取在一个struct中,后面两大段主要作用于生成图片的保存,并在保存不成功时抛出错误。这里能看到,该代码并没有包含文件的读取,需要我自己写(草泥马)。 先以一个非常简单的LOGO程序开始,然后再加上烦人的细节,LOGO代码如下: 可以构建一个stack结构来保存每一个token(命令、数值、变量名均为token),stack结构可以用下图表示: 我想到了一个简单的方法表示token:将整行语句读取为字符串,然后按照空格划分存入stack之中,在该简单示例中语法比较简单,可以根据读取的token数量将命令划分为不同的种类: 事实上我也是这么做的。为了说明进一步的设计,这里要再对字节码做一个分析。上文已经给出了字节码的定义,即一个转化源码与机器码的中介,虽说这里可以直接使用RUST作为字节码,可我才疏学浅还没能想到怎么直接转化,不妨自己重新定义一个字节码。以原LOGO文件中这一句为例: 要执行这一句,我们需要做如下的事情在上面的图示中表达的很清楚,其涉及三个不同的字节码: 代码的执行逻辑就是: 其中,语法树的定义如下: 虚拟机需要做的就是,构建一个HashMap,将经过整理的语法树所传入的命令函数(command)与Rust代码中执行相同任务的命令函数对应起来。可以构建如下结构来清晰表明结果: 然后遍历传入的语法树中所有的字节码,根据字节码采取不同的动作。这就是大体的思路,马上开始具体实现。

  • Rust项目实战——LOGO编译器(DAY0)

    目标:使用rust语言编写一个读取logo语言的编译器,编译器需要能识别原logo语言的语法错误,并使用rust语言unsvg crate来实现按相关作图要求。 unsvg crate对应文档链接如下:https://docs.rs/unsvg/latest/unsvg/ 编译器需要识别的Logo语言基本命令如下: 1.Logo语言特色赋值语法:MALKE 命令 ADDASSIGN 相当于其它语言中的 ‘+=’, 程序要有识别该命令的能力。 2.Logo语言查询语句: 3.LOGO语言条件判断与循环: 4.LOGO语言中的函数定义,LOGO函数定义语法如下: 其中: 5.LOGO语言中的数学表达式:

  • First day in Rust language

    TL;ND : This blog includes the usage of these features:  Details: Well, practice is the best learning. Start my task in a simple coding task (in fact, it is one…

Hey!

I’m Bedrock. Discover the ultimate Minetest resource – your go-to guide for expert tutorials, stunning mods, and exclusive stories. Elevate your game with insider knowledge and tips from seasoned Minetest enthusiasts.

Join the club

Stay updated with our latest tips and other news by joining our newsletter.

Categories

Tags

Rust