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

📄 parser.h

📁 近日学习编译原理课程
💻 H
字号:
#pragma once

#ifndef  FILENAME_LENGTH
#define FILENAME_LENGTH	128
#endif

#ifndef IDLENGTH
#define IDLENGTH	15
#endif

#ifndef STRLENGTH
#define STRLENGTH	255
#endif

extern  char sourcefile[];
extern  FILE *in, *out;
extern  FILE *str;
void fatal_error( const char msg[] );

//////////////////////////////////////////

enum keyword{
	identity=0,
	//关键字
	k_if=100,
	k_of,
	k_do,
	k_to,
	k_or,
	k_var,
	k_for,
	k_end,
	k_not,
	k_and,
	k_div,
	k_mod,
	k_type,
	k_then,
	k_else,
	k_const,	k_begin,
	k_while,
	k_array,
	k_downto,
	k_record,
	k_program,
	k_function,
	k_procedure,

	//常量
	c_true=200,
	c_false,
	c_integer,
	c_real,
	c_string,
	c_char,
	c_maxint,
	//系统类型
	t_integer=300,
	t_char,
	t_boolean,
	t_real,	t_string,
	//系统函数	f_abs=400,
	f_sqr,
	f_ord,
	f_chr,
	f_succ,
	f_pred,
	f_odd,	f_read,	f_readln,
	f_write,
	f_writeln,

	//操作符和分隔符
	o_plus=500,//+
	o_minus,//-	o_ls,//<
	o_le,//<=
	o_gt,//>
	o_ge,//>=
	o_ne,//<>
	o_eq,//=
	o_lparent,//[
	o_rparent,//]
	o_lbracket,//(
	o_rbracket,//)
	o_comma,//,
	o_semicolon,//;
	o_period,//.
	o_colon,//:
	o_becomes,//:=
	o_range,//..
	o_time,//*
	o_div///
};
typedef struct  tuple{
	keyword	flag;
	union	DATA{
		char c_val;
		struct int_val{
			int	int_val1;
			int	int_val2;
		}i_val;
		double d_val;
	}data;
}TUPLE;
extern TUPLE result_tuple;
extern int _linenum;
int	lex();

#ifdef _DEBUG
void print_result(FILE*o=stdout);
#endif
#define LEX_NOTUPLE		-1
#define LEX_END			0
#define LEX_SUCCESS		1
#define LEX_WITH_ERROR	2
#ifdef  _DEBUG
#define LEX_MAX_IDENTITY 512
#else 
#define LEX_MAX_IDENTITY 2048
#endif
//所有的字符串常量都保存在文件*.str中

⌨️ 快捷键说明

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