?? analyze.cpp
字號(hào):
/* analyze.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include "data.h"
void main()
{
int i;
char item=' ';
void list_analyze();
while(item!='3')
{
printf("\n1 . input expression to analyze\n2 . list analyze progress\n3 . exit\nplease enter your choice:");
item=getche();
switch (item)
{
case '1' : {
printf("\nplease input a ll(1) sentence :");
for(i=0;i<=input_max;i++) input_stream[i]='\0';
scanf("%s",input_stream);
strcat(input_stream,"~");
}
break;
case '2' : list_analyze();break;
case '3' : break;
default : printf("\nerror,please input again");
}
}
}
void list_analyze()
{
VT get_next();
void print_step();
int i;
input_ptr=0;
analyze_stack=NULL;
line=0,num=0;
push(ana_sign);
top=E;
next=get_next();
while(analyze_matrix[top][next].err==0)
{
i=0;
print_step();
while(analyze_matrix[top][next].right[i]!=empty)
push(analyze_matrix[top][next].right[i++]);
if(analyze_matrix[top][next].del==1)
{
next=get_next();
if(next==NUL) {printf("\nthis is not a sentence of ll(1) syntax");return;}
}
top=pop();
}
if(analyze_matrix[top][next].err==-1) printf("\nthis is a correct sentence of ll(1) syntax");
else printf("\nthis is not a sentence of ll(1) syntax");
return;
}
VT get_next()
{
switch (input_stream[input_ptr++])
{
case '+' : return add;
case '*' : return mul;
case 'i' : return i;
case '(' : return lef;
case ')' : return VT_rgt;
case '~' : return VT_sign;
default : return NUL;
}
}
void print_step()
{
int i;
analyze_node *temp=analyze_stack;
if(++line>19) {line=0;getch();}
printf("\n%3d : ",++num);
i=0;
while(i<stack_max&&temp!=NULL)
{
printf("%s",ana_cha[temp->data]);
temp=temp->next;
i++;
}
printf("%s",ana_cha[top]);
for(;i<stack_max;i++) printf(" ");
for(i=0;i<input_max;i++)
if(i>=input_ptr-1) printf("%c",input_stream[i]);
else printf(" ");
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -