⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 analyze.cpp

📁 在纯DOS下运行的TurboC3_ucos2_ucgui bug改进版本
💻 CPP
字号:
/* 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(" ");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -