- 11
- 0
- 约1.98万字
- 约 16页
- 2017-12-11 发布于河南
- 举报
词法分析程序(C语言编写,针对PL_0语言)
#include stdio.h
#include stdlib.h
#include string.h
#define NORW 13 /* of reserved words */
#define TXMAX 100 /* length of identifier table */
#define NMAX 14 /* max number of digits in numbers */
#define AL 10 /* length of identifiers */
#define AMAX 2047 /* maxinum address */
#define LEVMAX 3 /* max depth of block nesting */
#define CXMAX 200 /* size of code array */
#define STACKSIZE 500
char *symbol[32]= {nul,ident,number,plus,minus,times,slash,oddsym,
eql,neq,lss,leq,gtr,geq,lparen,rparen,comma,
semicolon,period,becomes,beginsym,endsym,ifsym,
thensym,whilesym,writesym,readsym,dosym,callsym,
constsym,varsym,procsym}; /* type of symbols */
char *word[NORW]={begin,call,const,do,end,if,odd,procedure,
read,then,var,while,write}; /* table of reserved words */
char *wsym[NORW]={ beginsym,callsym,constsym,dosym,endsym,ifsym,
oddsym,procsym,readsym,thensym,varsym,whilesym,writesym};
char *mnemonic[8]= {lit,opr,lod,sto,cal,ini,jmp,jpc};
char ch; /* last char read */
char id[AL+1]; /*last identifier read */
char sym[10]; /* last symbol read */
char line[81];
char a[AL+1],fname[AL+1];
enum object{constant,variable,procedur};
enum object kind;
enum fct{lit,opr,lod,sto,cal,ini,jmp,jpc};
enum listswitcher{false,true}; /*true set list object code */
enum listswitcher listswitch;
FILE *fa;
FILE *fa1, *fa2;
FILE *fin, *fout;
int num; /* last number read */
int cc; /* character count */
int ll; /* line length */
int cx; /* code allocation index */
int err;
int lev=0,tx=0,dx=3;
int linecnt=0;
struct instruction
{enum fct f; /* function code */
int l; /* level */
int a;
原创力文档

文档评论(0)