中文词法分析的简单程序
VC 6.0 下编译通过 disc 为辞典 expression 为输入的短语
// Code.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream.h"
#include "string.h"
#include "windows.h"
int CountWord(char* words); //计算有多少个字符
struct dict
{
char syn[8],word[6];
int scode,wcode;
} dic[19];
int main(int argc, char* argv[])
{
strcpy(dic[0].syn,"祈使动词");
dic[0].scode=0;
strcpy(dic[0].word,"请");
dic[0].wcode=0;
strcpy(dic[1].syn,"祈使动词");
dic[1].scode=0;
strcpy(dic[1].word,"把");
dic[1].wcode=1;
strcpy(dic[2].syn,"代词");
dic[2].scode=1;
strcpy(dic[2].word,"你");
dic[2].wcode=0;
strcpy(dic[3].syn,"动词");
dic[3].scode=2;
strcpy(dic[3].word,"走");
dic[3].wcode=0;
strcpy(dic[4].syn,"动词");
dic[4].scode=2;
strcpy(dic[4].word,"跑");
dic[4].wcode=1;
strcpy(dic[5].syn,"动词");
dic[5].scode=2;
strcpy(dic[5].word,"跳");
dic[5].wcode=2;
strcpy(dic[6].syn,"动词");
dic[6].scode=2;
strcpy(dic[6].word,"转");
dic[6].wcode=3;
strcpy(dic[7].syn,"动词");
dic[7].scode=2;
strcpy(dic[7].word,"抬");
dic[7].wcode=4;
strcpy(dic[8].syn,"方向词");
dic[8].scode=3;
strcpy(dic[8].word,"向左");
dic[8].wcode=0;
strcpy(dic[9].syn,"方向词");
dic[9].scode=3;
strcpy(dic[9].word,"向右");
dic[9].wcode=1;
strcpy(dic[10].syn,"方位词");
dic[10].scode=4;
strcpy(dic[10].word,"向前");
dic[10].wcode=0;
strcpy(dic[11].syn,"方位词");
dic[11].scode=4;
strcpy(dic[11].word,"侧");
dic[11].wcode=1;
strcpy(dic[12].syn,"名词");
dic[12].scode=5;
strcpy(dic[12].word,"左手");
dic[12].wcode=0;
strcpy(dic[13].syn,"名词");
dic[13].scode=5;
strcpy(dic[13].word,"右手");
dic[13].wcode=1;
strcpy(dic[14].syn,"名词");
dic[14].scode=5;
strcpy(dic[14].word,"左腿");
dic[14].wcode=2;
strcpy(dic[15].syn,"名词");
dic[15].scode=5;
strcpy(dic[15].word,"右腿");
dic[15].wcode=3;
strcpy(dic[16].syn,"副词");
dic[16].scode=6;
strcpy(dic[16].word,"快");
dic[16].wcode=0;
strcpy(dic[17].syn,"副词");
dic[17].scode=6;
strcpy(dic[17].word,"慢");
dic[17].wcode=1;
strcpy(dic[18].syn,"其他词");
dic[18].scode=7;
strcpy(dic[18].word,"起来");
dic[18].wcode=0;
//////////////////////--Init Data End
///////////////////////////////////////////
char expression[30],phrase[40]; //输入句子的分词程序
char *p1,*p2; //*
PWORD pw_exp1,pw_exp2,pw_old; //temp pw_old Can RollBack
int n_WordNub = 0,n_InputNub = 0; //*
strcpy(expression,"请你向前走快抬左手侧左腿");
for(int i=0; i<40; i++)
phrase[i] = ' ' ;
phrase[39] = '