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

📄 parser.h

📁 编译器 用C语言对下述文法和单词表定义的语言设计编制一个编译器
💻 H
字号:
/**************************************************************************************************
 * parser.h
 *
 * 2008-04-20 12:13
 * 周鑫(zhouxin63766@yahoo.com.cn)
 *
 * 语法分析。
 *************************************************************************************************/

#ifndef PARSER_H
#define PARSER_H

#include <cstdarg>
#include <QStringList>
#include "glossary.h"
#include "shared.h"

typedef double (*FuncPtr)(double);
struct ExprNode
{
	enum TokenType opCode;

	union
	{
		struct
		{
			ExprNode *Left;
			ExprNode *Right;
		}CaseOperator;

		struct
		{
			ExprNode *Child;
			FuncPtr MathFuncPtr;
		}CaseFunc;

		double CaseConst;
		double *CaseParmPtr;
	}Content;
};

// Forward declaration
class QString;

class Parser
{
public:
	Parser();
	~Parser();

	bool build( const QString &fileName );

	QStringList errorList()
	{
		return _errorList;
	}
private:
	void fetchToken();
	void matchToken( enum TokenType AToken );
	void syntaxError( int errorCase );
	void printSyntaxTree( struct ExprNode *root, int indent = 1 );

	void program();
	void statement();
	void originStatement();
	void rotStatement();
	void scaleStatement();
	void forStatement();
	struct ExprNode *expression();
	struct ExprNode *term();
	struct ExprNode *factor();
	struct ExprNode *component();
	struct ExprNode *atom();
	struct ExprNode *makeExprNode( enum TokenType opcode, ... );

	Token token;
	double parameter;		// 参数T的存储空间
	double originX, originY;	// 横、纵平移距离
	double scaleX, scaleY;		//横、纵比例因子
	double rotAngle;		//旋转角度

	QStringList _errorList;
	Glossary *glossary;
	bool noError;
};
#endif

⌨️ 快捷键说明

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