Giter Site home page Giter Site logo

cc's Introduction

C Compiler In TypeScript

dependencies

Node.js v20+

build

npm i && npm run build

test

npm test

features

  • tokenizer src/tokenizer/clang.mts
  • parser src/parser/clang.mts
  • semantic analysis (doing...)
  • asm generation
  • virtual machine src/vm/lc3.mts (doing...)
  • runtime (I/O API)
import { ClangParser } from "./src/parser/index.mjs";
import type { Program } from "./src/parser/index.mjs";
import util from "util";

const parser = ClangParser.fromCode(`
int main(char* args) {
  return 0;
}`);

const ast: Program = parser.parse();

console.log(util.inspect(ast, { depth: null, colors: true }));

run demo

npx ts-node src/index.mts src/demo/hello.c

# {
#   type: 'program',
#   parent: undefined,
#   definitions: [
#     <ref *1> {
#       type: 'function-definition',
#       name: 'main',
#       parameters: [ [Object] ],
#       body: {
#         type: 'function-body',
#         statements: [Array],
#         symbolTable: [ScopedMap [Map]]
#       },
#       returnType: 'int',
#       declaration: {
#         type: 'function-declaration',
#         name: 'main',
#         parameters: [Array],
#         returnType: 'int',
#         definition: [Circular *1]
#       },
#       parent: [Circular *2]
#     }
#   ],
#   symbolTable: ScopedMap(1) [Map] {
#     'main' => <ref *1> {
#       type: 'function-definition',
#       name: 'main',
#       parameters: [ [Object] ],
#       body: {
#         type: 'function-body',
#         statements: [Array],
#         symbolTable: [ScopedMap [Map]]
#       },
#       returnType: 'int',
#       declaration: {
#         type: 'function-declaration',
#         name: 'main',
#         parameters: [Array],
#         returnType: 'int',
#         definition: [Circular *1]
#       },
#       parent: [Circular *2]
#     },
#     parent: Map(0) {}
#   }
# }

dev

Watch file changes and trigger test during development:

npm run dev
# npx nodemon -w src --ext mts --exec "npm test"

cc's People

Contributors

drincann avatar

Watchers

 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.