Implementing a mini compiler
that takes as input a JavaScript program (with focus on the programming construct for loop statements) and produces an optimized intermediate code as an output.
This project uses yacc
and lex
to generate a mini compiler for JavaScript. A mini compiler
performs lexical analysis, symbol table generation and syntax validation. This project intends to manage assignments, datatypes, evaluate expressions and emulate loops in javascript.
- To initalize the project:
git clone [email protected]:Varun487/MiniJavaScriptCompiler.git
cd MiniJavaScriptCompiler
make
- To compile and run a program:
./jscompiler < test.js
- Varun Seshu - PES2201800074
- Sneha Jain A - PES2201800030
- Bhavan Naik - PES2201800047
- Lexical Analysis and Token Generation
- Conversion of strings to numbers
DONE
- Update yylval, yylloc, other global variables (line and col nums) and return token code for each action
- Record the line number and first and last column in yylloc for all tokens
- Recording the position of each lexeme requires you to track the current line and column numbers (you will need global variables) and update them as the scanner reads the file, most likely incrementing the line count on each new line and the column on each token. A tab character accounts for 8 columns.
- Report lexical errors for improper strings, lengthy identifiers, and invalid characters
- For each character that cannot be matched to any token pattern, report it and continue parsing with the next character.
- If a string erroneously contains a newline, report an error and continue at the beginning of the next line.
- If an identifier is longer than the maximum (31 characters), report the error, truncate the identifier to the first 31 characters (discarding the rest), and continue.
- Conversion of strings to numbers
- Symbol Table generation
- CFG and Parsing (Syntax validation)
- Print number
DONE
- Print string
DONE
BUGS
- Assign Variable
- number
- string
- Print Varible
- number
- string
- Simple math expressions
- Assign variable after computing numeric expression
- Assign variable after computing string expression
- Assign variable after computing string and numeric combination expression
- Print after computing numeric expression
- Print after computing string expression
- Print after computing string and numeric combination expression
- Boolean operations on variables
- Increment and decrement variables
- For loop computation
- Recognising errors and suggesting fix
- Evaluate complex math expressions?
- Objects?
- Dot notation?
- Functions?
- Print number
- BUGS
- Multiline comments not working
- if a file ends with unterminated comments, return error
- Fix Inline comment after a statement
- Evaluate special charaters in a string
- Produce error if string not terminated properly or partially terminated