Giter VIP home page Giter VIP logo

programminglanguage's Introduction

Programming Language

This is an implementation of my own programming language. Notice, that AST tree is built according to our own standart.

Overview

In this project I will translate instructions, written on my custom language to binary file. It can be executed with my own CPU implementation. In my Binary translator project this binary file is translated into .elf file.

How it works

Writing program with custom language

Heres an example of program, written on Meow meow script:

комната_единички >маин ( )
    нюх_нюх >бобер 1     мяу
    нюх_нюх >текущ 1     мяу
    нюх_нюх >топчик 0    мяу
    слизнуть ( >топчик ) мяу

    нюх_нюх >бобер кис_кис >фак ( >бобер >текущ >топчик ) мяу
    буэээ ( >бобер ) мяу
    лее_куда_прешь ( )  мяу
валим

комната_единички >фак ( >верх >сус >рез )
    
    нюх_нюх >сус >сус сожрать 1 мяу
    нюх_нюх >рез >рез мяя >сус мяу
    нюх_нюх >бобер 123 мяу

    куда_епта >сус пахнет_знакомо >верх
        лее_куда_прешь ( >рез ) мяу
    валим
    ай_ладно
        нюх_нюх >рез кис_кис >фак ( >рез >сус >верх ) мяу
    валим
    лее_куда_прешь ( >рез ) мяу

валим

Program finds factorial of number, given by user.

Frontend - parsing

Using recursive descent input file is parsed into AST tree. The result of parsing you can see on this image: image

Frontend - Writing AST tree on disk

After parsing code to AST tree, program is not translating it into assembly code. It writes it into .txt file instead, to save the tree image in easy-to-access format.

This is done mostly in educational purposes. With the help of language standart we are capable of generating executable files from different programming languages if they support such language standart.

Here is some of my colleagues, whose programming language I can handle: MrGukas , AleksPlast, Tyazhelkov Victor , and 4+ more.

Example of AST tree image in .txt file:

{  ST  {  FUNC  { "main" { NIL } { VOID }  }  {  ST  {  VAR  { "zho" }  { 3802 }  }  {  ST  {  VAR  { "pk" }  { 2083 }  }  {  ST  {  VAR  { "a" }  { 1 }  }  {  ST  {  VAR  { "b" }  { 2 }  }  { ...

Backend - Translating AST tree into assembly

I build AST tree from tree.txt file, according to language standart. After that, tree is being translated into Sequence of Assembly commands.

Note: in this project I implemented my own assembly and CPU work.

Example of generated assembly code:

call main 
hlt

; let the chaos begin

; function 
main:
in

push [rax+2]
push [rax+1]

...

out
ret
end

Executing the code

After we get assembly file, we can execute it with CPU work implementation wich is integrated in this project.

You can see more detailed explanation of this process here.

Conclusion

This project gave me a ton of knowledge about parsing algorithms and structures. Also I got a unique experience in developing my own language standart with my colleagues. In the end of the 1st year of education in MIPT this project become 100% real programming language, because it is now capable of generating .elf file. See its improved version here.

programminglanguage's People

Contributors

dodokek avatar

Stargazers

 avatar

Watchers

 avatar

programminglanguage's Issues

Unnecessary copying of an array

Are you sure you want to copy the entire "token_array" every time you call functions from "parser_frontend.h"? Would it better to pass it to these functions as Token*?

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.