Skip to content
/ PyRust Public
forked from Rahul-RB/PyRust

A lexer parser for Rust written in Python's PLY.

License

Notifications You must be signed in to change notification settings

akhilmd/PyRust

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyRust - A tool to parse Rust and produce Intermediate Code.

Prerequisites:

Testing:

  • Generate AST Nodes definitions in ./src/RustAST.py:
    $ ./src/_build_tables.py
  • Run tests:
    • All tests:
      $ ./tools/test-all.sh
    • Lexer Unit Tests:
      $ ./tests/TestLexerAuto.py
    • Lexer Manual Tests:
      $ ./tests/TestLexerManual.py
    • Symbol Table Test:
      $ ./tests/TestSymbolTable.py ./tests/testFile2.rs 2
    • Abstract Syntax Tree Test:
      $ ./tests/TestAST.py ./tests/testFile1.rs
    • Intermediate Code Generation Test:
      $ ./tests/TestICGen.py ./tests/testFile1.rs
  • Clean project directory:
    $ ./tools/clean.sh

TODO:

Lexical Analysis

  • Remove Comments.
  • Generate tokens.
  • Preload keywords into the symbol table.
  • Make an entry for the identifiers into the symbol table(if there exists an identifier with the same name in different scopes then construct symbol table per scope).
  • Symbol table must contain entries for predefined routines like printf, scanf etc

Syntax Analysis

  • Write CFG for the entire program.
  • If implementing parser by hand:
    • Prefer RDP with backtracking.
    • Perform translation at required places in the code for each non-terminal.
  • If implementing using tool:
    • Provide appropriate semantic rules.

Semantic Analysis

  • Take care of the primitive types and array types.
  • Take care of coersions.
  • Take care of Arithemetic expressions.
  • Concetrate on the looping construct choosen.
  • Update type and storage information into the symbol table.
  • Show Abstract Syntax tree(AST).

Intermediate Code Generation

  • Three address code generation

Optimizing Intermediate Code

  • Constant folding
  • Constant Propogation
  • Common subexpression elimination (optional)
  • Dead code elimination
  • Reducing temporaries (optional)
  • Loop optimizations

About

A lexer parser for Rust written in Python's PLY.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.3%
  • Rust 1.9%
  • Shell 1.8%