a simple language C--(C++ like) C-- should have braces for blocks of code, an if
ID: 3555600 • Letter: A
Question
a simple language C--(C++ like)
C-- should have braces for blocks of code, an if statement, while statement, and a double, int, and character. Each statement ends with a semi-colon and you must have a main routine (forget about defining methods). Needs to declare variables and have some sort of print and input statement.
Make the languages simple. You can use the extended BNF to describe the language. Then have a sample program as follows:
For C--, read in the number of values, then read in that many numbers, while summing and printing them, and print the sum
Explanation / Answer
#include #include mixture : [letter|digit] {letter | digit}; integer : [ "+"|"-"] digit {digit}; naturalNumber : digit {digit}; digit : "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; letter : "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" | "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"; int main() { char c[7]; c[0] = '1'; c[1] = '2'; c[2] = '3'; c[3] = 'x'; c[4] = 'y'; c[5] = 'z'; c[6] = ''; if(c == mixture){ printf("You have a mixture of numbers and letters"); } else if(c == integer){ printf("This is just a number"); } else if(c == naturalNumber){ printf("This is just a positive number"); } else if(c == digit){ printf("This is a plain digit"); } else if(c == letter){ printf("This is a plain letter"); } return 0;Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.