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

📄 eval_read.c

📁 Gambas is a graphical development environment based on a Basic interpreter, like Visual Basic. It us
💻 C
字号:
/***************************************************************************  eval_read.c  Lexical parser  (c) 2000-2003 Beno顃 Minisini <gambas@users.sourceforge.net>  This program is free software; you can redistribute it and/or modify  it under the terms of the GNU General Public License as published by  the Free Software Foundation; either version 1, or (at your option)  any later version.  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.  You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.***************************************************************************/#define __EVAL_READ_C#include <ctype.h>#include "gb_common.h"#include "gb_error.h"#include "gb_table.h"#include "eval.h"#include "eval_read.h"/*#define DEBUG*/PRIVATE long source_ptr;PRIVATE int last_pattern_type = -1;PRIVATE PATTERN last_pattern = 0;PRIVATE boolean begin_line = FALSE;/* We declare the well known class to the compiler *//*PRIVATE void READ_exit(void){  static char *wkclass[] = { "gb", "Class", "File", "Error", "App", "Sys", NULL };  long index;  char **wkc;  for (wkc = wkclass; *wkc; wkc++)  {    if (TABLE_find_symbol(JOB->class->table, *wkc, strlen(*wkc), NULL, &index))      CLASS_add_class(JOB->class, index);  }}*/PUBLIC void READ_dump_pattern(PATTERN *pattern){  int type = PATTERN_TYPE(*pattern);  long index = PATTERN_INDEX(*pattern);  long pos;  pos = (long)(pattern - EVAL->pattern);  if (pos >= 0 && pos < ARRAY_count(EVAL->pattern))    printf("%ld ", pos);  if (PATTERN_flag(*pattern) & RT_FIRST)    printf("!");  else    printf(" ");  if (PATTERN_flag(*pattern) & RT_POINT)    printf(".");  else    printf(" ");  printf(" ");  if (type == RT_RESERVED)    printf("RESERVED     %s\n", TABLE_get_symbol_name(COMP_res_table, index));  else if (type == RT_NUMBER)    printf("NUMBER       %s\n", TABLE_get_symbol_name(EVAL->table, index));  else if (type == RT_IDENTIFIER)    printf("IDENTIFIER   %s\n", TABLE_get_symbol_name(EVAL->table, index));  else if (type == RT_STRING)    printf("STRING       %s\n", TABLE_get_symbol_name(EVAL->string, index));  else if (type == RT_TSTRING)    printf("TSTRING      %s\n", TABLE_get_symbol_name(EVAL->string, index));  else if (type == RT_NEWLINE)    printf("NEWLINE      (%ld)\n", index);  else if (type == RT_END)    printf("END\n");  else if (type == RT_PARAM)    printf("PARAM        %ld\n", index);  else if (type == RT_SUBR)    printf("SUBR         %s\n", COMP_subr_info[index].name);  else    printf("?            %ld\n", index);}PRIVATE uchar get_char_offset(int offset){  offset += source_ptr;  if (offset >= EVAL->len || offset < 0)    return 0;  else    return (uchar)(EVAL->source[offset]);}PRIVATE uchar get_char(void){  return get_char_offset(0);}PRIVATE uchar next_char(void){  source_ptr++;  return get_char();}PRIVATE void add_pattern(int type, long index){  PATTERN *pattern;  /*  if (index > 100)    THROW("add_pattern", "Too many words.");  */  pattern = ARRAY_add(&EVAL->pattern);  *pattern = MAKE_PATTERN(type, index);  last_pattern_type = type;  last_pattern = *pattern;  #ifdef DEBUG  READ_dump_pattern(pattern);  #endif}PRIVATE void add_newline(){  add_pattern(RT_NEWLINE, 0);  source_ptr++;}PRIVATE void add_end(){  add_pattern(RT_END, 0);  source_ptr++;}PRIVATE bool is_number(){  int pos = 0;  unsigned char car;  unsigned char car2;  car = get_char_offset(pos);  if (car == '-' || car == '+')  {    car = get_char_offset(-1);    if (car && !isspace(car))      return FALSE;    pos++;    car = get_char_offset(pos);  }  if (isdigit(car))    return TRUE;  car2 = toupper(get_char_offset(pos + 1));  if (car == '&')  {      if (car2 == 'H')    {      pos += 2;      goto __HEX;    }        if (car2 == 'X')    {      pos += 2;      goto __BIN;    }        pos++;    goto __HEX;  }  else if (car == '%')  {    pos ++;    goto __BIN;  }  else    return FALSE;  __HEX:   car = get_char_offset(pos);  return (isdigit(car) || index("abcdefABCDEF", car) != NULL);  __BIN:     car = get_char_offset(pos);  return (car == '0' || car == '1');}PRIVATE void add_number(){  unsigned char car;  long start;  long index;  start = source_ptr;  car = get_char();  if (car == '-' || car == '+')    car = next_char();  if (car == '&')  {    car = toupper(next_char());    if (car == 'H')      goto READ_HEXA;    else if (car == 'X')      goto READ_BINARY;    else    {      source_ptr--;      goto READ_HEXA;    }  }  else if (car == '%')    goto READ_BINARY;  else    goto READ_NUMBER;READ_BINARY:  for (;;)  {    car = next_char();    if (car != '0' && car != '1')      break;  }  if (car == '&')    car = next_char();  goto END;READ_HEXA:  for (;;)  {    car = next_char();    if (!isxdigit(car))      break;  }  if (car == '&')    car = next_char();  goto END;READ_NUMBER:  while (isdigit(car))    car = next_char();  if (car == '.')  {    do    {      car = next_char();    }    while (isdigit(car));  }  if (toupper(car) == 'E')  {    car = next_char();    if (car == '+' || car == '-')      car = next_char();    while (isdigit(car))      car = next_char();  }  goto END;END:  TABLE_add_symbol(EVAL->table, &EVAL->source[start], source_ptr - start, NULL, &index);  add_pattern(RT_NUMBER, index);}PRIVATE void add_identifier(){  unsigned char car;  long start;  int len;  long index;  int type;  boolean not_first;  boolean can_be_reserved;  boolean can_be_subr;  boolean is_type;  boolean last_func, last_declare, last_type;  start = source_ptr;  len = 1;  for(;;)  {    source_ptr++;    car = get_char();    if (car == 0 || ((!isalnum(car)) && (strchr("$_?", (int)car) == NULL)))      break;    len++;  }  /* On peut mettre ':' dans un identifieur, 

⌨️ 快捷键说明

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