- A basic syntax and semantic analyser of C-based programs supporting following features:
- Data types -
int
,char
- Assignments to the variables can be done at the time of declaration.
- IO
get x;
(taking x as input from stdin)
put x;
(printing x at stdout) - Conditional statement syntax:
id = expression ? expression:expression;
- Relational Operators supported: {>, <, ~}
- Arithmetic Operators supported: {+, -, *}
- Only
main()
function is supported. The function may definition may contain arguments and return statement. - White-spaces and new lines within statements are ignored.
- Statements end with ;
- Data types -
- Steps involved in the construction of the Compiler -
- Construction of CFG for the language.
- Building Lexical Analyser to scan the stream of characters from a program written in above language and generate a stream of tokens to pass to the parser.
- Building a Bottom-up parser for this language using SLR(1) parsing technique.
mod.txt
: Map from symbols of the language to letters of CFGLetterCFG.txt
: CFG grammar productionsaugCFG.txt
: Human readable CFG grammar production
input.cpp
: Input file to analysekeywords.txt
: File for keywords
tokens.txt
: Output from Lexical AnalyserDFA_for_Lexical.txt
: DFA statesStatesFile.txt
: Item set createdGoToTransitions.txt
: Goto (I,a) for all item setParsing Table.csv
: SLR parsing table
- Put the file to be analysed in
input.cpp
- Open a terminal and go to the project's directory
- Run command
g++ -o compile driver.cpp -w
- Run command
./compile input_file