📄 lr(1).txt
字号:
#if !defined(AFX_LR_H__AE1C45AE_3327_435F_B08A_C405CB06A099__INCLUDED_)
#define AFX_LR_H__AE1C45AE_3327_435F_B08A_C405CB06A099__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h"
class CLRApp : public CWinApp{
public:
CLRApp();
//{{AFX_VIRTUAL(CLRApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
//{{AFX_MSG(CLRApp)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
#endif
========================
#if !defined(AFX_LRDLG_H__4519D97B_FF8A_4269_8661_4CD57D246904__INCLUDED_)
#define AFX_LRDLG_H__4519D97B_FF8A_4269_8661_4CD57D246904__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif
#include "mlr1.h"
class CLRDlg : public CDialog{
protected:
FILE* p_file;
MLR1 m_mlr1;
public:
CLRDlg(CWnd* pParent = NULL);
virtual ~CLRDlg();
//{{AFX_DATA(CLRDlg)
enum { IDD = IDD_LR_DIALOG };
CListBox m_lstShow;
//}}AFX_DATA
//{{AFX_VIRTUAL(CLRDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL
protected:
HICON m_hIcon;
//{{AFX_MSG(CLRDlg)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnFileOpen();
afx_msg void OnViewIdent();
afx_msg void OnViewFirstSet();
afx_msg void OnViewFollowSet();
afx_msg void OnMlr1Size();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
#endif
========================
#if !defined(AFX_MLR1_H__E7626B26_4BA9_4910_849A_151001216F5E__INCLUDED_)
#define AFX_MLR1_H__E7626B26_4BA9_4910_849A_151001216F5E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif
#include "pchar.h"
#define ADJUST 1
//-128 空输入
//-127 结束符$
//-126 小数点
//-125..-1 非终结符编号
//0 字符串结束标志
//1-127 终结符的ASCII码
#ifndef LENGTH
#define ID_LENGTH 20
#define LINE_LENGTH 128
#define MAX_IDENT 125
#define MAP_SIZE 16
#define LR_NULL -128
#define LR_EOF -127
#define LR_DOT -126
#define LR_EOS 0
#endif
class MLR1{
public:
CString GetFirst(int i);
CString GetFollow(int i);
public:
MLR1();
virtual ~MLR1();
void ReSet(FILE*);
const CStringArray& GetIdentList();
int GetExpressNum();
int GetIdentNum();
protected:
bool Lex1();
int Lex2();
int Lex2_1(char*&,bool isUse=false);
bool Lex3();
//词法、语法分析模块
void FirstSet1();
void FirstSet2(int,int,int);
bool FirstSet3(const char*,char*);
bool FirstSet4(const char,char*);
CString FirstSet5(const char*,bool has_null=false);
void FirstSet6();
//First集求解模块
CString FollowSet1(const char*,bool has_eof=false);
bool FollowSet2(const char*);
void FollowSet3();
bool FollowSet4(int,int,int);
//Follow集求解模块
void LR0_table1();
void LR0_table2(char*);
//构造LR0分析表模块
private:
CStringArray list_Ident;
CPtrArray list_Express;
//非终结符表和产生式表
CStringArray list_Seed0;
CStringArray list_Clouser0;
int* list_Index0;
//用token[LINE_LENGTH]作为临时索引表,完成后拷贝到list_Index0
//list_Clouser0中字符串的第一个字符指向种子表,LR0项目从第二个字符开始
struct s_first{
char Fi[MAP_SIZE];
char Fo[MAP_SIZE];
char flag;}
m_first[MAX_IDENT];
//b6:正在计算Fi0x40
//b5-b3:正在计算Fo0x20,Fo以求解0x10,包含LR_EOF0x08
//b2-b0:Fi已求解0x04,推出LR_NULL0x02,b1有效0x01
char token[2048];
int token_len;
//token不止用来缓冲输入串,还被各个功能模块用做工作区
//所以各功能模块不能同时进行
char bit_map[MAP_SIZE];
//如果说token被各模块用做位图的话
//bit_map则是一个小的位图
FILE* p_file;
};
inline const CStringArray& MLR1::GetIdentList(){
return list_Ident;}
inline int MLR1::GetExpressNum(){
return list_Express.GetSize();}
inline int MLR1::GetIdentNum(){
return list_Ident.GetSize();}
#endif
//First集以空推导检测为前提
//Follow集以First集为前提
========================
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by LR.rc
//
#define IDD_LR_DIALOG 102
#define IDR_MAINFRAME 128
#define IDR_MENU_MAIN 129
#define IDC_LIST_SHOW 1000
#define IDR_FILE_OPEN 32772
#define IDR_VIEW_IDENT 32773
#define IDR_VIEW_FIRST_SET 32774
#define IDR_VIEW_FOLLOW_SET 32775
#define IDR_MLR1_SIZE 32776
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32777
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
========================
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__923C3E27_880E_4A70_99F0_14A6BA1FB709__INCLUDED_)
#define AFX_STDAFX_H__923C3E27_880E_4A70_99F0_14A6BA1FB709__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__923C3E27_880E_4A70_99F0_14A6BA1FB709__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -