Reference no: EM133169988
CIS524 Project
Requirements:
• Write in two languages
o Language 1: C or C++
o Language 2: Java
o Language 3: Python
• Must be able to compile in a machine in our department (spirit, bach, etc)
• Submit to both CSU Blackboard and grail.eecs.csuohio.edu CIS524
• Each person in a group must submit; otherwise treated as "NO SUBMISSION" (0 points)
Project Description:
Write a parser for a programming language that accepts the following EBNF using the method in textbook Chapters 3 and 4
<Program1> -> (<VarDefinition> | <AssignmentStatement> | <ForStatment>) {(<VarDefinition> | <AssignmentStatement> | <ForStatment>) }
<varDefinition> -> var <varName>;
<varName> -> (a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z){ (0|1|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z) }
<AssignmentStatement> -><varname> = <ExpressionStatement>;
<ExpressionStatement> -> (<varname> | <constant>) { + (<varname> | <constant>) };
<constant> -> (0|1) {(0|1)}
<ForStatement> -> for "(" var <AssignmentStatement><ConditionStatement><IncreasementStatement> ")" "{"
{<AssignmentStatement>}
"}"
<ConditionStatement> -><VarName>(">" | "<" )<ExpressionStatement>
<IncreasementStatement> -><varName>++;
(1) var <varname>;
<varname> -> (a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z){0|1|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z}
<varname> begins with a letter in a-z, remaining can be a-z, 0-1
var is the keyword.
Example:
var abcd001;
(2) assignment statements
<varname> = (<varname> | <constant>) { + (<varname> | <constant>) };
<constant> is an integer number in binary format, such as 000, 1000, 011000011, 111001000
example
var1 = var2 + var3 + 110 + 011 + var5;
(3) for statements
example
for (var var1=001; var1 < 11100; var1++){
myvar = myvar + var1;
}
Given a text file, if the text file follows the above format, your compiler compiles the text file successfully, and outputs
"Compilation succeeded."
Eg. run your compiler as ./MyCompiler successful-compilation-text-case-1.txt
the successful-compilation-text-case-1.txt is written as follows:
var counter;
counter = 10;
for (var index=0; index < 11100; index++){
counter = counter + index;
}
The output will be "Compilation succeeded."
Given a text file, if the text file fails the above grammar, it will point out where the exact position where the grammar is wrong.
If there are multiple places grammar is wrong, then the first position where grammar is wrong will be pointed.
It will point to the exact line and the exact column position from the line that is incorrect.
Eg. run your compiler as ./MyCompiler unsuccessful-compilation-text-case-1.txt
the unsuccessful-compilation-text-case-1.txt is written as follows:
var counter;
counter = 93
for (var index=0; index < 11100; index++){
counter = counter index;
}
Your program will output
Line 2, column 11, incorrect grammar
Compilation failed.
Eg. run your compiler as ./MyCompiler unsuccessful-compilation-text-case-2.txt
the unsuccessful-compilation-text-case-2.txt is written as follows:
var counter;
counter = 11;
for (var index=0; index 11100; index++){
counter = counter index;
}
Your program will output
Line 3, column 25, incorrect grammar
Compilation failed.
Eg. run your compiler as ./MyCompiler unsuccessful-compilation-text-case-3.txt
the unsuccessful-compilation-text-case-3.txt is written as follows:
var counter;
counter = 11;
for (var index=0; index < 11100; index++){
counter = counter index;
}
Your program will output
Line 4, column 23, incorrect grammar
Compilation failed.
Attachment:- Group_project.rar