sntncelex.c
资源名称:ictprop.rar [点击查看]
上传用户:tenhai
上传日期:2021-02-19
资源大小:492k
文件大小:4k
源码类别:
组合框控件
开发平台:
Visual C++
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "sntncelex.h"
- #include "grmrgrph.h"
- #define MAXTOKENSIZE 100
- //#define MAXLINESIZE 5000
- char token[MAXTOKENSIZE];
- char sentbuf[MAXSENTLEN];
- int symbmode;
- int endofsntnce;
- int endposofsntnce;
- unsigned int nextcate, currcate;
- unsigned int curchartnode, prechartnode, accchartnode;
- wentry_t *nextwentry, *currwentry;
- wentry_t *wentries[MAXCNODE-1];
- unsigned int (*nextdefs)[MAXDEFS], (*currdefs)[MAXDEFS];
- unsigned int deflettice[MAXCNODE-1][MAXDEFS];
- FILE *pfs;
- int bufptr;
- //int maxlink;
- //int fufiled;
- wentry_t *dictionary[MAXWENTRY];
- int hash(char *s){
- unsigned hashval;
- for (hashval=0;*s!=' ';s++)
- hashval=*s+31*hashval;
- return hashval % MAXWENTRY;
- }
- wentry_t *listsearch(int hashval, char *word){
- wentry_t *curwentry;
- for (curwentry=dictionary[hashval];curwentry!=NULL;curwentry=curwentry->nxt){
- // link++;
- // if (link>maxlink)
- //maxlink=link;
- if (strcmp(curwentry->word, word)==0)
- break;
- }
- return curwentry;
- }
- int listrelease(int hashval){
- wentry_t *pwentry, *qwentry;
- def_t *pdef, *qdef;
- for (pwentry=dictionary[hashval];pwentry!=NULL;pwentry=qwentry){
- qwentry=pwentry->nxt;
- for (pdef=pwentry->def;pdef!=NULL;pdef=qdef){
- qdef=pdef->nxt;
- free(pdef);
- }
- free(pwentry->word);
- free(pwentry);
- }
- return 0;
- }
- int dictrelease(){
- int i;
- for (i=0;i<MAXWENTRY;i++){
- listrelease(i);
- dictionary[i]=NULL;
- }
- return 0;
- }
- wentry_t *dictsearch(char *word){
- return listsearch(hash(word), word);
- }
- wentry_t *dictinsert(char *word){
- int hashval;
- wentry_t *newwentry;
- hashval=hash(word);
- newwentry=listsearch(hashval, word);
- if (newwentry==NULL){
- newwentry=(wentry_t *)malloc(sizeof(wentry_t));
- newwentry->def=NULL;
- newwentry->word=(char *)malloc(strlen(word)+1);
- strcpy(newwentry->word, word);
- newwentry->nxt=dictionary[hashval];
- // if (newwentry->nxt==NULL)
- // fufiled++;
- dictionary[hashval]=newwentry;
- }
- return newwentry;
- }
- adddef(wentry_t *wentry, unsigned int cate){
- def_t *curdef, *newdef;
- for (curdef=wentry->def;curdef!=NULL;curdef=curdef->nxt)
- if (curdef->cate==cate)
- break;
- if (curdef==NULL){
- newdef=(def_t *)malloc(sizeof(def_t));
- newdef->cate=cate;
- newdef->nxt=wentry->def;
- wentry->def=newdef;
- }
- return 0;
- }
- /*
- char *gettoken(){
- int c, pos=0;
- while ((c=fgetc(pfs))==' '||c=='t')
- ;
- if (c==EOF || c=='n')
- endofsntnce=1;
- else{
- do{
- token[pos++]=(char)c;
- }while ((c=getc(pfs))!=EOF && c!=' ' && c!='t' && c!='n') ;
- if (c=='n')
- ungetc(c, pfs);
- }
- token[pos]=' ';
- return token;
- }
- */
- filllattice(){
- int i,j,c,pos;
- char *stoken;
- def_t *pdef;
- endposofsntnce=-1;
- for (i=0; i<(MAXCNODE-1); i++){
- if (endposofsntnce>=0)
- break;
- pos=0;
- while (((c=sentbuf[bufptr++])==' ')||c=='t')
- ;
- if (c=='n' || c==' ')
- endposofsntnce=i;
- else{
- do{
- token[pos++]=(char)c;
- }while ((c=sentbuf[bufptr++])!=' ' && c!=' ' && c!='t' && c!='n') ;
- if (c=='n'||c==' ')
- bufptr--;
- }
- token[pos]=' ';
- if (*token==' ')
- endposofsntnce=i;
- if (*token!=' ')
- stoken=strtok(token, "/");
- else
- stoken=token;
- wentries[i]=dictinsert(stoken);
- if (*token!=' ')
- stoken=strtok(NULL, "/");
- else
- stoken=NULL;
- if (stoken!=NULL){
- deflettice[i][0]=token2tcode(stoken);
- deflettice[i][1]=tcount;
- }
- else{
- for (j=0, pdef=wentries[i]->def;pdef!=NULL;pdef=pdef->nxt){
- deflettice[i][j++]=pdef->cate;
- }
- deflettice[i][j]=tcount;
- }
- }
- return 0;
- }
- lookahead(){
- nextwentry=wentries[curchartnode];
- nextdefs=&deflettice[curchartnode];
- // for (i=0; i<MAXDEFS; i++)
- // nextdefs[i]=deflettice[curchartnode][i];
- endofsntnce=(endposofsntnce==curchartnode);
- return 0;
- }