Coder Social home page Coder Social logo

rust-compiler's Introduction

an attempt at making a compiler in rust!

Future "Valid Syntax", negative whitespace significant indentation!

          hhh {
        eee {
      aaa {
   ddd {
aaa }
  ccc } 
    hhh }
      eee }

Core Functionality Required:

  • variables WITH DATA TYPES
  • operations: (boolean, logical//bitwise, binary)
  • control flow branches: (if/else)
  • loops: (while/for)
  • types
  • functions: (recursion << should be free?)
  • array
  • user defined struct

Currently working on:

  • if

    • rework lexer to handle multi-symbol keywords (i.e "==" or "<=")
    • parse boolean comparison
    • else & else if parsing
    • code generation
      • invert 'jump' conditions
      • unsigned vs signed comparison (diff jump instructions) (no types, all signed)
      • binary expr conditions
        • conditional expr, either has explicity bool comparison or implicit, expr = lhs: (lhs > 0)
        • cmp reg1, reg2 ; compare arguments
        • set(EQUIVALENCE e.g e, le) al; sets register 'al' (8 bit) to 1,0 depending on cmp flag
        • movzx output_reg, al ; Move Zero Xtend. copies 'al' into 'output_reg' && zero init reg1 bits.
    • types of scope
      • inherits variables from parent scope (if, else if, else)
      • doesn't (new function, UNLESS class, inherits 'self')
  • (kinda done) split 'TokenKind': 'Symbol' .. 'LogicalOp' .. 'BinaryOp' .. etc

  • comments

  • re-design multi-symbol in Lexer: match against longest multi-symbol to shortest, until finds match (or illegal token.)

  • update grammar to match code.

  • variable reassignment (mutability)

  • Operators

    • modulus '%' op
    • Associativity
    • binary
    • logical
      • i.e: if (5) | 5 != 0 so -> if (true)
      • i.e: if (!5) | 5 == 0 so -> if (false)
      • eval expr, jump if zero. << un-optimal, uses 'al' reg when not necessary
    • bitwise
    • unary
      • LogicalNot
      • BitwiseNot
  • dynamically place variables on stack if they are(nt) used immediately.

    • on expr generation.
  • Testing infrastructure.

  • data types

    • bools: al register (8 bit)
    • u8: al
    • u16: ax
    • u32: eax
    • u64: rax
  • functions

    • return type
    • arguments
    • body
    • program entry point ("main")
  • Implement C equivalent operators:

    • comma: ','
    • assignment: '=' | '+=' | '/=' | ..
    • modulus: %
    • logical not: !
    • unary minus: i.e -10
    • function call: '()'
    • array subscript: '[]'
    • struct member: '.' | '->'
    • Increment/Decrement (OPTIONAL)
    • cast: (type)
  • (Joke mode:) negative whitespace significance, the most nested piece of code has 0 indentations, everything out has an indentation.

    • compiler error on uppercase

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.