e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */
1b10db2002-10-08Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba) /* * Lexical analyzer template. * Based on lex.c 1.62 * * Henrik Grubbström 1999-02-20 */ #ifndef SHIFT
a4a1722000-12-05Per Hedbor #error Internal error: SHIFT not defined
acbf0a1999-02-20Henrik Grubbström (Grubba) #endif /* * Definitions */
e232c32000-11-25Henrik Grubbström (Grubba)  /* Generic */ #define GOBBLE(c) (LOOK()==c?(SKIP(),1):0)
e045b22014-09-03Martin Nilsson #define SKIPSPACE() do { while(isspace(LOOK()) && LOOK()!='\n') SKIP(); }while(0) #define SKIPWHITE() do { while(isspace(LOOK())) SKIP(); }while(0)
e232c32000-11-25Henrik Grubbström (Grubba) #define SKIPUPTO(X) do { while(LOOK()!=(X) && LOOK()) SKIP(); }while(0)
acbf0a1999-02-20Henrik Grubbström (Grubba) #if (SHIFT == 0)
362ba42004-11-01Martin Stjernholm #define WCHAR p_wchar0
e021fe2008-04-14Henrik Grubbström (Grubba) #define LOOK() EXTRACT_UCHAR(lex->pos) #define GETC() EXTRACT_UCHAR(lex->pos++) #define SKIP() lex->pos++ #define SKIPN(N) (lex->pos += (N))
acbf0a1999-02-20Henrik Grubbström (Grubba) 
c858402000-08-03Henrik Grubbström (Grubba) #define READBUF(X) do { \
636bc52014-11-01Martin Nilsson  int C; \
e021fe2008-04-14Henrik Grubbström (Grubba)  buf = lex->pos; \
c858402000-08-03Henrik Grubbström (Grubba)  while((C = LOOK()) && (X)) \
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pos++; \ len = (size_t)(lex->pos - buf); \
c858402000-08-03Henrik Grubbström (Grubba) } while(0)
acbf0a1999-02-20Henrik Grubbström (Grubba)  #define TWO_CHAR(X,Y) ((X)<<8)+(Y)
665ec72015-04-21Henrik Grubbström (Grubba) #define ISWORD(X) ((len == CONSTANT_STRLEN(X)) && !memcmp(buf,X,len))
acbf0a1999-02-20Henrik Grubbström (Grubba)  /* * Function renaming */
362ba42004-11-01Martin Stjernholm #define parse_esc_seq parse_esc_seq0
acbf0a1999-02-20Henrik Grubbström (Grubba) #define yylex yylex0 #define low_yylex low_yylex0 #define lex_atoi atoi
2ae97e2014-09-03Martin Nilsson #define lex_strtol strtol
acbf0a1999-02-20Henrik Grubbström (Grubba) #define lex_strtod my_strtod
f50eb01999-02-20Henrik Grubbström (Grubba) #define lex_isidchar isidchar
acbf0a1999-02-20Henrik Grubbström (Grubba)  #else /* SHIFT != 0 */
e021fe2008-04-14Henrik Grubbström (Grubba) #define LOOK() INDEX_CHARP(lex->pos,0,SHIFT) #define SKIP() (lex->pos += (1<<SHIFT))
9e60f22014-01-11Arne Goedeke #define SKIPN(N) (lex->pos += (N) < 0 ? -(-(N) << SHIFT) : ((N)<<SHIFT))
e021fe2008-04-14Henrik Grubbström (Grubba) #define GETC() (SKIP(),INDEX_CHARP(lex->pos-(1<<SHIFT),0,SHIFT))
acbf0a1999-02-20Henrik Grubbström (Grubba) 
c858402000-08-03Henrik Grubbström (Grubba) #define READBUF(X) do { \
636bc52014-11-01Martin Nilsson  int C; \
e021fe2008-04-14Henrik Grubbström (Grubba)  buf = lex->pos; \
c858402000-08-03Henrik Grubbström (Grubba)  while((C = LOOK()) && (X)) \
e232c32000-11-25Henrik Grubbström (Grubba)  SKIP(); \
e021fe2008-04-14Henrik Grubbström (Grubba)  len = (size_t)((lex->pos - buf) >> SHIFT); \
c858402000-08-03Henrik Grubbström (Grubba) } while(0)
acbf0a1999-02-20Henrik Grubbström (Grubba)  #define TWO_CHAR(X,Y) ((X)<<8)+(Y)
7cf8872014-09-03Martin Nilsson #define ISWORD(X) ((len == strlen(X)) && low_isword(buf, X, len))
acbf0a1999-02-20Henrik Grubbström (Grubba)  #if (SHIFT == 1)
362ba42004-11-01Martin Stjernholm #define WCHAR p_wchar1 /* Function renaming */
acbf0a1999-02-20Henrik Grubbström (Grubba) #define low_isword low_isword1
362ba42004-11-01Martin Stjernholm #define parse_esc_seq parse_esc_seq1
acbf0a1999-02-20Henrik Grubbström (Grubba) #define char_const char_const1 #define readstring readstring1 #define yylex yylex1 #define low_yylex low_yylex1 #define lex_atoi lex_atoi1 #define lex_strtol lex_strtol1 #define lex_strtod lex_strtod1 #else /* SHIFT != 1 */
362ba42004-11-01Martin Stjernholm #define WCHAR p_wchar2 /* Function renaming */
acbf0a1999-02-20Henrik Grubbström (Grubba) #define low_isword low_isword2
362ba42004-11-01Martin Stjernholm #define parse_esc_seq parse_esc_seq2
acbf0a1999-02-20Henrik Grubbström (Grubba) #define char_const char_const2 #define readstring readstring2 #define yylex yylex2 #define low_yylex low_yylex2 #define lex_atoi lex_atoi2 #define lex_strtol lex_strtol2 #define lex_strtod lex_strtod2 #endif /* SHIFT == 1 */
a09e182000-08-06Henrik Grubbström (Grubba) 
f50eb01999-02-20Henrik Grubbström (Grubba) #define lex_isidchar(X) ((((unsigned) X)>=256) || isidchar(X))
c858402000-08-03Henrik Grubbström (Grubba) static int low_isword(char *buf, char *X, size_t len)
acbf0a1999-02-20Henrik Grubbström (Grubba) { while(len--) { if (INDEX_CHARP(buf, len, SHIFT) != ((unsigned char *)X)[len]) { return 0; } } return 1; } static int lex_atoi(char *buf) { /* NOTE: Cuts at 63 digits */ char buff[64]; int i=0; int c; while(((c = INDEX_CHARP(buf, i, SHIFT))>='0') && (c <= '9') && (i < 63)) { buff[i++] = c; } buff[i] = 0; return atoi(buff); } static long lex_strtol(char *buf, char **end, int base) {
f3ece81999-02-28Fredrik Hübinette (Hubbe)  PCHARP foo; long ret; ret=STRTOL_PCHARP(MKPCHARP(buf,SHIFT),&foo,base);
01a9572000-02-03Henrik Grubbström (Grubba)  if(end) end[0]=(char *)foo.ptr;
f3ece81999-02-28Fredrik Hübinette (Hubbe)  return ret;
acbf0a1999-02-20Henrik Grubbström (Grubba) } static double lex_strtod(char *buf, char **end) {
f3ece81999-02-28Fredrik Hübinette (Hubbe)  PCHARP foo; double ret; ret=STRTOD_PCHARP(MKPCHARP(buf,SHIFT),&foo);
01a9572000-02-03Henrik Grubbström (Grubba)  if(end) end[0]=(char *)foo.ptr;
f3ece81999-02-28Fredrik Hübinette (Hubbe)  return ret;
acbf0a1999-02-20Henrik Grubbström (Grubba) } #endif /* SHIFT == 0 */
a09e182000-08-06Henrik Grubbström (Grubba) 
acbf0a1999-02-20Henrik Grubbström (Grubba) /*** Lexical analyzing ***/
794be52001-01-30Henrik Grubbström (Grubba) /* String escape sequences * * Sequence Character * \\ backslash * \[0-7]* octal escape * \a alert (BEL) * \b backspace (BS)
2345342006-07-05Martin Stjernholm  * \d[0-9]* decimal escape
794be52001-01-30Henrik Grubbström (Grubba)  * \e escape (ESC) * \f form-feed (FF) * \n newline (LF) * \r carriage-return (CR) * \t tab (HT) * \v vertical-tab (VT) * \x[0-9a-fA-F]* hexadecimal escape
362ba42004-11-01Martin Stjernholm  * \u+[0-9a-fA-F]{4,4} 16 bit unicode style escape * \U+[0-9a-fA-F]{8,8} 32 bit unicode style escape * * If there are more than one u or U in the unicode style escapes, one * is removed and the escape remains otherwise intact.
794be52001-01-30Henrik Grubbström (Grubba)  */
362ba42004-11-01Martin Stjernholm 
fab49a2008-06-29Marcus Comstedt int parse_esc_seq (WCHAR *buf, p_wchar2 *chr, ptrdiff_t *len)
362ba42004-11-01Martin Stjernholm /* buf is assumed to be after the backslash. Return codes: * 0: All ok. The char's in *chr, consumed length in *len. * 1: Found a literal \r at *buf. * 2: Found a literal \n at *buf. * 3: Found a literal \0 at *buf. * 4: Too large octal escape. *len is gobbled to the end of it all. * 5: Too large hexadecimal escape. *len is gobbled to the end of it all. * 6: Too large decimal escape. *len is gobbled to the end of it all. * 7: Not 4 digits in \u escape. *len is up to the last found digit. * 8: Not 8 digits in \U escape. *len is up to the last found digit. */
acbf0a1999-02-20Henrik Grubbström (Grubba) {
362ba42004-11-01Martin Stjernholm  ptrdiff_t l = 1;
fab49a2008-06-29Marcus Comstedt  p_wchar2 c;
fe62692014-01-11Arne Goedeke  int of = 0;
362ba42004-11-01Martin Stjernholm  switch ((c = *buf))
acbf0a1999-02-20Henrik Grubbström (Grubba)  {
362ba42004-11-01Martin Stjernholm  case '\r': return 1; case '\n': return 2; case 0: return 3; case 'a': c = 7; break; /* BEL */ case 'b': c = 8; break; /* BS */ case 't': c = 9; break; /* HT */ case 'n': c = 10; break; /* LF */ case 'v': c = 11; break; /* VT */ case 'f': c = 12; break; /* FF */ case 'r': c = 13; break; /* CR */ case 'e': c = 27; break; /* ESC */
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '0': case '1': case '2': case '3':
362ba42004-11-01Martin Stjernholm  case '4': case '5': case '6': case '7': {
b279262008-06-29Marcus Comstedt  unsigned INT32 n = c-'0';
9648cd2014-05-10Per Hedbor  for (l = 1; buf[l] >= '0' && buf[l] < '8'; l++) {
fe62692014-01-11Arne Goedeke  if (DO_UINT32_MUL_OVERFLOW(n, 8, &n)) of = 1; else n += buf[l] - '0'; } if (of) { *len = l; return 4;
362ba42004-11-01Martin Stjernholm  }
b279262008-06-29Marcus Comstedt  c = (p_wchar2)n;
362ba42004-11-01Martin Stjernholm  break; }
f6b1ee2011-05-05Henrik Grubbström (Grubba)  case '8': case '9': if( Pike_compiler->compiler_pass == 1 ) yywarning("%c is not a valid octal digit.", c); break;
13670c2015-05-25Martin Nilsson 
362ba42004-11-01Martin Stjernholm  case 'x': {
b279262008-06-29Marcus Comstedt  unsigned INT32 n=0;
362ba42004-11-01Martin Stjernholm  for (l = 1;; l++) { switch (buf[l]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
fe62692014-01-11Arne Goedeke  if (DO_UINT32_MUL_OVERFLOW(n, 16, &n)) of = 1; else n += buf[l] - '0';
a09e182000-08-06Henrik Grubbström (Grubba)  continue;
acbf0a1999-02-20Henrik Grubbström (Grubba)  case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
fe62692014-01-11Arne Goedeke  if (DO_UINT32_MUL_OVERFLOW(n, 16, &n)) of = 1; else n += buf[l] - 'a' + 10;
a09e182000-08-06Henrik Grubbström (Grubba)  continue;
acbf0a1999-02-20Henrik Grubbström (Grubba)  case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
fe62692014-01-11Arne Goedeke  if (DO_UINT32_MUL_OVERFLOW(n, 16, &n)) of = 1; else n += buf[l] - 'A' + 10;
a09e182000-08-06Henrik Grubbström (Grubba)  continue;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
a09e182000-08-06Henrik Grubbström (Grubba)  break;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
fe62692014-01-11Arne Goedeke  if (of) { *len = l; return 5; }
b279262008-06-29Marcus Comstedt  c = (p_wchar2)n;
8a59c12000-08-07Henrik Grubbström (Grubba)  break;
362ba42004-11-01Martin Stjernholm  }
acbf0a1999-02-20Henrik Grubbström (Grubba) 
362ba42004-11-01Martin Stjernholm  case 'd': {
b279262008-06-29Marcus Comstedt  unsigned INT32 n=0;
362ba42004-11-01Martin Stjernholm  for (l = 1;; l++) { switch (buf[l]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
fe62692014-01-11Arne Goedeke  if (DO_UINT32_MUL_OVERFLOW(n, 10, &n) || DO_UINT32_ADD_OVERFLOW(n, buf[l] - '0', &n)) { of = 1; }
a09e182000-08-06Henrik Grubbström (Grubba)  continue;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
a09e182000-08-06Henrik Grubbström (Grubba)  break;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
fe62692014-01-11Arne Goedeke  if (of) { *len = l; return 6; }
b279262008-06-29Marcus Comstedt  c = (p_wchar2)n;
362ba42004-11-01Martin Stjernholm  break; } case 'u': case 'U': { /* FIXME: Do we need compat goo to turn this off? */
a6d6f02004-11-14Martin Stjernholm  /* Note: Code dup in gobble_identifier in preprocessor.h. */
5bd3482014-01-11Tobias S. Josefowitz  unsigned INT32 n = 0;
aee0b52004-11-16Martin Stjernholm  int stop, longq;
362ba42004-11-01Martin Stjernholm  l = 1;
aee0b52004-11-16Martin Stjernholm  if (buf[1] == c) { /* A double-u quoted escape. Convert the "\u" or "\U" to "\", * thereby shaving off a "u" or "U" from the escape * sequence. */ /* Don't check that there's a valid number of hex digits in * this case, since the encoding code that can produce them * doesn't check that. */ c = '\\'; break; }
362ba42004-11-01Martin Stjernholm  if (c == 'u') { stop = l + 4; longq = 0; } else { stop = l + 8; longq = 1; } for (; l < stop; l++) switch (buf[l]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
5bd3482014-01-11Tobias S. Josefowitz  n = 16 * n + buf[l] - '0';
362ba42004-11-01Martin Stjernholm  break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
5bd3482014-01-11Tobias S. Josefowitz  n = 16 * n + buf[l] - 'a' + 10;
362ba42004-11-01Martin Stjernholm  break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
5bd3482014-01-11Tobias S. Josefowitz  n = 16 * n + buf[l] - 'A' + 10;
362ba42004-11-01Martin Stjernholm  break; default: *len = l; return longq ? 8 : 7; }
5bd3482014-01-11Tobias S. Josefowitz  c = (p_wchar2)n;
362ba42004-11-01Martin Stjernholm  } } *len = l; *chr = c; return 0; }
fab49a2008-06-29Marcus Comstedt static p_wchar2 char_const(struct lex *lex)
362ba42004-11-01Martin Stjernholm {
fab49a2008-06-29Marcus Comstedt  p_wchar2 c;
362ba42004-11-01Martin Stjernholm  ptrdiff_t l;
e021fe2008-04-14Henrik Grubbström (Grubba)  switch (parse_esc_seq ((WCHAR *)lex->pos, &c, &l)) {
362ba42004-11-01Martin Stjernholm  case 0: break; case 1: SKIP(); return '\r'; case 2: SKIP();
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->current_line++;
362ba42004-11-01Martin Stjernholm  return '\n'; case 3: yyerror("Unexpected end of file.");
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pos -= (1<<SHIFT);
362ba42004-11-01Martin Stjernholm  return 0; case 4: case 5: case 6:
f682df2008-06-29Martin Nilsson  if( Pike_compiler->compiler_pass == 1 )
0346dc2014-05-10Martin Nilsson  yyerror ("Too large character value in escape.");
fab49a2008-06-29Marcus Comstedt  c = -1;
8a59c12000-08-07Henrik Grubbström (Grubba)  break;
362ba42004-11-01Martin Stjernholm  case 7:
f682df2008-06-29Martin Nilsson  if( Pike_compiler->compiler_pass == 1 )
0346dc2014-05-10Martin Nilsson  yyerror ("Too few hex digits in \\u escape.");
362ba42004-11-01Martin Stjernholm  return '\\'; case 8:
f682df2008-06-29Martin Nilsson  if( Pike_compiler->compiler_pass == 1 )
0346dc2014-05-10Martin Nilsson  yyerror ("Too few hex digits in \\U escape.");
362ba42004-11-01Martin Stjernholm  return '\\';
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
362ba42004-11-01Martin Stjernholm  SKIPN (l);
acbf0a1999-02-20Henrik Grubbström (Grubba)  return c; }
e021fe2008-04-14Henrik Grubbström (Grubba) static struct pike_string *readstring(struct lex *lex)
acbf0a1999-02-20Henrik Grubbström (Grubba) { int c; struct string_builder tmp;
ce4be42000-12-01Henrik Grubbström (Grubba) #if (SHIFT != 0)
e232c32000-11-25Henrik Grubbström (Grubba)  PCHARP bufptr = { NULL, SHIFT };
ce4be42000-12-01Henrik Grubbström (Grubba) #endif /* SHIFT != 0 */
e232c32000-11-25Henrik Grubbström (Grubba) 
acbf0a1999-02-20Henrik Grubbström (Grubba)  init_string_builder(&tmp,0);
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  while(1) {
e232c32000-11-25Henrik Grubbström (Grubba)  char *buf; size_t len;
ce4be42000-12-01Henrik Grubbström (Grubba)  READBUF(((C > '\\') || ((C != '"') && (C != '\\') && (C != '\n'))));
e232c32000-11-25Henrik Grubbström (Grubba)  if (len) {
ce4be42000-12-01Henrik Grubbström (Grubba) #if (SHIFT == 0) string_builder_binary_strcat(&tmp, buf, len); #else /* SHIFT != 0 */
529b842004-03-24Henrik Grubbström (Grubba)  bufptr.ptr = (p_wchar0 *)buf;
e232c32000-11-25Henrik Grubbström (Grubba)  string_builder_append(&tmp, bufptr, len);
ce4be42000-12-01Henrik Grubbström (Grubba) #endif /* SHIFT == 0 */
e232c32000-11-25Henrik Grubbström (Grubba)  }
acbf0a1999-02-20Henrik Grubbström (Grubba)  switch(c=GETC()) { case 0:
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pos -= (1<<SHIFT);
acbf0a1999-02-20Henrik Grubbström (Grubba)  yyerror("End of file in string."); break;
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '\n':
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->current_line++;
acbf0a1999-02-20Henrik Grubbström (Grubba)  yyerror("Newline in string."); break;
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '\\':
e021fe2008-04-14Henrik Grubbström (Grubba)  string_builder_putchar(&tmp, char_const(lex));
acbf0a1999-02-20Henrik Grubbström (Grubba)  continue;
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '"': break;
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  default:
ce4be42000-12-01Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG
5aad932002-08-15Marcus Comstedt  Pike_fatal("Default case in readstring() reached. c:%d\n", c);
ce4be42000-12-01Henrik Grubbström (Grubba) #endif /* PIKE_DEBUG */ break;
acbf0a1999-02-20Henrik Grubbström (Grubba)  } break; }
c15ad82006-10-26Henrik Grubbström (Grubba)  return dmalloc_touch(struct pike_string *, finish_string_builder(&tmp));
acbf0a1999-02-20Henrik Grubbström (Grubba) }
a09e182000-08-06Henrik Grubbström (Grubba) 
072edc2014-02-26Arne Goedeke #if LEXDEBUG>4
e021fe2008-04-14Henrik Grubbström (Grubba) static int low_yylex(struct lex *lex, YYSTYPE *);
072edc2014-02-26Arne Goedeke #endif /* LEXDEBUG>4 */
e021fe2008-04-14Henrik Grubbström (Grubba) int yylex(struct lex *lex, YYSTYPE *yylval)
acbf0a1999-02-20Henrik Grubbström (Grubba) #if LEXDEBUG>4 { int t; #if LEXDEBUG>8 fprintf(stderr, "YYLEX:\n"); #endif /* LEXDEBUG>8 */
e021fe2008-04-14Henrik Grubbström (Grubba)  t=low_yylex(lex, yylval);
acbf0a1999-02-20Henrik Grubbström (Grubba)  if(t<256) { fprintf(stderr,"YYLEX: '%c' (%d) at %s:%d\n",t,t,lex.current_file->str,lex.current_line); }else{
0a2f132008-03-27Henrik Grubbström (Grubba)  fprintf(stderr,"YYLEX: token #%d at %s:%d\n",t,lex.current_file->str,lex.current_line);
acbf0a1999-02-20Henrik Grubbström (Grubba)  } return t; }
e021fe2008-04-14Henrik Grubbström (Grubba) static int low_yylex(struct lex *lex, YYSTYPE *yylval)
acbf0a1999-02-20Henrik Grubbström (Grubba) #endif /* LEXDEBUG>4 */ {
c858402000-08-03Henrik Grubbström (Grubba)  INT32 c; size_t len;
acbf0a1999-02-20Henrik Grubbström (Grubba)  char *buf; #ifdef __CHECKER__
21b12a2014-09-03Martin Nilsson  memset(yylval,0,sizeof(YYSTYPE));
acbf0a1999-02-20Henrik Grubbström (Grubba) #endif #ifdef MALLOC_DEBUG check_sfltable(); #endif while(1) {
e232c32000-11-25Henrik Grubbström (Grubba)  c = GETC();
ce4be42000-12-01Henrik Grubbström (Grubba)  if((c>'9') && lex_isidchar(c))
e232c32000-11-25Henrik Grubbström (Grubba)  {
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pos -= (1<<SHIFT);
e232c32000-11-25Henrik Grubbström (Grubba)  READBUF(lex_isidchar(C));
7a10652003-03-27Martin Stjernholm  PIKE_MEM_WO_RANGE (yylval, sizeof (YYSTYPE));
e232c32000-11-25Henrik Grubbström (Grubba) 
0a2f132008-03-27Henrik Grubbström (Grubba)  if(len>1 && len<16)
e232c32000-11-25Henrik Grubbström (Grubba)  { /* NOTE: TWO_CHAR() will generate false positives with wide strings, * but that doesn't matter, since ISWORD() will fix it. */ switch(TWO_CHAR(INDEX_CHARP(buf, 0, SHIFT), INDEX_CHARP(buf, 1, SHIFT))) { case TWO_CHAR('a','r'): if(ISWORD("array")) return TOK_ARRAY_ID; break;
55c53a2015-03-22Henrik Grubbström (Grubba)  case TWO_CHAR('a','u'): if(ISWORD("auto")) { if (Pike_compiler->compiler_pass == 1) { yywarning("auto will soon be a reserved keyword."); } break; } break;
e232c32000-11-25Henrik Grubbström (Grubba)  case TWO_CHAR('b','r'): if(ISWORD("break")) return TOK_BREAK; break; case TWO_CHAR('c','a'): if(ISWORD("case")) return TOK_CASE; if(ISWORD("catch")) return TOK_CATCH; break; case TWO_CHAR('c','l'): if(ISWORD("class")) return TOK_CLASS; break; case TWO_CHAR('c','o'): if(ISWORD("constant")) return TOK_CONSTANT; if(ISWORD("continue")) return TOK_CONTINUE;
55c53a2015-03-22Henrik Grubbström (Grubba)  if(ISWORD("const")) { if (Pike_compiler->compiler_pass == 1) { yywarning("const will soon be a reserved keyword."); } break; }
e232c32000-11-25Henrik Grubbström (Grubba)  break; case TWO_CHAR('d','e'): if(ISWORD("default")) return TOK_DEFAULT; break; case TWO_CHAR('d','o'): if(ISWORD("do")) return TOK_DO; break; case TWO_CHAR('e','l'): if(ISWORD("else")) return TOK_ELSE; break;
76e7f92001-03-18Henrik Grubbström (Grubba)  case TWO_CHAR('e','n'): if(ISWORD("enum")) return TOK_ENUM; break;
e232c32000-11-25Henrik Grubbström (Grubba)  case TWO_CHAR('e','x'): if(ISWORD("extern")) return TOK_EXTERN; break; case TWO_CHAR('f','i'): if(ISWORD("final")) return TOK_FINAL_ID; break; case TWO_CHAR('f','l'): if(ISWORD("float")) return TOK_FLOAT_ID; break; case TWO_CHAR('f','o'): if(ISWORD("for")) return TOK_FOR; if(ISWORD("foreach")) return TOK_FOREACH; break; case TWO_CHAR('f','u'): if(ISWORD("function")) return TOK_FUNCTION_ID; break; case TWO_CHAR('g','a'): if(ISWORD("gauge")) return TOK_GAUGE; break;
3604362002-05-05Martin Stjernholm  case TWO_CHAR('g','l'):
ec80082014-08-24Martin Nilsson  if (ISWORD("global")) return TOK_GLOBAL;
3604362002-05-05Martin Stjernholm  break;
e232c32000-11-25Henrik Grubbström (Grubba)  case TWO_CHAR('i','f'): if(ISWORD("if")) return TOK_IF; break; case TWO_CHAR('i','m'): if(ISWORD("import")) return TOK_IMPORT; break; case TWO_CHAR('i','n'): if(ISWORD("int")) return TOK_INT_ID; if(ISWORD("inherit")) return TOK_INHERIT; if(ISWORD("inline")) return TOK_INLINE; break; case TWO_CHAR('l','a'): if(ISWORD("lambda")) return TOK_LAMBDA; break; case TWO_CHAR('l','o'): if(ISWORD("local")) return TOK_LOCAL_ID; break; case TWO_CHAR('m','a'): if(ISWORD("mapping")) return TOK_MAPPING_ID; break; case TWO_CHAR('m','i'): if(ISWORD("mixed")) return TOK_MIXED_ID; break; case TWO_CHAR('m','u'): if(ISWORD("multiset")) return TOK_MULTISET_ID; break; case TWO_CHAR('o','b'): if(ISWORD("object")) return TOK_OBJECT_ID; break; case TWO_CHAR('o','p'): if(ISWORD("optional")) return TOK_OPTIONAL; break; case TWO_CHAR('p','r'): if(ISWORD("program")) return TOK_PROGRAM_ID; if(ISWORD("predef")) return TOK_PREDEF; if(ISWORD("private")) return TOK_PRIVATE; if(ISWORD("protected")) return TOK_PROTECTED; break; case TWO_CHAR('p','u'): if(ISWORD("public")) return TOK_PUBLIC; break; case TWO_CHAR('r','e'): if(ISWORD("return")) return TOK_RETURN; break; case TWO_CHAR('s','s'): if(ISWORD("sscanf")) return TOK_SSCANF; break; case TWO_CHAR('s','t'): if(ISWORD("string")) return TOK_STRING_ID; if(ISWORD("static")) return TOK_STATIC; break; case TWO_CHAR('s','w'): if(ISWORD("switch")) return TOK_SWITCH; break; case TWO_CHAR('t','y'):
5e3aa52001-04-01Henrik Grubbström (Grubba)  if(ISWORD("typedef")) return TOK_TYPEDEF;
e232c32000-11-25Henrik Grubbström (Grubba)  if(ISWORD("typeof")) return TOK_TYPEOF; break; case TWO_CHAR('v','a'): if(ISWORD("variant")) return TOK_VARIANT; break; case TWO_CHAR('v','o'): if(ISWORD("void")) return TOK_VOID_ID; break; case TWO_CHAR('w','h'): if(ISWORD("while")) return TOK_WHILE; break;
0a2f132008-03-27Henrik Grubbström (Grubba)  case TWO_CHAR('_','_'):
ff9bec2008-05-31Henrik Grubbström (Grubba)  if(len < 5) break; if(ISWORD("__attribute__"))
0e472c2008-05-31Martin Stjernholm  return TOK_ATTRIBUTE_ID;
ff9bec2008-05-31Henrik Grubbström (Grubba)  if(ISWORD("__deprecated__"))
0e472c2008-05-31Martin Stjernholm  return TOK_DEPRECATED_ID;
ff9bec2008-05-31Henrik Grubbström (Grubba)  if(ISWORD("__func__"))
0e472c2008-05-31Martin Stjernholm  return TOK_FUNCTION_NAME;
ff9bec2008-05-31Henrik Grubbström (Grubba)  /* Allow triple (or more) underscore for the user, and make sure we * don't get false matches below for wide strings. */ if((INDEX_CHARP(buf, 2, SHIFT) == '_') || (INDEX_CHARP(buf, len-3, SHIFT) == '_') || (INDEX_CHARP(buf, len-2, SHIFT) != '_') || (INDEX_CHARP(buf, len-1, SHIFT) != '_') || (INDEX_CHARP(buf, 0, SHIFT) != '_') || (INDEX_CHARP(buf, 1, SHIFT) != '_')) break;
4b3dc52008-06-18Martin Stjernholm  { /* Double underscore before and after is reserved for keywords. */
32bc322008-06-18Henrik Grubbström (Grubba) #if (SHIFT == 0)
4b3dc52008-06-18Martin Stjernholm  struct pike_string *tmp = make_shared_binary_string(buf, len);
32bc322008-06-18Henrik Grubbström (Grubba) #else /* SHIFT != 0 */ #if (SHIFT == 1)
4b3dc52008-06-18Martin Stjernholm  struct pike_string *tmp = make_shared_binary_string1((p_wchar1 *)buf, len);
32bc322008-06-18Henrik Grubbström (Grubba) #else /* SHIFT != 1 */
4b3dc52008-06-18Martin Stjernholm  struct pike_string *tmp = make_shared_binary_string2((p_wchar2 *)buf, len);
32bc322008-06-18Henrik Grubbström (Grubba) #endif /* SHIFT == 1 */ #endif /* SHIFT == 0 */
4b3dc52008-06-18Martin Stjernholm  yylval->n=mkstrnode(tmp);
612e522009-04-16Henrik Grubbström (Grubba)  /* - But only for lower case US-ASCII. * - Upper case is used for symbols intended for #if constant(). */ if (tmp->size_shift) {
13670c2015-05-25Martin Nilsson  free_string(tmp);
612e522009-04-16Henrik Grubbström (Grubba)  return TOK_IDENTIFIER; } while(len--) { int c = tmp->str[len]; if ((c >= 'A') && (c <= 'Z')) { free_string(tmp); return TOK_IDENTIFIER; } }
13670c2015-05-25Martin Nilsson  free_string(tmp);
4b3dc52008-06-18Martin Stjernholm  }
32bc322008-06-18Henrik Grubbström (Grubba)  return TOK_RESERVED;
e232c32000-11-25Henrik Grubbström (Grubba)  } } { #if (SHIFT == 0) struct pike_string *tmp = make_shared_binary_string(buf, len); #else /* SHIFT != 0 */ #if (SHIFT == 1) struct pike_string *tmp = make_shared_binary_string1((p_wchar1 *)buf, len); #else /* SHIFT != 1 */ struct pike_string *tmp = make_shared_binary_string2((p_wchar2 *)buf, len); #endif /* SHIFT == 1 */ #endif /* SHIFT == 0 */ yylval->n=mkstrnode(tmp); free_string(tmp); return TOK_IDENTIFIER; } }
ce4be42000-12-01Henrik Grubbström (Grubba)  /* Note that 0 <= c <= 255 at this point. */
e232c32000-11-25Henrik Grubbström (Grubba)  switch(c)
acbf0a1999-02-20Henrik Grubbström (Grubba)  { case 0:
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pos -= (1<<SHIFT); if(lex->end != lex->pos)
5f0d8b2003-01-08Henrik Grubbström (Grubba)  yyerror("Illegal character (NUL)");
7db54d2001-10-02Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) #ifdef TOK_LEX_EOF return TOK_LEX_EOF; #else /* !TOK_LEX_EOF */
acbf0a1999-02-20Henrik Grubbström (Grubba)  return 0;
f76b4c2000-05-11Henrik Grubbström (Grubba) #endif /* TOK_LEX_EOF */
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '\n':
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->current_line++;
acbf0a1999-02-20Henrik Grubbström (Grubba)  continue;
b6669a1999-03-14Henrik Grubbström (Grubba)  case 0x1b: case 0x9b: /* ESC or CSI */ /* Assume ANSI/DEC escape sequence. * Format supported: * <ESC>[\040-\077]+[\100-\177] * or * <CSI>[\040-\077]*[\100-\177] */ while ((c = LOOK()) && (c == ((c & 0x1f)|0x20))) { SKIP(); } if (c == ((c & 0x3f)|0x40)) { SKIP(); } else { /* FIXME: Warning here? */ } continue;
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '#': SKIPSPACE();
e232c32000-11-25Henrik Grubbström (Grubba)  READBUF(C!='\n' && C!=' ' && C!='\t');
acbf0a1999-02-20Henrik Grubbström (Grubba)  switch(len>0?INDEX_CHARP(buf, 0, SHIFT):0) {
ea0d482012-07-22Arne Goedeke  case 'l': if (ISWORD("line")) { SKIPSPACE(); if (LOOK() < '0' || LOOK() > '9') goto unknown_directive; READBUF(C!='\n' && C!=' ' && C!='\t'); /* fallthrough */ } else goto unknown_directive;
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
ef24a82012-01-12Henrik Grubbström (Grubba)  lex->current_line = lex_strtol(buf, NULL, 10)-1;
acbf0a1999-02-20Henrik Grubbström (Grubba)  SKIPSPACE(); if(GOBBLE('"')) {
e021fe2008-04-14Henrik Grubbström (Grubba)  struct pike_string *tmp=readstring(lex); free_string(lex->current_file); lex->current_file = dmalloc_touch(struct pike_string *, tmp);
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
4f985f2001-06-30Martin Stjernholm  if (Pike_compiler->compiler_pass == 1 && !Pike_compiler->new_program->num_linenumbers) { /* A nested program will always get an entry right away in * language.yacc. */
e021fe2008-04-14Henrik Grubbström (Grubba)  store_linenumber(0, lex->current_file);
4f985f2001-06-30Martin Stjernholm #ifdef DEBUG_MALLOC
e021fe2008-04-14Henrik Grubbström (Grubba)  if(strcmp(lex->current_file->str,"-")) debug_malloc_name(Pike_compiler->new_program, lex->current_file->str, 0);
4f985f2001-06-30Martin Stjernholm #endif }
acbf0a1999-02-20Henrik Grubbström (Grubba)  break;
4f985f2001-06-30Martin Stjernholm 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case 'p': if(ISWORD("pragma")) { SKIPSPACE();
a3196f2008-06-28Martin Nilsson  READBUF(C!='\n'&&C!=' ');
acbf0a1999-02-20Henrik Grubbström (Grubba)  if (ISWORD("all_inline")) {
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pragmas |= ID_INLINE;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
0085e42014-10-05Martin Nilsson  else if (ISWORD("all_final"))
acbf0a1999-02-20Henrik Grubbström (Grubba)  {
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pragmas |= ID_FINAL;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
04d8b71999-11-23Henrik Grubbström (Grubba)  else if (ISWORD("strict_types")) {
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pragmas |= ID_STRICT_TYPES;
04d8b71999-11-23Henrik Grubbström (Grubba)  }
001aa52001-06-08Fredrik Hübinette (Hubbe)  else if (ISWORD("save_parent")) {
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pragmas |= ID_SAVE_PARENT;
001aa52001-06-08Fredrik Hübinette (Hubbe)  }
2fbfc42002-06-11Martin Stjernholm  else if (ISWORD("dont_save_parent")) {
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pragmas |= ID_DONT_SAVE_PARENT;
2fbfc42002-06-11Martin Stjernholm  }
fe459e2008-05-29Henrik Grubbström (Grubba)  else if (ISWORD("no_deprecation_warnings")) { lex->pragmas |= ID_NO_DEPRECATION_WARNINGS; } else if (ISWORD("deprecation_warnings")) { lex->pragmas &= ~ID_NO_DEPRECATION_WARNINGS; }
9b4ac32014-11-26Henrik Grubbström (Grubba)  else if (ISWORD("disassemble")) { lex->pragmas |= ID_DISASSEMBLE; } else if (ISWORD("no_disassemble")) { lex->pragmas &= ~ID_DISASSEMBLE; }
c23dba2008-06-28Martin Nilsson  else {
f682df2008-06-29Martin Nilsson  if( Pike_compiler->compiler_pass == 1 ) yywarning("Unknown #pragma directive.");
c23dba2008-06-28Martin Nilsson  }
acbf0a1999-02-20Henrik Grubbström (Grubba)  break; }
0a54c32002-11-04Martin Nilsson 
ac87152000-09-25Fredrik Hübinette (Hubbe)  if(ISWORD("pike")) { int minor; int major; SKIPSPACE();
e232c32000-11-25Henrik Grubbström (Grubba)  READBUF(C!='.' && C!='\n');
ac87152000-09-25Fredrik Hübinette (Hubbe)  major=lex_atoi(buf); if(!GOBBLE('.')) { yyerror("Missing '.' in #pike directive."); minor=0; }else{ READBUF(C!='\n' && C!='.'); minor=lex_atoi(buf); if(GOBBLE('.')) yyerror("Build numbers not supported in #pike directive."); READBUF(C!='\n'); change_compiler_compatibility(major, minor); } break; }
2bc8282004-03-24Henrik Grubbström (Grubba)  /* FALL_THROUGH */ default:
ea0d482012-07-22Arne Goedeke unknown_directive:
e232c32000-11-25Henrik Grubbström (Grubba)  if (len < 256) { #if (SHIFT == 0) struct pike_string *dir = make_shared_binary_string(buf, len);
1cefd22014-05-06Per Hedbor #elif (SHIFT == 1)
e232c32000-11-25Henrik Grubbström (Grubba)  struct pike_string *dir = make_shared_binary_string1((p_wchar1 *)buf, len);
1cefd22014-05-06Per Hedbor #elif (SHIFT == 2)
e232c32000-11-25Henrik Grubbström (Grubba)  struct pike_string *dir = make_shared_binary_string2((p_wchar2 *)buf, len);
1cefd22014-05-06Per Hedbor #endif
ce060e2004-06-30Martin Nilsson  my_yyerror("Unknown preprocessor directive %S.", dir);
e232c32000-11-25Henrik Grubbström (Grubba)  free_string(dir); } else {
5f0d8b2003-01-08Henrik Grubbström (Grubba)  yyerror("Unknown preprocessor directive.");
acbf0a1999-02-20Henrik Grubbström (Grubba)  } SKIPUPTO('\n'); continue; } continue; case ' ': case '\t': continue; case '\'': {
896a342014-10-22Per Hedbor  unsigned int l = 0; struct svalue res = svalue_int_zero; MP_INT bigint;
1cefd22014-05-06Per Hedbor  while(1) { INT32 tmp; switch( (tmp=GETC()) ) { case 0: lex->pos -= (1<<SHIFT); yyerror("Unexpected end of file\n"); goto return_char; case '\\': tmp = char_const(lex); /* fallthrough. */ default:
896a342014-10-22Per Hedbor  l++; if( l == sizeof(INT_TYPE)-1 ) { /* overflow possible. Switch to bignums. */ mpz_init(&bigint); mpz_set_ui(&bigint,res.u.integer); TYPEOF(res) = PIKE_T_OBJECT; } if( l >= sizeof(INT_TYPE)-1 )
1cefd22014-05-06Per Hedbor  {
896a342014-10-22Per Hedbor  mpz_mul_2exp(&bigint,&bigint,8); mpz_add_ui(&bigint,&bigint,tmp); } else { res.u.integer <<= 8; res.u.integer |= tmp;
1cefd22014-05-06Per Hedbor  } break; case '\'': if( l == 0 ) yyerror("Zero-length character constant."); goto return_char; } } return_char:
896a342014-10-22Per Hedbor  if( TYPEOF(res) == PIKE_T_OBJECT ) { push_bignum( &bigint ); mpz_clear(&bigint); reduce_stack_top_bignum(); res = *--Pike_sp; } debug_malloc_pass( yylval->n=mksvaluenode(&res) ); free_svalue( &res );
1cefd22014-05-06Per Hedbor  return TOK_NUMBER;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
b42e942015-09-28Martin Nilsson  UNREACHABLE();
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '"': {
e021fe2008-04-14Henrik Grubbström (Grubba)  struct pike_string *s=readstring(lex);
acbf0a1999-02-20Henrik Grubbström (Grubba)  yylval->n=mkstrnode(s); free_string(s);
f76b4c2000-05-11Henrik Grubbström (Grubba)  return TOK_STRING;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
1cefd22014-05-06Per Hedbor 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case ':':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE(':')) return TOK_COLON_COLON;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return c; case '.': if(GOBBLE('.')) {
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('.')) return TOK_DOT_DOT_DOT; return TOK_DOT_DOT;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
e021fe2008-04-14Henrik Grubbström (Grubba)  if (((c = INDEX_CHARP(lex->pos, 0, SHIFT)) <= '9') &&
3d512f2007-04-02Henrik Grubbström (Grubba)  (c >= '0')) {
b244fc2015-09-27Martin Nilsson  lex->pos -= (1<<SHIFT);
3d512f2007-04-02Henrik Grubbström (Grubba)  goto read_float; } return '.';
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '0':
5656451999-10-26Fredrik Noring  { int base = 0;
e04ce12013-12-11Per Hedbor 
5656451999-10-26Fredrik Noring  if(GOBBLE('b') || GOBBLE('B'))
acbf0a1999-02-20Henrik Grubbström (Grubba)  {
5656451999-10-26Fredrik Noring  base = 2; goto read_based_number; } else if(GOBBLE('x') || GOBBLE('X')) {
ef069c1999-11-11Henrik Grubbström (Grubba)  struct svalue sval;
5656451999-10-26Fredrik Noring  base = 16; read_based_number:
017b572011-10-28Henrik Grubbström (Grubba)  SET_SVAL(sval, PIKE_T_INT, NUMBER_NUMBER, integer, 0);
15f63a2008-07-23Martin Stjernholm  safe_wide_string_to_svalue_inumber(&sval, lex->pos, &lex->pos, base, 0, SHIFT);
ef069c1999-11-11Henrik Grubbström (Grubba)  dmalloc_touch_svalue(&sval); yylval->n = mksvaluenode(&sval); free_svalue(&sval);
f76b4c2000-05-11Henrik Grubbström (Grubba)  return TOK_NUMBER;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
5656451999-10-26Fredrik Noring  }
12bb2a2015-04-22Henrik Grubbström (Grubba)  /* FALL_THROUGH */
e04ce12013-12-11Per Hedbor 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { char *p1, *p2; double f;
96e32e2013-11-03Arne Goedeke  long l;
ef069c1999-11-11Henrik Grubbström (Grubba)  struct svalue sval;
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pos -= (1<<SHIFT); if(INDEX_CHARP(lex->pos, 0, SHIFT)=='0') for(l=1;INDEX_CHARP(lex->pos, l, SHIFT)<='9' && INDEX_CHARP(lex->pos, l, SHIFT)>='0';l++) if(INDEX_CHARP(lex->pos, l, SHIFT)>='8')
5f0d8b2003-01-08Henrik Grubbström (Grubba)  my_yyerror("Illegal octal digit '%c'.",
e021fe2008-04-14Henrik Grubbström (Grubba)  INDEX_CHARP(lex->pos, l, SHIFT));
acbf0a1999-02-20Henrik Grubbström (Grubba) 
3d512f2007-04-02Henrik Grubbström (Grubba)  read_float:
e021fe2008-04-14Henrik Grubbström (Grubba)  f=lex_strtod(lex->pos, &p1);
011ad31999-10-22Fredrik Hübinette (Hubbe) 
017b572011-10-28Henrik Grubbström (Grubba)  SET_SVAL(sval, PIKE_T_INT, NUMBER_NUMBER, integer, 0);
ef069c1999-11-11Henrik Grubbström (Grubba) 
15f63a2008-07-23Martin Stjernholm  safe_wide_string_to_svalue_inumber(&sval, lex->pos, &p2, 0, 0, SHIFT);
acbf0a1999-02-20Henrik Grubbström (Grubba)  if(p1>p2) {
b6659f2006-01-21Henrik Grubbström (Grubba)  /* Floating point or version. */
017b572011-10-28Henrik Grubbström (Grubba)  if ((TYPEOF(sval) == PIKE_T_INT) &&
b6659f2006-01-21Henrik Grubbström (Grubba)  (INDEX_CHARP(p2, 0, SHIFT) == '.')) { int major = sval.u.integer; char *p3 = p2; p2 += (1<<SHIFT); dmalloc_touch_svalue(&sval); sval.u.integer = 0;
15f63a2008-07-23Martin Stjernholm  safe_wide_string_to_svalue_inumber(&sval, p2, &p3, 0, 0, SHIFT);
b6659f2006-01-21Henrik Grubbström (Grubba)  dmalloc_touch_svalue(&sval);
017b572011-10-28Henrik Grubbström (Grubba)  if ((TYPEOF(sval) == PIKE_T_INT) && (p3 > p2)) {
e045b22014-09-03Martin Nilsson  for (l=0; isspace(INDEX_CHARP(p3, l, SHIFT)); l++)
b6659f2006-01-21Henrik Grubbström (Grubba)  ; if ((INDEX_CHARP(p3, l, SHIFT) == ':') && (INDEX_CHARP(p3, l+1, SHIFT) == ':')) { /* Version prefix. */
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pos = p3;
b6659f2006-01-21Henrik Grubbström (Grubba)  yylval->n = mkversionnode(major, sval.u.integer); return TOK_VERSION; } } } free_svalue(&sval);
acbf0a1999-02-20Henrik Grubbström (Grubba)  yylval->fnum=(FLOAT_TYPE)f;
e0d4ce2000-10-08Henrik Grubbström (Grubba) #if 0 fprintf(stderr, "LEX: \"%.8s\" => %f, %f\n",
e021fe2008-04-14Henrik Grubbström (Grubba)  (char *)lex->pos, f, yylval->fnum);
e0d4ce2000-10-08Henrik Grubbström (Grubba) #endif /* 0 */
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pos=p1;
2f18672003-02-26Martin Stjernholm  if (lex_isidchar (LOOK())) {
96e32e2013-11-03Arne Goedeke  my_yyerror ("Invalid char '%c' in constant.", LOOK());
2f18672003-02-26Martin Stjernholm  do SKIP(); while (lex_isidchar (LOOK())); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  return TOK_FLOAT;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }else{
b6659f2006-01-21Henrik Grubbström (Grubba)  dmalloc_touch_svalue(&sval); yylval->n = mksvaluenode(&sval); free_svalue(&sval);
011ad31999-10-22Fredrik Hübinette (Hubbe)  debug_malloc_touch(yylval->n);
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pos=p2;
e04ce12013-12-11Per Hedbor  if (lex_isidchar (LOOK())) { if( GOBBLE('b') ) if( GOBBLE( 'i' ) ) if( GOBBLE( 't' ) ) { GOBBLE('s'); return TOK_BITS; }
96e32e2013-11-03Arne Goedeke  my_yyerror ("Invalid char '%c' in constant.", LOOK());
2f18672003-02-26Martin Stjernholm  do SKIP(); while (lex_isidchar (LOOK())); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  return TOK_NUMBER;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
e232c32000-11-25Henrik Grubbström (Grubba)  }
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '-':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_SUB_EQ; if(GOBBLE('>')) return TOK_ARROW; if(GOBBLE('-')) return TOK_DEC;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '-';
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '+':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_ADD_EQ; if(GOBBLE('+')) return TOK_INC;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '+';
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '&':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_AND_EQ; if(GOBBLE('&')) return TOK_LAND;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '&';
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '|':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_OR_EQ; if(GOBBLE('|')) return TOK_LOR;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '|'; case '^':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_XOR_EQ;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '^';
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '*':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_MULT_EQ;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '*'; case '%':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_MOD_EQ;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '%';
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '/':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_DIV_EQ;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '/';
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '=':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_EQ;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '=';
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '<': if(GOBBLE('<')) {
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_LSH_EQ; return TOK_LSH;
acbf0a1999-02-20Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_LE;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '<';
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '>':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE(')')) return TOK_MULTISET_END; if(GOBBLE('=')) return TOK_GE;
acbf0a1999-02-20Henrik Grubbström (Grubba)  if(GOBBLE('>')) {
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_RSH_EQ; return TOK_RSH;
acbf0a1999-02-20Henrik Grubbström (Grubba)  } return '>'; case '!':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('=')) return TOK_NE; return TOK_NOT;
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '(':
f76b4c2000-05-11Henrik Grubbström (Grubba)  if(GOBBLE('<')) return TOK_MULTISET_START;
acbf0a1999-02-20Henrik Grubbström (Grubba)  return '('; case '?':
0ad6502012-10-02Per Hedbor  if(GOBBLE(':')) return TOK_LOR; if(GOBBLE('-') ) /* safe index: ?-> or ?[] */ { if( GOBBLE( '>' ) ) /* ?-> */ return TOK_SAFE_INDEX; SKIPN(-1); /* Undo GOBBLE('-') above */ } /* Probably wanted: ?. for safe constant index ?[] for safe [] index They however conflict with valid ?: syntaxes. */ /* if( GOBBLE('.' ) ) */ /* return TOK_SAFE_INDEX; */ case ']':
acbf0a1999-02-20Henrik Grubbström (Grubba)  case ',': case '~': case '@': case ')':
0ad6502012-10-02Per Hedbor 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '{': case ';': case '}': return c;
ccb5932012-11-03Per Hedbor  case '[': if( GOBBLE('?' ) ) return TOK_SAFE_START_INDEX; return c;
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '`': { char *tmp; int offset=2;
e232c32000-11-25Henrik Grubbström (Grubba)  if(GOBBLE('`')) { offset--; if(GOBBLE('`')) { offset--; } }
13670c2015-05-25Martin Nilsson 
0d3d502008-04-18Henrik Grubbström (Grubba)  switch(c = GETC())
acbf0a1999-02-20Henrik Grubbström (Grubba)  { case '/': tmp="```/"; break; case '%': tmp="```%"; break; case '*': tmp="```*"; break; case '&': tmp="```&"; break; case '|': tmp="```|"; break; case '^': tmp="```^"; break; case '~': tmp="```~"; break; case '+': if(GOBBLE('=')) { tmp="```+="; break; } tmp="```+"; break; case '<': if(GOBBLE('<')) { tmp="```<<"; break; } if(GOBBLE('=')) { tmp="```<="; break; } tmp="```<"; break; case '>': if(GOBBLE('>')) { tmp="```>>"; break; } if(GOBBLE('=')) { tmp="```>="; break; } tmp="```>"; break; case '!': if(GOBBLE('=')) { tmp="```!="; break; } tmp="```!"; break; case '=': if(GOBBLE('=')) { tmp="```=="; break; } tmp="```="; break; case '(':
e232c32000-11-25Henrik Grubbström (Grubba)  tmp="```()";
13670c2015-05-25Martin Nilsson  if(GOBBLE(')'))
acbf0a1999-02-20Henrik Grubbström (Grubba)  { break; }
e232c32000-11-25Henrik Grubbström (Grubba)  yyerror("Illegal ` identifier. Expected `().");
acbf0a1999-02-20Henrik Grubbström (Grubba)  break;
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  case '-': if(GOBBLE('>')) {
c15ad82006-10-26Henrik Grubbström (Grubba)  if ((offset == 2) && lex_isidchar(LOOK())) {
59af282007-11-15Henrik Grubbström (Grubba)  /* Getter/setter (old-style)
c15ad82006-10-26Henrik Grubbström (Grubba)  * * Either * `->symbol * Or * `->symbol= */ char *buf; size_t len; struct pike_string *s; READBUF(lex_isidchar(C));
2c2d9e2006-10-28Henrik Grubbström (Grubba)  if (GOBBLE('=')) len += 1;
c15ad82006-10-26Henrik Grubbström (Grubba)  /* Adjust for the prefix (`->). */
2c2d9e2006-10-28Henrik Grubbström (Grubba)  len += 3;
c15ad82006-10-26Henrik Grubbström (Grubba)  buf -= 3<<SHIFT; #if (SHIFT == 0) s = make_shared_binary_string(buf, len); #else /* SHIFT != 0 */ #if (SHIFT == 1) s = make_shared_binary_string1((p_wchar1 *)buf, len); #else /* SHIFT != 1 */ s = make_shared_binary_string2((p_wchar2 *)buf, len); #endif /* SHIFT == 1 */ #endif /* SHIFT == 0 */ yylval->n = mkstrnode(s); free_string(s); return TOK_IDENTIFIER; }
acbf0a1999-02-20Henrik Grubbström (Grubba)  tmp="```->"; if(GOBBLE('=')) tmp="```->="; }else{ tmp="```-"; } break; case '[':
e232c32000-11-25Henrik Grubbström (Grubba)  tmp="```[]";
acbf0a1999-02-20Henrik Grubbström (Grubba)  if(GOBBLE(']')) { if(GOBBLE('=')) tmp="```[]="; break; }
408a1e2004-10-30Martin Stjernholm  if (GOBBLE ('.') && GOBBLE ('.') && GOBBLE (']')) { tmp = "```[..]"; break; } yyerror("Illegal ` identifier. Expected `[], `[]= or `[..].");
e232c32000-11-25Henrik Grubbström (Grubba)  break;
acbf0a1999-02-20Henrik Grubbström (Grubba)  default:
0d3d502008-04-18Henrik Grubbström (Grubba)  if (offset==2 && lex_isidchar(c)) {
59af282007-11-15Henrik Grubbström (Grubba)  /* Getter/setter (new-style) * * Either * `symbol * Or * `symbol= */ char *buf; size_t len; struct pike_string *s; READBUF(lex_isidchar(C)); if (GOBBLE('=')) len += 1;
0d3d502008-04-18Henrik Grubbström (Grubba)  /* Adjust for the prefix (`c). */ len += 2; buf -= 2<<SHIFT;
59af282007-11-15Henrik Grubbström (Grubba) #if (SHIFT == 0) s = make_shared_binary_string(buf, len); #else /* SHIFT != 0 */ #if (SHIFT == 1) s = make_shared_binary_string1((p_wchar1 *)buf, len); #else /* SHIFT != 1 */ s = make_shared_binary_string2((p_wchar2 *)buf, len); #endif /* SHIFT == 1 */ #endif /* SHIFT == 0 */ yylval->n = mkstrnode(s); free_string(s); return TOK_IDENTIFIER; }
acbf0a1999-02-20Henrik Grubbström (Grubba)  yyerror("Illegal ` identifier.");
e021fe2008-04-14Henrik Grubbström (Grubba)  lex->pos -= (1<<SHIFT);
e232c32000-11-25Henrik Grubbström (Grubba)  tmp="```";
acbf0a1999-02-20Henrik Grubbström (Grubba)  break; } { struct pike_string *s=make_shared_string(tmp+offset); yylval->n=mkstrnode(s); free_string(s);
f76b4c2000-05-11Henrik Grubbström (Grubba)  return TOK_IDENTIFIER;
acbf0a1999-02-20Henrik Grubbström (Grubba)  } }
13670c2015-05-25Martin Nilsson 
acbf0a1999-02-20Henrik Grubbström (Grubba)  default: {
e232c32000-11-25Henrik Grubbström (Grubba)  if (c > 31) {
f36e9b2004-11-06Henrik Grubbström (Grubba)  my_yyerror("Illegal character '%c' (0x%02x)", c, c);
acbf0a1999-02-20Henrik Grubbström (Grubba)  } else {
f36e9b2004-11-06Henrik Grubbström (Grubba)  my_yyerror("Illegal character 0x%02x", c);
acbf0a1999-02-20Henrik Grubbström (Grubba)  } return ' '; } } } } /* * Clear the defines for the next pass */
362ba42004-11-01Martin Stjernholm #undef WCHAR
acbf0a1999-02-20Henrik Grubbström (Grubba) #undef LOOK #undef GETC
7bc30d1999-03-14Henrik Grubbström (Grubba) #undef SKIP
362ba42004-11-01Martin Stjernholm #undef SKIPN
acbf0a1999-02-20Henrik Grubbström (Grubba) #undef GOBBLE #undef SKIPSPACE #undef SKIPWHITE #undef SKIPUPTO #undef READBUF #undef TWO_CHAR #undef ISWORD #undef low_isword
362ba42004-11-01Martin Stjernholm #undef parse_esc_seq
acbf0a1999-02-20Henrik Grubbström (Grubba) #undef char_const #undef readstring #undef yylex #undef low_yylex #undef lex_atoi #undef lex_strtol #undef lex_strtod
f50eb01999-02-20Henrik Grubbström (Grubba) #undef lex_isidchar