0% found this document useful (0 votes)
145 views

C2JS

This document summarizes a project called C2JS that aims to compile C code to JavaScript. The project is being undertaken by 3 students - Danish Nawab, Shabbir-ul-Hassan, and Usman Riaz. C2JS will define syntax equivalence between C and JavaScript and support the C standard library. The generated JavaScript can then be executed on JavaScript engines in browsers or desktop runtimes. The goals are to make C portable, enable interoperability between C and JavaScript, and allow C developers access to the large JavaScript ecosystem.

Uploaded by

arslan0989
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views

C2JS

This document summarizes a project called C2JS that aims to compile C code to JavaScript. The project is being undertaken by 3 students - Danish Nawab, Shabbir-ul-Hassan, and Usman Riaz. C2JS will define syntax equivalence between C and JavaScript and support the C standard library. The generated JavaScript can then be executed on JavaScript engines in browsers or desktop runtimes. The goals are to make C portable, enable interoperability between C and JavaScript, and allow C developers access to the large JavaScript ecosystem.

Uploaded by

arslan0989
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like