📄 metre.h
字号:
/************************************************************* Copyright (c) 1993-1995 by Paul Long All rights reserved.**************************************************************//************************************************************* metre.h - This header file contains #defines, typedefs, and externs that are used by the rules code to interface with the parser.**************************************************************/#ifndef METRE_H_#define METRE_H_#include <stdio.h>/* Define TRUE and FALSE if environment doesn't. */#ifndef TRUE#define TRUE (0==0)#define FALSE (!TRUE)#endiftypedef int BOOLEAN;/* Number of dimensions in array. E.g., the following prints 10: int a[10]; printf("%d\n", DIM_OF(a));*/#define DIM_OF(x) (sizeof (x) / sizeof (x[0]))/* If you want to support the MS-DOS convention of a slash introduction character, define OPT_INTRO_CHARS to be "-/". This way, both characters are recognized. Slash can be a problem because UNIX-style file paths can start with a slash, making it difficult for Metre to decide whether the command-line argument is the name of a file to process or a command-line option, as in /tmp/file.i.*/#define OPT_INTRO_CHARS "-" /* Command-line option-introduction characters. *//* Offset into command-line argument where option character starts. E.g., for -Xabc=def, it would refer past "-" to the "X" part.*/#define OPTION_START 1/* Offset into command-line argument where option string would start. E.g., for -Xabc=def, it would refer past "-X" to the "abc=def" part.*/#define OPTION_STRING_START 2/* Project information. A project consists of one or more modules (source files).*/typedef struct { BOOLEAN begin; /* Set to whether beginning of the project. */ BOOLEAN end; /* Set to whether end of the project. */ BOOLEAN need_cmd_name; /* Name of command is needed. Call cmd_name() with name, e.g., cmd_name("MYTOOL"). */ BOOLEAN help; /* Set to whether help has been requested. */} PRJ;/* Module information. In Metre, a module is currently the same thing as a source file.*/typedef struct { BOOLEAN begin; /* Set to whether beginning of a source module has been encountered. */ BOOLEAN end; /* Set to whether end of a source module (a file and all of its included files) has been reached. */ struct { unsigned total; /* Set to the total number of lines in a module. */ unsigned com; /* Set to the number of comment lines in a module. */ unsigned white; /* Set to the number of whitespace lines in a module. */ unsigned code; /* Set to the number of code lines in a module, not including comment-only and white-space lines. */ } lines; unsigned pp; /* Set to the total number of preprocessor statements in a module. */ unsigned decl; /* Set to the total number of declaration statements in a module. */ unsigned decisions; /* Set to the number of decision points in a module. */ unsigned conditions; /* Set to the number of conditions in a module. */ unsigned functions; /* Set to the number of functions defined in a module. */} MOD;/* Function information. */typedef struct { BOOLEAN begin; /* Set to whether beginning of a function has been found. */ BOOLEAN end; /* Set to whether end of a function has been found. */ struct { unsigned total; /* Set to the total number of lines in a function. */ unsigned com; /* Set to the number of comment lines in a function. */ unsigned white; /* Set to the number of whitespace lines in a function. */ unsigned code; /* Set to the number of code lines in a function, not including comment-only and white-space lines. */ } lines; unsigned decl; /* Set to the number of declaration statements found in the definition of a C function. */ unsigned high; /* Set to the number of high-level statements found in the definition of a C function. */ unsigned low; /* Set to the number of low-level statements found in the definition of a C function. */ unsigned decisions; /* Set to the number of decision points in a function. */ unsigned conditions; /* Set to the number of conditions in a function. */} FCN;/* Statement information. */typedef struct { /* Set to whether this is immediately before or after the declarations within a compound statement. */ BOOLEAN before_compound_declarations, after_compound_declarations; /* Set to whether this is immediately before or after an initializer. */ BOOLEAN before_initializer, after_initializer; BOOLEAN end; /* Set to whether end of a statement has been found. */ unsigned depth; /* Set to the logical depth of a statement, i.e., its nesting level within if-, for-, while-, and do-statements. */ BOOLEAN is_decl; /* Set to whether is a declaration statement. */ BOOLEAN is_comp; /* Set to whether is a compound statement. */ BOOLEAN is_expr; /* Set to whether is an expression statement. */ BOOLEAN is_empty_expr; /* Set to whether is an empty expression statement, i.e., ";". */ BOOLEAN is_high; /* Set to whether is a compound, selection, or iteration statement. */ BOOLEAN is_iter; /* Set to whether is an iteration statement. */ BOOLEAN is_jump; /* Set to whether is a jump statement. */ BOOLEAN is_label; /* Set to whether is a labeled statement. */ BOOLEAN is_low; /* Set to whether is an expression or jump statement. */ BOOLEAN is_select; /* Set to whether is a selection statement. */} STM;/* Line information. */typedef struct { unsigned number; /* Set to the number of the current line, relative to the start of the current file. */ BOOLEAN end; /* Set to whether a newline character has been found. */ BOOLEAN is_comment; /* Set to whether line has no C code and either contains a comment or is contained within a comment. The comment must contain text to qualify as a real comment. */ BOOLEAN is_white; /* Set to whether line consists entirely of whitespace tabs & spaces), or is a comment line without any text. */ BOOLEAN is_code; /* Set to whether line contains code and not exclusively comments or white space. */ unsigned statements; /* Set to the number of statements on the current line. */ BOOLEAN is_mixed_indent; /* Set to whether line is indented with both space and tab characters. */} LIN;/* Grammatical information. */typedef struct { /* Set to whether the parser has found a type name, identifier, keyword, constant, string literal, or operator, e.g., BOOLEAN, apples, else, 23, "hello", and +, respectively. */ BOOLEAN is_type_name; BOOLEAN is_identifier; BOOLEAN is_declarator; BOOLEAN is_keyword; BOOLEAN is_constant; BOOLEAN is_string; BOOLEAN is_operator; BOOLEAN is_call;} GRM;/* Lexical information. */typedef struct { /* Whenever a character is found that is not in the standard C set, the value of this variable is set to the integer representation of the nonstandard character. */ int nonstandard;} LEX;/* Extern declarations for the structs through which the parser provides information to the rules.*/extern PRJ prj;extern MOD mod;extern FCN fcn;extern STM stm;extern LIN lin;extern GRM grm;extern LEX lex;/* A rule may specify the name of the command that invokes the program by calling this function with the name of the command when prj.cmd_name is true, as in if (prj.need_cmd_name) cmd_name("MYTOOL");*/extern void cmd_name(char *);/* FILE pointer to where any output should be directed by the rules. */extern FILE *out_fp;/* Returns pointer to current function name. */extern char *fcn_name(void);/* Returns pointer to current module (file) name. */extern char *mod_name(void);/* Returns pointer to current source line. */extern char *line(void);/* Returns current line number. */extern unsigned lineno(void);/* Returns pointer to string that "points" to the parser's current location in source. E.g., - Useful in error messages. The parser uses this function for syntax errors, but it could also be used by a rule.*/extern char *marker(void);/* Returns pointer to current token (lexeme, actually) in the source. */extern char *token(void);/* Return pointer to identifier that corresponds to when grammar identifier trigger is fired.*/extern char *this_identifier(void);/* Returns pointer to last-encountered identifier and declarator. */extern char *last_identifier(void);extern char *last_declarator(void);/* Returns TRUE when the indicated operator, keyword, type name, or identifier, e.g., "++", "while", "BOOLEAN", or "myBuffer", respectively, is encountered. Can be used as a trigger in a rule.*/extern BOOLEAN keyword(char *);extern BOOLEAN oper(char *);extern BOOLEAN identifier(char *);extern BOOLEAN type_name(char *);/* Returns pointer to the part of an option following the "=". E.g., for -Xabc=def, it would point to the "def" part.*/extern char *str_option(int);/* Returns TRUE if the indicated option character was specified on the command line. E.g., for -S, would return TRUE for option('S').*/extern int option(int);/* Return pointer to command-line-argument array. */extern char **argv(void);/* Return command-line argument count. */extern int argc(void);/* Used by rules to indicate a fatal error or warning. Expects a fatal-error or warning number that the programmer can make up, followed by a format string and other arguments, just like printf(). E.g., warn(0, "goto statement used (%u time%s)", fcn_gotos, NUMBER(fcn_gotos));*/extern void fatal(int, char *, ...);extern void warn(int, char *, ...);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -