詞法掃瞄器設計

2021-04-13 13:57:45 字數 3738 閱讀 9967

/*詞法掃瞄器設計*/

/*2007-10-24 21:22除錯通過*/

#include "iostream.h"

#include "stdlib.h"

#include "fstream.h"

#include "stdio.h"

#include "string.h"

/*the length of token if 9*/

#define max_len_token 10

#define max_len_symbol 3

#define keywordnumber 21

#define operatornumber 8

/*以下為使用的語言子類

保留字procedure ,var ,begin ,if ,then ,else ,end ,do ,while ,switch ,case ,for ,string ,false ,maxint ,true ,boolean ,char ,real ,integer ,new

運算子+ - * / ( ) :=

對於其他暫時不做過多考慮

*/typedef struct token_mytoken;

typedef struct symbol_symbol;

struct input;

/*function*/

void read_file(char * );  /*從檔案中讀出資料*/

void init(void);  /*init*/

int inputchar(char ); /*讀入乙個字元*/

int isoperator(char ); /*是否為 operator*/

void movestr (void ); /*將字元陣列移動到鍊錶中*/

void iskeyword(char * ); /*是否為 keyword*/

int exist(char *, mytoken * ); /*是否已經存在*/

void printall(void); /*全部列印到螢幕*/

/*list*/

//因為不區分大小寫,設定兩個陣列,乙個用於比較字元,另乙個用於儲存輸入的字元

mytoken *keywordlist, *idlist ,*constantlist; /*儲存字元*/

mytoken *keywordcmp , *idcmp , *constantcmp; /*儲存比較字元*/

int operatorflag[operatornumber];

mytoken syskw[keywordnumber];

symbol sysop[operatornumber];

int delimiterflag ;

struct input *n_input =(struct input *)malloc (sizeof(struct input));

struct input *ori_input =(struct input *)malloc (sizeof(struct input));

char operatorbuf[4];

static int bufcount =0;

static int ncount=0;

static int rowcount =0;

static int flag =0;

void main(int argc,char *argv)

;void read_file(char * filename)

for( i = 0 ; i < 4 ; i++)

for ( i = 0 ;i < operatornumber ;i++)

};/**************************

0 is continue

1 is ok

2 is error

***************************/

int inputchar (char c)

if(c ==0x0a)

if (isoperator (c))

operatorbuf[bufcount ++] = c;

return 1;

}bufcount =0;

if( (c > 0x40 )&& (c < 0x5b ))

ccompare = c + 0x20;

else

ccompare = c;

corigin = c;

if ((ccompare >0x60) && (ccompare < 0x7b))

if( n_input-> type & 4 != 0 )

n_input-> type ^= 4;

n_input-> str[ncount] =ccompare ;

ori_input-> str[ncount ++] =corigin ;

return 0;

}else if((ccompare > 0x2f) && (ccompare < 0x3a))

else if(ccompare == '_')

return 2;

};int isoperator (char c);

void movestr (void )

else if(n_input ->type == 2)

else if(n_input ->type == 4)

if(exist (n_input ->str ,q))

return ;

//新增資料到list中

while (p->next != null)

p = p->next ;

p->next = (mytoken *)malloc (sizeof (mytoken));

p = p->next ;

p->next =null;

strcpy(p->str ,ori_input ->str );

while(q->next != null)

q = q->next ;

q->next = (mytoken *)malloc (sizeof (mytoken));

q = q->next ;

q->next =null;

strcpy(q->str ,n_input ->str );

//重置

for (int i = 0;i < 10 ;i++)

n_input-> type = 7 ;

ncount = 0;

}if (bufcount != 0)}}

else if (bufcount == 2)

}bufcount = 0;

operatorbuf[0] = 0 ;

operatorbuf[1] = 0 ;}};

void iskeyword(char *key)

}n_input->type = 1;

};int exist(char *str, mytoken *list)

p = p->next ;

}return 0;

};void printall(void )

cout<<"*******************"while(p !=null)

cout<<"*******************"while(p !=null)

cout<<"*******************"

掃瞄器詳解

一 掃瞄器的定義 掃瞄器是一種獲取影象的裝置,並將資訊轉為電腦可以顯示 編輯 儲存和輸出的數字格式。即可以完成以下工作 在檔案中插隊圖和 將文字識別,免去打字 將傳真檔案掃到庫中存檔 在多 中加入影象 在報刊中加入有效表達主題。二 掃瞄器的工作原理 將光線照到待掃瞄的稿件上,光線反向回平後再由乙個稱...

編寫漏洞掃瞄器

編寫漏洞掃瞄器 一 漏洞掃瞄器基本原理 編寫漏洞掃瞄器探查遠端伺服器上可能存在的具有安全隱患的檔案是否存在,它的socket建立過程和上面的埠掃瞄器是相同的,所不同的是漏洞掃瞄器通常使用80埠,然後對這個埠傳送乙個get檔案的請求,伺服器接收到請求會返回檔案內容,如果檔案不存在則返回乙個錯誤提示,通...

API掃瞄器小結

不久前,冏哥叫我寫乙個api的掃瞄器,具體的要是先的功能就是掃瞄api,當然是用shell實現。我這個shell語法都有點問題的小青年寫的可是夠嗆人的。下面是有一些語法的問題,我記錄下。echo 2.0 1.2 bc 如果正確就返回1,否則返回0。bin bash i 1while read isb...