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

📄 ch19par.h

📁 稀疏矩阵、链表、图、队列、二叉树、多叉树、排序、遗传算法等的实现
💻 H
📖 第 1 页 / 共 2 页
字号:
    /* keeping, and point to the parent parse node, and the next node*/
    /* at this level in the parse tree.                              */
    struct sParseNode*  ParentParse;
    struct sParseNode*  NextParse;
    struct sParseNode*  PreviousParse;
    /* If this node has a daughter (or set of daughter) node(s) then */
    /* point to the first of these. If this pointer is NULL then no  */
    /* daughter exists for this node - it is a leaf of the parse tree*/
    struct sParseNode*   ThisParse;
    /* This parse head also corresponds to one particular syntax     */
    /* body item within a syntax head - point to these:              */
    struct sSyntaxHead*  ThisHead;
    struct sSyntaxBody*  ThisBody;
    /* If the matching syntax item indicates a code generate, then   */
    /* point to that routine:                                        */
    int (*CodeGenerate) ( void* );
    /* This parse node has a start and end character - indexes within*/
    /* the input (parse) buffer:                                     */
    int iFirstChar;
    int iLastChar;
};



/*
*  Table of Syntax names, and pointers to their tree items. This table
*  is NOT normalized, in that there is duplication here of some informa-
*  tion that is also in the tree element itself. This is for speedier
*  access, and is not (in theory) required.
*/
struct sSyntaxTableElement {
    char SyntaxName[SYNTAX_NAME_LENGTH+1];
    struct sSyntaxHead* pSyntaxPointer;
    int iStartsWith;
    int iMustContain;
};

/*
*  Any given alternate has a number, and a possible "starts with" and
*  a possible "must contain". If these are zero, then they are not set.
*/
struct sAlternateTableElement {
    struct sSyntaxAlt* pAlternatePointer;
    int iSyntaxNumber;
    int iStartsWith;
    int iMustContain;
};

/*
*  The following table matches character strings against routine
*  names. It is used at run time to determine which of the parser
*  code generation (etc.) routines should be called according to
*  the specified syntax. Every routine returns an int, and takes
*  as parameter two int pointers.
*/
struct sRoutineNameTableElement {
    char sNameBody[ROUTINE_NAME_LENGTH+1];
    int (*BodyRoutine) ( void* );
};

/* ------------------------- GLOBAL VARIABLES ----------------------- */
/*
*  GLOBAL VARIABLES:
*  There is a lot of argument as to whether global variables are
*  ever justified. All of the following variables are used throughout
*  the parser and code generator, and are declared here as global.
*  one alternative would be to declare them as subordinate to a
*  private structure, and to pass the address of that structure to
*  every routine as an additional parameter. IMHO the manner of writing
*  used here is clearer.
*/

static int iNextSyntax;
static int iNextAlternate;
/*
*  The files which contains the syntax definitions, the expressions
*  to be parsed, and the file to contain the output:
*/
static FILE * fSyntaxFile;
/*static char sSyntaxFileName[FILENAME_MAX+1];*/
static FILE * fInputFile;
/*static char sInputFileName[FILENAME_MAX+1];*/
static FILE * fOutputFile;
/*static char sOutputFileName[FILENAME_MAX+1];*/


/* ----------------------- END GLOBAL VARIABLES --------------------- */

/* ------ Prototypes -------------------------------------------------*/

/*
*  The prototypes for the functions:
*/

int ReadSyntax        ( struct sSyntaxTableElement* SyntaxTable,
                        struct sAlternateTableElement* AlternateTable,
                        struct sRoutineNameTableElement* RoutineNameTable,
                        char* SyntaxLine,
                        struct sSyntaxHead** pRoot,
                        char* sSyntaxFileName );
int FindSyntaxName    ( struct sSyntaxTableElement* SyntaxTable,
                        char*  SyntaxName );
int ProcessSyntaxLine ( struct sSyntaxTableElement* SyntaxTable,
                        struct sAlternateTableElement* AlternateTable,
                        struct sRoutineNameTableElement* RoutineNameTable,
                        char* SyntaxLine,
                        struct sSyntaxHead* pRootSyntax );
void FreeWholeSyntax  ( struct sSyntaxTableElement* SyntaxTable );
int GetNewSyntaxHead  ( struct sSyntaxTableElement* SyntaxTable,
                        struct sRoutineNameTableElement* RoutineNameTable,
                        struct sSyntaxHead** ppNewSyntaxHead,
                        char*  Identifier );
int CreateSyntaxTableEntry (struct sSyntaxTableElement* SyntaxTable,
                        char* pSyntaxName);
void FreeSyntaxHead   ( struct sSyntaxHead*  pFreeHead );
int GetAlternates     ( struct sSyntaxTableElement* SyntaxTable,
                        struct sAlternateTableElement* AlternateTable,
                        struct sRoutineNameTableElement* RoutineNameTable,
                        char* SyntaxLine,
                        int*   j,
                        struct sSyntaxHead*  pNewSyntaxHead );
int GetOneAlternate   ( struct sSyntaxTableElement* SyntaxTable,
                        struct sRoutineNameTableElement* RoutineNameTable,
                        char* SyntaxLine,
                        int*   j,
                        struct sSyntaxAlt*   pNewAlternate );
void FreeAlternates   ( struct sSyntaxAlt**  pFreeAlt );
int GetSyntaxItem     ( struct sSyntaxTableElement* SyntaxTable,
                        struct sRoutineNameTableElement* RoutineNameTable,
                        char* SyntaxLine,
                        int*   j,
                        struct sSyntaxBody*  pNewBody );
void FreeSyntaxItem   ( struct sSyntaxBody** pFreeBody );
void SkipSpaces       ( char*  SyntaxLine,
                        int*   j );
int GetSyntaxName     ( struct sSyntaxTableElement* SyntaxTable,
                        char*  SyntaxLine,
                        int*   j );
void RemoveSpaces     ( char*  InputBuffer );
int TryMatchParse     ( char** ppInputBuffer,
                        int*   k,
                        struct sSyntaxBody*  pSyntaxP,
                        struct sParseNode**  ppParseBody );
int GetNewParseBody (   struct sParseNode*   pParentHead,
                        struct sParseNode*   pPreviousBody,
                        struct sParseNode**  ppNewBody );
int BuildNewParseBody ( struct sParseNode*   pParentHead,
                        struct sParseNode*   pPreviousBody,
                        struct sParseNode**  ppNewBody,
                        int    iFirstChar,
                        int    iLastChar );
int Parse             ( char** ppInputBuffer,
                        int*   k,
                        struct sSyntaxHead*  pRootS,
                        struct sParseNode**  ppRootP );
int GenerateOutputCode( struct sParseNode*   pRootP );
int GetNextSyntax     ( struct sSyntaxBody**  ppSyntaxP );
int SkipNextSyntax    ( struct sSyntaxBody**  ppSyntaxP );
#if 0
  struct sSyntaxBody* NextParseItem (struct sParseNode* pRootP );
#endif
void PrintSyntaxTree  ( struct sSyntaxTableElement* SyntaxTable,
                        struct sAlternateTableElement* AlternateTable,
                        struct sSyntaxHead* pRootSyntax );
int isidchar          ( char   testchar );
int GetIdentifier     ( char*  InputBuffer,
                        char*  Identifier,
                        int*   j );
int GetLexName        ( struct sSyntaxTableElement* SyntaxTable,
                        char*  SyntaxLine,
                        char*  Identifier,
                        int*   j,
                        int    k );
int ProcessOutputNode ( struct sParseNode** ppParseHead,
                        struct sParseNode** ppParseBody );
int GetRoutinePointer ( struct sRoutineNameTableElement* RoutineNameTable,
                        char*  pszRoutineName,
                        int    (**FoundRoutine) (void*) );
int parletter         ( void* );
int pardigit          ( void* );
int paroctal          ( void* );
int parchar           ( void* );
int gencomparison     ( char* pszComparator );
int testgen           ( void* );
int genlt             ( void* );
int genle             ( void* );
int gengt             ( void* );
int genge             ( void* );
int geneq             ( void* );
int genne             ( void* );
int genAND            ( void* );
int genOR             ( void* );
int genXOR            ( void* );
int genLAND           ( void* );
int genLOR            ( void* );
int genoperate        ( char*  pszOperator );
int genadd            ( void* );
int gensubtract       ( void* );
int genmutiply        ( void* );
int gendivide         ( void* );
int genmodulus        ( void* );
void SetupRoutineNames ( struct sRoutineNameTableElement* RoutineNameTable );

#endif  /* end of double copy protection, Ch19_parser2_h */

/* End of parser prototypes. */

/*
*  Copyright (C) 2000  Ian D. K. Kelly,
*                      idkk Consultancy Ltd.
*                      Macmillan Computer Publishing
*  GNU General Public Licence: see copyright reference information
*  at the start of this file.
*/

⌨️ 快捷键说明

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