aliasar1 / Compiler-Construction-Project

This is my compiler construction project which is implemented for only lexical and syntax analyzer phase in Java.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiler Construction Project

Objective

This is my compiler construction project which is implemented for only lexical and syntax analyzer phase. For syntax analyzer the provided rules are: E -> E + T , E -> T , T -> T * F , T -> F , F -> ( E ) , F -> id

The code is written in java. Along with that for GUI Java Swing is used.

Requirements

Recognize following tokens for the lexemes in the input source program: – Keywords: int, char, string, if, else, do, while. – Identifiers (ID): letter followed by zero or more letters or digits. – String Literal: (SL): anything that is surrounded by double quotes, for example “Hello” – Integer value (IV): example: 155 (unsigned only) – Relational Operators (ROP): <, <=, ==, <>, >= and > – Arithmetic Operators (AOP): +, -, *, / – Other Operators (OOP): assignment: =, parenthesis: (, ), braces: {, }, line terminator: ;

• Upon recognizing a token, lexical analyzer should output the lexeme, the token name and the attribute value based on the above table. • Store tokens in symbol table based on the above table. • Should properly handle the comments enclosed in /* and */ or following // . • Should properly handle the white spaces (blanks, tabs or newlines). • Also output all the data stored in the symbol table. • If the input to your compiler contains something other than the lexemes mentioned in the table above, then it should generate and display the error with: – The line number – The unrecognized lexeme in the source code and – A meaningful error message • For Syntax Analysis, if the input contains a legal expression involving operators + and * and parenthesis ( and ), your compiler should accept it and output “Compiled Successfully” message, otherwise give out error message with correct line number and a meaningful error message: Use the CFG and the Parsing Table given below for Syntax Analysis of the input.

image

Here are the screen shots of GUI:

image

Lexical Analyzer Working:

image image

Incase of Lexical Error:

image image

Syntax Analyzer:

image

Incase of Syntax Error:

image image

About

This is my compiler construction project which is implemented for only lexical and syntax analyzer phase in Java.


Languages

Language:Java 100.0%