Sei sulla pagina 1di 23

C2JS

A C COMPILER

ADVISORS:
MR. MAHMOOD SIDDIQUE (INTERNAL) MR. BILAL GHAFFAR (EXTERNAL)

Members:

Danish Nawab Shabbir-ul-Hassan Usman Riaz

L1F10BSCS0032 L1F10BSCS0003 L1S11BSCS2033

C2JS - CORE
A C compiler that compiles (translates) C source into JavaScript source.
Sourc e Targe t

.C

C2JS

.JS

Desired result will be achieved by defining syntax level equivalence between C & JavaScript languages.
Support for C language standard library (ANSI C) will be provided.

C2JS RUNTIME
The generated JavaScript source could very well be executed in a JavaScript engine, whether it is inside a browser or any desktop based runtime environment.
Sourc e Targe t
100110 001001 111010

.JS

WHY HLL TO HLL ?


Question: Why translate one High Level Language (HLL) to another HLL?

Portability Interoperability Bootstrap economics of the HLL

Why translate C language to JavaScript?

RISE OF C

IMPORTANCE OF JAVASCRIPT
Browser support NodeJS
JavaScript on the Desktop JavaScript on embedded Devices JavaScript on server scale machinery

PhoneGap
JavaScript on the smart phones (iOS, Android, BlackBerry,
Windows Phone)

WHY C TO JS?

Cross Platform Executes in the browser Rapid Prototyping for C Bridges the gap between C & JS learning Opens C to JS ecosystem Enables the possibility of a web framework

JAVASCRIPT ECOSYSTEM
Apple iTunes Store
(till 2013) : 40 billion apps downloaded

Google Play
2013)

:
:

50 billion app downloads


750 million apps

(till
(till

Chrome Web Store


2012)

All these markets would be accessible to C developer if


they have a way to port C code to JS

C VALIDATE EMAIL
int isemail (char *email) { int atsign = -1, dot = -1, i = 0; if (! isalpha(email[0]) ) return 0;

else if (email[i] == '.') { if (dot == -1) dot = i; else return 0; } }


if (atsign > dot) return 0; return isdomain (&email[dot]); }

int length = strlen(email); for (i = 0; i < length; i++) { if (email[i] == '@') { if (atsign == -1) atsign = i; else return 0; }

JAVASCRIPT VALIDATE EMAIL


function isemail(email) { var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/; if ( re.test(email) ) return false; } return true;

INTEROPERABLE WEB FRAMEWORK


int isemail (char *email) { char *regex = "/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/"; int result = match(email, regex); return result; }

R&D GOALS (OBJECTIVES)


Source to Source Compiler Theory Compiler as a Service Implementation (Compiler on
Demand)

Browser based Integrated Development Environment Efficient Mapping between C & JS libraries Management of the local compilation & execution

MOTIVATION
Add C to the list of languages that compile down to JS Abstract the compilation from user space Provide a way to rapidly develop C & JS applications Enable C developers to become stakeholders of JS
ecosystem

RELATED PRODUCTS
Overview of a compiler

RELATED PRODUCTS

Overview of a compiler
Sourc e
Lexer Parse r Optimizer

Front-End
Semantic Analyzer

IR

Back-End
Code Generator

Targe t

RELATED PRODUCTS

Emscripten
Assumes that the input file is syntactically correct.
Source Targe t

Corre ct.C

Emscripten

.JS

RELATED PRODUCTS

C2JS vs Emscripten
Sourc e

Lexer

Parse r

Optimizer

Targe t

.C

Front-End
Semantic Analyzer

IR

Back-End
Code Generator

.JS

.C

RELATED PRODUCTS

Variety of online compilers


Heavily make use of network resources

ONLINE C COMPILERS
.C
Cloud
[C compiler]

.ex e

Cloud

User Browser

Program Input
Program Output

[C Runtime]

PEEK INTO THE C2JS INFRASTRUCTURE

Progra m Input

User Browser
[C2JS web-page]

Program Output

PROJECT PLAN

Potrebbero piacerti anche