parser.h

来自「compiler principle how to ananilyze」· C头文件 代码 · 共 79 行

H
79
字号
// Parser.h: interface for the Parser class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PARSER_H__5FBF73C5_1C0B_437F_A991_37F9E34F3ED4__INCLUDED_)
#define AFX_PARSER_H__5FBF73C5_1C0B_437F_A991_37F9E34F3ED4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Token.h"
#include "Lexer.h"

#include "Product.h"
#include "GrammarTitleProduct.h"

class Parser  
{
private:
	Token look_ahead;
	Lexer lexer;
	
	GrammarTitleProduct grammarTitle;
	vector<Product> products;
	int currentRow;
	int currentColumn;

	/*
	G[S];
	S -> GrammarTitle ';' ProductList;
	GrammarTitle -> GrammarName '[' StartSymbol ']' ;
	ProductList -> Product ';' ProductList | epsilon;
	Product -> LeftList '->' RightListSet;
	LeftList -> VN LeftList | epsilon;
	RightListSet ->   RightList MoreRightList;
	RightList -> VT RightList | VN RightList | epsilon;
	MoreRightList -> '|' RightList MoreRightList | epsilon;

    GrammarName -> VN;
	StartSymbol -> VN;
	VN -> [A-Za-z][A-Za-z_0-9]* ; 
	VT -> \'Escape\' | 'epsilon' ;
	Escape -> NoEscapeChar Escape | '\\\\' Escape | '\\\'' Escape | epsilon;
	NoEscapeChar -> [^\'];
*/
	void g_GrammarTitle();
	void g_ProductList();
	void g_Product();
	void g_LeftList();
	void g_RightListSet();
	void g_RightList();
	void g_MoreRightList();

	void match(const Token& token);
	void match_advance(const Token& token);
	void advance();

	void addLocationInfo();
	void append_Left();
	void append_Right_Epsilon();
	void append_Right_VN_VT();
	void newProduct();
	void newAlternative();

	void checkExistStartSymbol() const;
	void check() const;
	void normalize();
public:
	Parser();
	
	void parse(ifstream* grammar);
	string grammar_display() const;
	string grammar_type();

};

#endif // !defined(AFX_PARSER_H__5FBF73C5_1C0B_437F_A991_37F9E34F3ED4__INCLUDED_)

⌨️ 快捷键说明

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