Compilers Lab
Compilers Lab
lec 1
#define
Syntax for Defining Constant macro:
#define MACRO_NAME value
#define PI 3.14
int main()
{
float r, area;
cout << "Enter the radius of a circle: ";
cin >> r;
area = PI * (r * r);
cout << "Area = " << area;
return 0;
}
int main()
{
int x,y;
cout << "Enter the value of x and y: ";
cin >> x >> y;
int sum = SUM(x,y);
cout << "sum = " << sum;
return 0;
}
compilers || 3rd stage Shahad Ali
H.W // Write a C++ program that uses a macro SQUARE(x) to calculate the
square of a number and prints the result for x.
write c++ program to identify keywords from a given input string “int a = 5;”
#include <iostream>
#include <string>
using namespace std;
int main() {
char c;
string x, code = "int a = 5;";
#include <iostream>
#include <string>
using namespace std;
int main() {
char c;
string x, code = "if (a>b)";
c = code[i];
if (isalpha(c) || (isdigit(c) && x!="")) {
x = x+c;
}
else {
if(x!="") {
if(!keyword(x)){
cout<<x<<"\tid\n";
}
x=""; }
}
}
if(x!="") {
if(!keyword(x))
cout<<x<<"\tid\n";
}
return 0; }
int main() {
tokenize("4 + 5");
return 0;
}
int main() {
find_P("3 * (2 + 1)");
return 0;
}