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

📄 label.cc

📁 早期freebsd实现
💻 CC
📖 第 1 页 / 共 3 页
字号:
#ifndef lintstatic char yysccsid[] = "@(#)yaccpar	1.8 (Berkeley) 01/20/90";#endif#define YYBYACC 1#line 22 "label.y"#include "refer.h"#include "refid.h"#include "ref.h"#include "token.h"int yylex();void yyerror(const char *);int yyparse();static const char *format_serial(char c, int n);struct label_info {  int start;  int length;  int count;  int total;  label_info(const string &);};label_info *lookup_label(const string &label);struct expression {  enum {    /* Does the tentative label depend on the reference?*/    CONTAINS_VARIABLE = 01,     CONTAINS_STAR = 02,    CONTAINS_FORMAT = 04,    CONTAINS_AT = 010  };  virtual ~expression() { }  virtual void evaluate(int, const reference &, string &,			substring_position &) = 0;  virtual unsigned analyze() { return 0; }};class at_expr : public expression {public:  at_expr() { }  void evaluate(int, const reference &, string &, substring_position &);  unsigned analyze() { return CONTAINS_VARIABLE|CONTAINS_AT; }};class format_expr : public expression {  char type;  int width;  int first_number;public:  format_expr(char c, int w = 0, int f = 1)    : type(c), width(w), first_number(f) { }  void evaluate(int, const reference &, string &, substring_position &);  unsigned analyze() { return CONTAINS_FORMAT; }};class field_expr : public expression {  int number;  char name;public:  field_expr(char nm, int num) : name(nm), number(num) { }  void evaluate(int, const reference &, string &, substring_position &);  unsigned analyze() { return CONTAINS_VARIABLE; }};class literal_expr : public expression {  string s;public:  literal_expr(const char *ptr, int len) : s(ptr, len) { }  void evaluate(int, const reference &, string &, substring_position &);};class unary_expr : public expression {protected:  expression *expr;public:  unary_expr(expression *e) : expr(e) { }  ~unary_expr() { delete expr; }  void evaluate(int, const reference &, string &, substring_position &) = 0;  unsigned analyze() { return expr ? expr->analyze() : 0; }};/* This caches the analysis of an expression.*/class analyzed_expr : public unary_expr {  unsigned flags;public:  analyzed_expr(expression *);  void evaluate(int, const reference &, string &, substring_position &);  unsigned analyze() { return flags; }};class star_expr : public unary_expr {public:  star_expr(expression *e) : unary_expr(e) { }  void evaluate(int, const reference &, string &, substring_position &);  unsigned analyze() {    return ((expr ? (expr->analyze() & ~CONTAINS_VARIABLE) : 0)	    | CONTAINS_STAR);  }};typedef void map_t(const char *, const char *, string &);class map_expr : public unary_expr {  map_t *func;public:  map_expr(expression *e, map_t *f) : unary_expr(e), func(f) { }  void evaluate(int, const reference &, string &, substring_position &);};  typedef const char *extractor_t(const char *, const char *, const char **);class extractor_expr : public unary_expr {  int part;  extractor_t *func;public:  enum { BEFORE = +1, MATCH = 0, AFTER = -1 };  extractor_expr(expression *e, extractor_t *f, int pt)    : unary_expr(e), func(f), part(pt) { }  void evaluate(int, const reference &, string &, substring_position &);};class truncate_expr : public unary_expr {  int n;public:  truncate_expr(expression *e, int i) : n(i), unary_expr(e) { }   void evaluate(int, const reference &, string &, substring_position &);};class separator_expr : public unary_expr {public:  separator_expr(expression *e) : unary_expr(e) { }  void evaluate(int, const reference &, string &, substring_position &);};class binary_expr : public expression {protected:  expression *expr1;  expression *expr2;public:  binary_expr(expression *e1, expression *e2) : expr1(e1), expr2(e2) { }  ~binary_expr() { delete expr1; delete expr2; }  void evaluate(int, const reference &, string &, substring_position &) = 0;  unsigned analyze() {    return (expr1 ? expr1->analyze() : 0) | (expr2 ? expr2->analyze() : 0);  }};class alternative_expr : public binary_expr {public:  alternative_expr(expression *e1, expression *e2) : binary_expr(e1, e2) { }  void evaluate(int, const reference &, string &, substring_position &);};class list_expr : public binary_expr {public:  list_expr(expression *e1, expression *e2) : binary_expr(e1, e2) { }  void evaluate(int, const reference &, string &, substring_position &);};class substitute_expr : public binary_expr {public:  substitute_expr(expression *e1, expression *e2) : binary_expr(e1, e2) { }  void evaluate(int, const reference &, string &, substring_position &);};class ternary_expr : public expression {protected:  expression *expr1;  expression *expr2;  expression *expr3;public:  ternary_expr(expression *e1, expression *e2, expression *e3)    : expr1(e1), expr2(e2), expr3(e3) { }  ~ternary_expr() { delete expr1; delete expr2; delete expr3; }  void evaluate(int, const reference &, string &, substring_position &) = 0;  unsigned analyze() {    return ((expr1 ? expr1->analyze() : 0)	    | (expr2 ? expr2->analyze() : 0)	    | (expr3 ? expr3->analyze() : 0));  }};class conditional_expr : public ternary_expr {public:  conditional_expr(expression *e1, expression *e2, expression *e3)    : ternary_expr(e1, e2, e3) { }  void evaluate(int, const reference &, string &, substring_position &);};static expression *parsed_label = 0;static expression *parsed_date_label = 0;static expression *parsed_short_label = 0;static expression *parse_result;string literals;#line 221 "label.y"typedef union {  int num;  expression *expr;  struct { int ndigits; int val; } dig;  struct { int start; int len; } str;} YYSTYPE;#line 211 "y.tab.c"#define TOKEN_LETTER 257#define TOKEN_LITERAL 258#define TOKEN_DIGIT 259#define YYERRCODE 256short yylhs[] = {                                        -1,    0,    1,    1,    6,    6,    2,    2,    2,    3,    3,    5,    5,    4,    4,    4,    4,    4,    4,    4,    4,    4,    4,    4,    4,    9,    9,    7,    7,    8,    8,   10,   10,   10,};short yylen[] = {                                         2,    1,    1,    5,    0,    1,    1,    3,    3,    1,    2,    1,    3,    1,    1,    1,    2,    2,    2,    5,    3,    3,    2,    3,    3,    0,    1,    1,    2,    1,    2,    0,    1,    1,};short yydefred[] = {                                      0,    0,   14,   13,    0,    0,    0,    0,    5,    0,    0,    0,    0,    1,   27,    0,   17,   29,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,   22,    0,   28,   30,   23,   24,    0,    0,    0,   32,   33,    0,    0,    0,    0,    0,    0,    3,    0,   19,};short yydgoto[] = {                                       7,    8,    9,   10,   11,   12,   13,   15,   18,   47,   39,};short yysindex[] = {                                    -32, -257,    0,    0, -240,  -32,  -32,    0,    0,  -18,  -32,  -36, -114,    0,    0, -246,    0,    0, -241,  -14,  -39,  -32,  -32,  -32, -114,  -21, -257, -257,    0,  -32,    0,    0,    0,    0,  -25,  -32,  -32,    0,    0, -223, -246, -246,  -36,  -32, -257,    0, -246,    0,};short yyrindex[] = {                                     35,    1,    0,    0,    0,   -5,   -4,    0,    0,   14,  208,  159,  224,    0,    0,   11,    0,    0,   40,    0,    0,    2,    0,    0,  253, -220,    0,    0,    0,    0,    0,    0,    0,    0,    0,  263,  281,    0,    0,    0,   50,  105,  214,    0,  115,    0,  149,    0,};short yygindex[] = {                                      0,   19,    0,    7,   37,  -10,   10,  -23,    0,    0,    0,};#define YYTABLESIZE 511short yytable[] = {                                      24,   15,   14,   40,   41,    4,   28,   26,    5,   27,   25,   16,   29,   30,    2,   19,   20,   16,   31,   17,   23,   46,   37,   33,   38,   24,   24,   32,    6,   35,   36,   34,    3,   43,   44,    4,    4,   31,   15,   15,   18,   15,   15,   15,   15,   21,   15,   15,   16,   16,   20,   16,   16,   16,   16,    2,   16,   16,    4,   15,    4,   15,   45,   15,   15,   15,   42,    0,    0,   16,    0,   16,    2,   16,   16,   16,    2,   18,   18,    0,   18,   18,   18,   18,    0,   18,   18,   20,   20,    0,   20,   20,   20,   20,    0,   20,   20,    0,   18,    0,   18,    0,   18,   18,   18,   21,   22,    0,   20,    0,   20,    0,   20,   20,   20,   25,    0,    0,    0,    0,    0,    0,    0,    0,    0,   15,    0,   15,    0,    0,    0,    0,    0,    0,    0,   16,    0,   16,    0,    0,    0,    0,   21,   21,    0,   21,   21,   21,   21,   26,   21,   21,   25,   25,    0,   25,   25,   25,   25,   11,   25,   25,    0,   21,   18,   21,   18,   21,   21,   21,    0,    0,    0,   25,   20,   25,   20,   25,   25,   25,    0,    0,    0,    0,    0,    0,   26,   26,    0,   26,   26,   26,   26,    0,   26,   26,   11,   11,    0,   11,   11,    0,    0,    0,    0,    0,    0,   26,    6,   26,    0,   26,   26,   26,   12,    0,    0,   11,    0,   11,    0,   11,   11,   11,    9,    1,    2,    0,    0,   21,    0,   21,    0,    0,    0,    0,    0,    0,    0,   25,    0,   25,    0,    0,    0,    0,    6,    0,    0,    6,    0,   12,   12,   10,   12,   12,    0,    0,   15,   15,    0,    9,    9,    7,    9,    9,    6,    0,   16,   16,    6,    6,   12,   26,   12,   26,   12,   12,   12,    0,    0,    8,    9,   11,    9,   11,    9,    9,    9,    0,   10,   10,    0,   10,   10,    0,    0,   18,   18,    0,    0,    7,    0,    0,    7,    0,    0,   20,   20,    0,    0,   10,    0,   10,    0,   10,   10,   10,    0,    8,    0,    7,    8,    0,    0,    7,    7,    0,    0,    0,    0,    0,    6,    0,    0,    0,    0,    0,   12,    8,   12,    0,    0,    8,    8,    0,    0,    0,    9,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,   21,   21,    0,    0,    0,    0,    0,    0,    0,    0,   25,   25,    0,    0,    0,   10,    0,    0,    0,    0,    0,    0,    0,    0,    0,    7,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    8,   26,   26,    0,    0,    0,    0,    0,    0,    0,    0,   11,   11,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,   12,   12,    0,    0,    0,    0,    0,    0,    0,    0,    9,    9,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,   10,   10,};short yycheck[] = {                                      10,    0,  259,   26,   27,   37,   42,   43,   40,   45,   46,    0,  126,  259,    0,    5,    6,  257,  259,  259,   38,   44,   43,   62,   45,   35,   36,   41,   60,   22,   23,   21,   64,   58,  257,    0,   41,  257,   37,   38,    0,   40,   41,   42,   43,   63,   45,   46,   37,   38,    0,   40,   41,   42,   43,   41,   45,   46,   62,   58,   58,   60,   43,   62,   63,   64,   29,   -1,   -1,   58,   -1,   60,   58,   62,   63,   64,   62,   37,   38,   -1,   40,   41,   42,   43,   -1,   45,   46,   37,   38,   -1,   40,   41,   42,   43,   -1,   45,   46,   -1,   58,   -1,   60,   -1,   62,   63,   64,    0,  124,   -1,   58,   -1,   60,   -1,   62,   63,   64,    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  124,   -1,  126,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  124,   -1,  126,   -1,   -1,   -1,   -1,   37,   38,   -1,   40,   41,   42,   43,    0,   45,   46,   37,   38,   -1,   40,   41,   42,   43,    0,   45,   46,   -1,   58,  124,   60,  126,   62,   63,   64,   -1,   -1,   -1,   58,  124,   60,  126,   62,   63,   64,   -1,   -1,   -1,   -1,   -1,   -1,   37,   38,   -1,   40,   41,   42,   43,   -1,   45,   46,   37,   38,   -1,   40,   41,   -1,   -1,   -1,   -1,   -1,   -1,   58,    0,   60,   -1,   62,   63,   64,    0,   -1,   -1,   58,   -1,   60,   -1,   62,   63,   64,    0,  257,  258,   -1,   -1,  124,   -1,  126,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  124,   -1,  126,   -1,   -1,   -1,   -1,   38,   -1,   -1,   41,   -1,   37,   38,    0,   40,   41,   -1,   -1,  257,  258,   -1,   37,   38,    0,   40,   41,   58,   -1,  257,  258,   62,   63,   58,  124,   60,  126,   62,   63,   64,   -1,   -1,    0,   58,  124,   60,  126,   62,   63,   64,   -1,   37,   38,   -1,   40,   41,   -1,   -1,  257,  258,   -1,   -1,   38,   -1,   -1,   41,   -1,   -1,  257,  258,   -1,   -1,   58,   -1,   60,   -1,   62,   63,   64,   -1,   38,   -1,   58,   41,   -1,   -1,   62,   63,   -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,   -1,   -1,   -1,  124,   58,  126,   -1,   -1,   62,   63,   -1,   -1,   -1,  124,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  257,  258,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  257,  258,   -1,   -1,   -1,  124,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  124,  257,  258,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  257,  258,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  257,  258,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  257,  258,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  257,  258,};#define YYFINAL 7#ifndef YYDEBUG#define YYDEBUG 0#endif#define YYMAXTOKEN 259#if YYDEBUGchar *yyname[] = {"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'","'.'",0,0,0,0,0,0,0,0,0,0,0,"':'",0,"'<'",0,"'>'","'?'","'@'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,"'~'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"TOKEN_LETTER","TOKEN_LITERAL","TOKEN_DIGIT",};char *yyrule[] = {"$accept : expr","expr : optional_conditional","conditional : alternative","conditional : alternative '?' optional_conditional ':' conditional","optional_conditional :","optional_conditional : conditional","alternative : list","alternative : alternative '|' list","alternative : alternative '&' list","list : substitute","list : list substitute","substitute : string","substitute : substitute '~' string","string : '@'","string : TOKEN_LITERAL","string : TOKEN_LETTER","string : TOKEN_LETTER number","string : '%' TOKEN_LETTER","string : '%' digits","string : string '.' flag TOKEN_LETTER optional_number","string : string '+' number","string : string '-' number","string : string '*'","string : '(' optional_conditional ')'","string : '<' optional_conditional '>'","optional_number :","optional_number : number","number : TOKEN_DIGIT","number : number TOKEN_DIGIT","digits : TOKEN_DIGIT","digits : digits TOKEN_DIGIT","flag :","flag : '+'","flag : '-'",};#endif#define yyclearin (yychar=(-1))#define yyerrok (yyerrflag=0)#ifdef YYSTACKSIZE#ifndef YYMAXDEPTH#define YYMAXDEPTH YYSTACKSIZE#endif#else#ifdef YYMAXDEPTH#define YYSTACKSIZE YYMAXDEPTH#else#define YYSTACKSIZE 500#define YYMAXDEPTH 500#endif#endifint yydebug;int yynerrs;int yyerrflag;int yychar;short *yyssp;YYSTYPE *yyvsp;YYSTYPE yyval;YYSTYPE yylval;short yyss[YYSTACKSIZE];YYSTYPE yyvs[YYSTACKSIZE];#define yystacksize YYSTACKSIZE#line 397 "label.y"/* bison defines const to be empty unless __STDC__ is defined, which itisn't under cfront */#ifdef const#undef const#endifconst char *spec_ptr;const char *spec_end;const char *spec_cur;int yylex(){  while (spec_ptr < spec_end && csspace(*spec_ptr))    spec_ptr++;  spec_cur = spec_ptr;  if (spec_ptr >= spec_end)    return 0;  unsigned char c = *spec_ptr++;  if (csalpha(c)) {    yylval.num = c;    return TOKEN_LETTER;  }  if (csdigit(c)) {    yylval.num = c - '0';    return TOKEN_DIGIT;  }  if (c == '\'') {    yylval.str.start = literals.length();    for (; spec_ptr < spec_end; spec_ptr++) {      if (*spec_ptr == '\'') {	if (++spec_ptr < spec_end && *spec_ptr == '\'')	  literals += '\'';	else {	  yylval.str.len = literals.length() - yylval.str.start;	  return TOKEN_LITERAL;	}      }      else	literals += *spec_ptr;    }    yylval.str.len = literals.length() - yylval.str.start;    return TOKEN_LITERAL;  }  return c;}int set_label_spec(const char *label_spec){  spec_cur = spec_ptr = label_spec;  spec_end = strchr(label_spec, '\0');  literals.clear();  if (yyparse())    return 0;  delete parsed_label;  parsed_label = parse_result;  return 1;}int set_date_label_spec(const char *label_spec){  spec_cur = spec_ptr = label_spec;  spec_end = strchr(label_spec, '\0');  literals.clear();  if (yyparse())    return 0;  delete parsed_date_label;  parsed_date_label = parse_result;  return 1;}int set_short_label_spec(const char *label_spec){  spec_cur = spec_ptr = label_spec;  spec_end = strchr(label_spec, '\0');  literals.clear();  if (yyparse())    return 0;  delete parsed_short_label;  parsed_short_label = parse_result;  return 1;}void yyerror(const char *message){  if (spec_cur < spec_end)    command_error("label specification %1 before `%2'", message, spec_cur);  else    command_error("label specification %1 at end of string",		  message, spec_cur);

⌨️ 快捷键说明

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