📄 ll1.cpp
字号:
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <iomanip.h>
#include <ctype.h>
void printgrammer();
void copyright();
void index();
int syntax_tree(char * );
void get_expression();
int size = 80;
char string[80];
char * tokenptr;
char *grammer[3] = {"E > E + T","T > T * F","F > id"};
int num_of_op=0;
int num_of_id = 0;
int main()
{
int exit;
index();
//tokenize the given sentence...
cout << "The sentence to be tokenized is: "<<string<<endl;
tokenptr = strtok(string," ");
while (tokenptr != NULL)
{
cout <<tokenptr<<" size is: "<<strlen(tokenptr) << '\n';
tokenptr = strtok(NULL," ");
if (*tokenptr == '*' || * tokenptr == '+')
num_of_op++;
else
num_of_id++;
}
//-----------------------------------
//cout << num_of_op << num_of_id;
if (++num_of_op == num_of_id)
cout << "\n\n\nsentence is correct...";
else
cout << "\n\n\nsyntax error...";
getch();
return 0;
}
/***************************************************/
int syntax_tree(char * token){
for (int i = 0 ; i < strlen(token); i++)
{
if ((toupper(token[i]) >'A') && (toupper(token[i]) < 'Z'))
{
cout << "code is compiling...\nPlease wait...\n";
}
if (token[i] == '(')
{
cout << "nested expression are found...\n";
}
if (token[i] == '+')
{
cout << "addition expression are used...\n";
}
else
if (token [i] == '*')
{
cout << "addition expression are used...\n";
}
}
return 0;}
void printgrammer()
{
cout << "\t\tThe Grammer Rules is :\n";
//print the used grammer...
for (int i=0; i<3; i++)
cout << "\t\t"<<i+1 << " : " << grammer[i]<<endl<<endl;
}
void index()
{
copyright();
printgrammer();
get_expression();
}
void copyright()
{
cout << "\t\t ===============================\n\n";
cout << "\t\t = Compiler Home Work =\n\n";
cout << "\t\t = Programed by =\n\n";
cout << "\t\t = Sarah Mozfi Al Omyan =\n\n";
cout << "\t\t ===============================\n\n\n";
}
void get_expression()
{
cout << "Enter a sentence:\n*Note: Separate the sentence by space... required..\n";
cin.get(string,size);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -