Git Product home page Git Product logo

one-draft-in-c's Introduction

one-draft-in-c

A attempt to rewrite one language compiler in pure c without lexer and parser generators.

Examples

pow(int a, int b) {
    _ 456
}
main ()  {
    _ "Hello, World"
}

Output:

Define function pow
    ARG:variable a with a type
    ARG:variable b with b type
  PRINT
    VALUE:16,number
Define function main
  PRINT
    VALUE:14,string double

multiPrint() {
    _ 'g'
    _  1, 5 , 150, +50, -45, "hi"
}

Output:

Define function multiPrint
  PRINT
    VALUE:15,string single
  PRINT
    VALUE:16,number
    VALUE:16,number
    VALUE:16,number
    VALUE:16,number
    VALUE:16,number
    VALUE:14,string double

multiPrint() {
    _ 'g';_  1, 5 , 150, +50, -45, "hi"
}

Output:

Define function multiPrint
  PRINT
    VALUE:15,string single
  PRINT
    VALUE:16,number
    VALUE:16,number
    VALUE:16,number
    VALUE:16,number
    VALUE:16,number
    VALUE:14,string double

int _underline_allowed_in_variable_ident=4;
main() {
    _ 1;
}

Output:

Define global variable _underline_allowed_in_variable_ident
    VALUE:16,number
Define function main
  PRINT
    VALUE:16,number

main() {
    if 1 {
        _ 1;
    }
}

pow(int a,int b) {
    _ "."
}
main ()  {
    _ "Hello, World"
}

Analyze Log:

------- ident 'pow'
Define function pow
-->ARG:variable a with a type
-->ARG:variable b with b type
==>STATEMENT:0,print
==>STATEMENT:14,string double
------- ident 'main'
Define function main
==>STATEMENT:0,print
==>STATEMENT:14,string double

Output ($ gcc main.c -o one && ./one input.txt):

Define function pow
    ARG:variable a with a type
    ARG:variable b with b type
  PRINT
    VALUE:14,string double
Define function main
  PRINT
    VALUE:14,string double

Output:

Define function main
  IF
    VALUE:16,number
  PRINT
    VALUE:16,number

© Copyright Max Base 2018-2020

one-draft-in-c's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.