Skip to content

deepsr2003/cpp-compiler-in-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp-compiler-in-rust

cpp compiler in rust

#basic components of a compiler:

Lexer: Breaks the source code into tokens. Parser: Converts the tokens into an Abstract Syntax Tree (AST). Semantic Analysis: Ensures the AST is semantically correct. Intermediate Representation (IR): Transforms the AST into an intermediate representation for optimization. Optimizer: Improves the IR without changing its meaning. Code Generator: Converts the optimized IR into target machine code. Linker: Combines multiple object files into a single executable.

#Rust project using cargo: cargo new cpp_compiler --bin cd cpp_compiler

#a parser that will use the tokens produced by the lexer to create an Abstract Syntax Tree (AST). // src/parser.rs

#Semantic Analysis This stage checks the correctness of the AST, ensuring that it adheres to C++'s semantic rules. // src/semantic.rs

#Generating Intermediate Representation (IR) Transform the AST into an IR, such as LLVM IR, which is a low-level representation of your code. // src/ir.rs

#Code Generation Finally, write the code generator to produce machine code from the IR. // src/codegen.rs

#Linking Combine the generated machine code with other object files or libraries to produce the final executable. // src/linker.rs

#Main Program Your main program ties everything together. // src/main.rs

#Adding Support for a Simple HTML/JS/CSS Server To make your C++ compiler capable of serving a basic website, you can include a simple HTTP server that delivers static files (like index.html, script.js, and style.css). You can use a library like tiny-http in Rust for this purpose.

About

cpp compiler in rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages