1424 lines · 49.1 KB · C
RawDownload
/* A recursive-descent parser generated by peg 0.1.15 */ #define YYRULECOUNT 38 #include <u.h>#include <libc.h>#include <stdio.h>#include "tree.h"#include "version.h"   typedef struct Header Header;   struct Header {    char   *text;    Header *next;  };   FILE *input= 0;   int   verboseFlag= 0;   static int	 lineNumber= 0;  static char	*fileName= 0;  static char	*trailer= 0;  static Header	*headers= 0;   void makeHeader(char *text);  void makeTrailer(char *text);   void yyerror(char *message); # define YY_INPUT(buf, result, max)		\  {						\    int c= getc(input);				\    if ('\n' == c || '\r' == c) ++lineNumber;	\    result= (EOF == c) ? 0 : (*(buf)= c, 1);	\  } # define YY_LOCAL(T)	static T# define YY_RULE(T)	static T #ifndef YY_MALLOC#define YY_MALLOC(C, N)		malloc(N)#endif#ifndef YY_REALLOC#define YY_REALLOC(C, P, N)	realloc(P, N)#endif#ifndef YY_FREE#define YY_FREE(C, P)		free(P)#endif#ifndef YY_LOCAL#define YY_LOCAL(T)	static T#endif#ifndef YY_ACTION#define YY_ACTION(T)	static T#endif#ifndef YY_RULE#define YY_RULE(T)	static T#endif#ifndef YY_PARSE#define YY_PARSE(T)	T#endif#ifndef YYPARSE#define YYPARSE		yyparse#endif#ifndef YYPARSEFROM#define YYPARSEFROM	yyparsefrom#endif#ifndef YYRELEASE#define YYRELEASE	yyrelease#endif#ifndef YY_BEGIN#define YY_BEGIN	( yy->__begin= yy->__pos, 1)#endif#ifndef YY_END#define YY_END		( yy->__end= yy->__pos, 1)#endif#ifdef YY_DEBUG# define yyprintf(args)	fprintf args#else# define yyprintf(args)#endif#ifndef YYSTYPE#define YYSTYPE	int#endif#ifndef YY_STACK_SIZE#define YY_STACK_SIZE 128#endif #ifndef YY_BUFFER_SIZE#define YY_BUFFER_SIZE 1024#endif #ifndef YY_PART typedef struct _yycontext yycontext;typedef void (*yyaction)(yycontext *yy, char *yytext, int yyleng);typedef struct _yythunk { int begin, end;  yyaction  action;  struct _yythunk *next; } yythunk; struct _yycontext {  char     *__buf;  int       __buflen;  int       __pos;  int       __limit;  char     *__text;  int       __textlen;  int       __begin;  int       __end;  int       __textmax;  yythunk  *__thunks;  int       __thunkslen;  int       __thunkpos;  YYSTYPE   __;  YYSTYPE  *__val;  YYSTYPE  *__vals;  int       __valslen;#ifdef YY_CTX_MEMBERS  YY_CTX_MEMBERS#endif}; #ifdef YY_CTX_LOCAL#define YY_CTX_PARAM_	yycontext *yyctx,#define YY_CTX_PARAM	yycontext *yyctx#define YY_CTX_ARG_	yyctx,#define YY_CTX_ARG	yyctx#ifndef YY_INPUT#define YY_INPUT(yy, buf, result, max_size)		\  {							\    int yyc= getchar();					\    result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1);	\    yyprintf((stderr, "<%c>", yyc));			\  }#endif#else#define YY_CTX_PARAM_#define YY_CTX_PARAM	void#define YY_CTX_ARG_#define YY_CTX_ARGyycontext _yyctx= { 0, 0 };yycontext *yyctx= &_yyctx;#ifndef YY_INPUT#define YY_INPUT(buf, result, max_size)			\  {							\    int yyc= getchar();					\    result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1);	\    yyprintf((stderr, "<%c>", yyc));			\  }#endif#endif YY_LOCAL(int) yyrefill(yycontext *yy){  int yyn;  while (yy->__buflen - yy->__pos < 512)    {      yy->__buflen *= 2;      yy->__buf= (char *)YY_REALLOC(yy, yy->__buf, yy->__buflen);    }#ifdef YY_CTX_LOCAL  YY_INPUT(yy, (yy->__buf + yy->__pos), yyn, (yy->__buflen - yy->__pos));#else  YY_INPUT((yy->__buf + yy->__pos), yyn, (yy->__buflen - yy->__pos));#endif  if (!yyn) return 0;  yy->__limit += yyn;  return 1;} YY_LOCAL(int) yymatchDot(yycontext *yy){  if (yy->__pos >= yy->__limit && !yyrefill(yy)) return 0;  ++yy->__pos;  return 1;} YY_LOCAL(int) yymatchChar(yycontext *yy, int c){  if (yy->__pos >= yy->__limit && !yyrefill(yy)) return 0;  if ((unsigned char)yy->__buf[yy->__pos] == c)    {      ++yy->__pos;      yyprintf((stderr, "  ok   yymatchChar(yy, %c) @ %s\n", c, yy->__buf+yy->__pos));      return 1;    }  yyprintf((stderr, "  fail yymatchChar(yy, %c) @ %s\n", c, yy->__buf+yy->__pos));  return 0;} YY_LOCAL(int) yymatchString(yycontext *yy, const char *s){  int yysav= yy->__pos;  while (*s)    {      if (yy->__pos >= yy->__limit && !yyrefill(yy)) return 0;      if (yy->__buf[yy->__pos] != *s)        {          yy->__pos= yysav;          return 0;        }      ++s;      ++yy->__pos;    }  return 1;} YY_LOCAL(int) yymatchClass(yycontext *yy, unsigned char *bits){  int c;  if (yy->__pos >= yy->__limit && !yyrefill(yy)) return 0;  c= (unsigned char)yy->__buf[yy->__pos];  if (bits[c >> 3] & (1 << (c & 7)))    {      ++yy->__pos;      yyprintf((stderr, "  ok   yymatchClass @ %s\n", yy->__buf+yy->__pos));      return 1;    }  yyprintf((stderr, "  fail yymatchClass @ %s\n", yy->__buf+yy->__pos));  return 0;} YY_LOCAL(void) yyDo(yycontext *yy, yyaction action, int begin, int end){  while (yy->__thunkpos >= yy->__thunkslen)    {      yy->__thunkslen *= 2;      yy->__thunks= (yythunk *)YY_REALLOC(yy, yy->__thunks, sizeof(yythunk) * yy->__thunkslen);    }  yy->__thunks[yy->__thunkpos].begin=  begin;  yy->__thunks[yy->__thunkpos].end=    end;  yy->__thunks[yy->__thunkpos].action= action;  ++yy->__thunkpos;} YY_LOCAL(int) yyText(yycontext *yy, int begin, int end){  int yyleng= end - begin;  if (yyleng <= 0)    yyleng= 0;  else    {      while (yy->__textlen < (yyleng + 1))	{	  yy->__textlen *= 2;	  yy->__text= (char *)YY_REALLOC(yy, yy->__text, yy->__textlen);	}      memcpy(yy->__text, yy->__buf + begin, yyleng);    }  yy->__text[yyleng]= '\0';  return yyleng;} YY_LOCAL(void) yyDone(yycontext *yy){  int pos;  for (pos= 0;  pos < yy->__thunkpos;  ++pos)    {      yythunk *thunk= &yy->__thunks[pos];      int yyleng= thunk->end ? yyText(yy, thunk->begin, thunk->end) : thunk->begin;      yyprintf((stderr, "DO [%d] %p %s\n", pos, thunk->action, yy->__text));      thunk->action(yy, yy->__text, yyleng);    }  yy->__thunkpos= 0;} YY_LOCAL(void) yyCommit(yycontext *yy){  if ((yy->__limit -= yy->__pos))    {      memmove(yy->__buf, yy->__buf + yy->__pos, yy->__limit);    }  yy->__begin -= yy->__pos;  yy->__end -= yy->__pos;  yy->__pos= yy->__thunkpos= 0;} YY_LOCAL(int) yyAccept(yycontext *yy, int tp0){  if (tp0)    {      fprintf(stderr, "accept denied at %d\n", tp0);      return 0;    }  else    {      yyDone(yy);      yyCommit(yy);    }  return 1;} YY_LOCAL(void) yyPush(yycontext *yy, char *text, int count){  yy->__val += count;  while (yy->__valslen <= yy->__val - yy->__vals)    {      long offset= yy->__val - yy->__vals;      yy->__valslen *= 2;      yy->__vals= (YYSTYPE *)YY_REALLOC(yy, yy->__vals, sizeof(YYSTYPE) * yy->__valslen);      yy->__val= yy->__vals + offset;    }}YY_LOCAL(void) yyPop(yycontext *yy, char *text, int count)   { yy->__val -= count; }YY_LOCAL(void) yySet(yycontext *yy, char *text, int count)   { yy->__val[count]= yy->__; } #endif /* YY_PART */ #define	YYACCEPT	yyAccept(yy, yythunkpos0) YY_RULE(int) yy_end_of_line(yycontext *yy); /* 38 */YY_RULE(int) yy_comment(yycontext *yy); /* 37 */YY_RULE(int) yy_space(yycontext *yy); /* 36 */YY_RULE(int) yy_braces(yycontext *yy); /* 35 */YY_RULE(int) yy_range(yycontext *yy); /* 34 */YY_RULE(int) yy_char(yycontext *yy); /* 33 */YY_RULE(int) yy_END(yycontext *yy); /* 32 */YY_RULE(int) yy_BEGIN(yycontext *yy); /* 31 */YY_RULE(int) yy_DOT(yycontext *yy); /* 30 */YY_RULE(int) yy_class(yycontext *yy); /* 29 */YY_RULE(int) yy_literal(yycontext *yy); /* 28 */YY_RULE(int) yy_CLOSE(yycontext *yy); /* 27 */YY_RULE(int) yy_OPEN(yycontext *yy); /* 26 */YY_RULE(int) yy_COLON(yycontext *yy); /* 25 */YY_RULE(int) yy_PLUS(yycontext *yy); /* 24 */YY_RULE(int) yy_STAR(yycontext *yy); /* 23 */YY_RULE(int) yy_QUESTION(yycontext *yy); /* 22 */YY_RULE(int) yy_primary(yycontext *yy); /* 21 */YY_RULE(int) yy_NOT(yycontext *yy); /* 20 */YY_RULE(int) yy_suffix(yycontext *yy); /* 19 */YY_RULE(int) yy_AND(yycontext *yy); /* 18 */YY_RULE(int) yy_action(yycontext *yy); /* 17 */YY_RULE(int) yy_TILDE(yycontext *yy); /* 16 */YY_RULE(int) yy_prefix(yycontext *yy); /* 15 */YY_RULE(int) yy_error(yycontext *yy); /* 14 */YY_RULE(int) yy_BAR(yycontext *yy); /* 13 */YY_RULE(int) yy_sequence(yycontext *yy); /* 12 */YY_RULE(int) yy_SEMICOLON(yycontext *yy); /* 11 */YY_RULE(int) yy_expression(yycontext *yy); /* 10 */YY_RULE(int) yy_EQUAL(yycontext *yy); /* 9 */YY_RULE(int) yy_identifier(yycontext *yy); /* 8 */YY_RULE(int) yy_RPERCENT(yycontext *yy); /* 7 */YY_RULE(int) yy_end_of_file(yycontext *yy); /* 6 */YY_RULE(int) yy_trailer(yycontext *yy); /* 5 */YY_RULE(int) yy_definition(yycontext *yy); /* 4 */YY_RULE(int) yy_declaration(yycontext *yy); /* 3 */YY_RULE(int) yy__(yycontext *yy); /* 2 */YY_RULE(int) yy_grammar(yycontext *yy); /* 1 */ YY_ACTION(void) yy_9_primary(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_9_primary\n"));  {   push(makePredicate("YY_END")); ;  }#undef __#undef yythunkpos#undef yypos#undef yy}YY_ACTION(void) yy_8_primary(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_8_primary\n"));  {   push(makePredicate("YY_BEGIN")); ;  }#undef __#undef yythunkpos#undef yypos#undef yy}YY_ACTION(void) yy_7_primary(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_7_primary\n"));  {   push(makeAction(yytext)); ;  }#undef __#undef yythunkpos#undef yypos#undef yy}YY_ACTION(void) yy_6_primary(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_6_primary\n"));  {   push(makeDot()); ;  }#undef __#undef yythunkpos#undef yypos#undef yy}YY_ACTION(void) yy_5_primary(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_5_primary\n"));  {   push(makeClass(yytext)); ;  }#undef __#undef yythunkpos#undef yypos#undef yy}YY_ACTION(void) yy_4_primary(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_4_primary\n"));  {   push(makeString(yytext)); ;  }#undef __#undef yythunkpos#undef yypos#undef yy}YY_ACTION(void) yy_3_primary(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_3_primary\n"));  {   push(makeName(findRule(yytext))); ;  }#undef __#undef yythunkpos#undef yypos#undef yy}YY_ACTION(void) yy_2_primary(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_2_primary\n"));  {   Node *name= makeName(findRule(yytext));  name->name.variable= pop();  push(name); ;  }#undef __#undef yythunkpos#undef yypos#undef yy}YY_ACTION(void) yy_1_primary(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_1_primary\n"));  {   push(makeVariable(yytext)); ;  }#undef __#undef yythunkpos#undef yypos#undef yy}YY_ACTION(void) yy_3_suffix(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_3_suffix\n"));  {   push(makePlus (pop())); ;  }#undef __#undef yythunkpos#undef yypos#undef yy}YY_ACTION(void) yy_2_suffix(yycontext *yy, char *yytext, int yyleng){#define __ yy->__#define yypos yy->__pos#define yythunkpos yy->__thunkpos  yyprintf((stderr, "do yy_2_suffix\n"));  {   push(makeStar (pop())); ;  }#undef __#undef yythunkpos#undef yypos

Lines 1–500 of 1424.