gcompile.yy

来自「Gambit 是一个游戏库理论软件」· YY 代码 · 共 860 行 · 第 1/2 页

YY
860
字号
      gsm->ErrorStream() << toktable[i].name << '\n';      return;    }  switch (gcl_yychar)   {    case NAME:      gsm->ErrorStream() << "identifier " << tval << '\n';      break;    case BOOLEAN:      if (bval == triTRUE)     	gsm->ErrorStream() << "True\n";      else if (bval == triFALSE)        gsm->ErrorStream() << "False\n";      else  /* (bval == triUNKNOWN) */        gsm->ErrorStream() << "Unknown\n";      break;    case FLOAT:      gsm->ErrorStream() << "floating-point constant " << dval << '\n';      break;    case INTEGER:      gsm->ErrorStream() << "integer constant " << ival << '\n';      break;    case TEXT:      gsm->ErrorStream() << "text string " << tval << '\n';      break;    case STDOUT:      gsm->ErrorStream() << "StdOut\n";      break;    case gNULL:      gsm->ErrorStream() << "NullOut\n";      break;    default:      if (isprint(gcl_yychar) && !isspace(gcl_yychar))        gsm->ErrorStream() << ((char) gcl_yychar) << '\n';      else         gsm->ErrorStream() << "nonprinting character " << gcl_yychar << '\n';      break;  }    }int gcl_yylex(void){  char c;    do  {    c = nextchar();  }  while (isspace(c) || c == '\r' || c == '\n');  if (isalpha(c))  {    gText s(c);    c = nextchar();    while (isalpha(c) || isdigit(c))   {      s += c;      c = nextchar();    }    ungetchar(c);    if (s == "True")   {      bval = triTRUE;      return BOOLEAN;    }    else if (s == "False")  {      bval = triFALSE;      return BOOLEAN;    }    else if (s == "Unknown") {      bval = triUNKNOWN;      return BOOLEAN;    }    else if (s == "StdOut") return STDOUT;    else if (s == "NullOut")   return gNULL;    else if (s == "AND")    return LAND;    else if (s == "OR")     return LOR;    else if (s == "NOT")    return LNOT;    else if (s == "DIV")    return DIV;    else if (s == "MOD")    return PERCENT;    else if (s == "If")     return IF;    else if (s == "While")  return WHILE;    else if (s == "For")    return FOR;    else if (s == "NewFunction")   return NEWFUNC;    else if (s == "DeleteFunction")   return DELFUNC;    else if (s == "Float")   return FLOATPREC;    else if (s == "Rational")  return RATIONALPREC;    else if (s == "Include")   return INCLUDE;    else  { tval = s; return NAME; }  }  if (c == '"')   {    tval = "";    bool quote = true;    bool check_digraph = true;    while( quote )    {      c = nextchar();      tval += c;            if( check_digraph &&           tval.Length() >= 2 &&           tval[ tval.Length() - 2 ] == '\\' )      {        switch( c )        {	case '\'':	case '\"':	case '\?':	case '\\':          tval = tval.Left( tval.Length() - 2 ) + gText(c);          check_digraph = false;          break;        case 'a':          tval = tval.Left( tval.Length() - 2 ) + gText('\a');          check_digraph = false;          break;                    case 'b':          tval = tval.Left( tval.Length() - 2 ) + gText('\b');          check_digraph = false;          break;                    case 'f':          tval = tval.Left( tval.Length() - 2 ) + gText('\f');          check_digraph = false;          break;                    case 'n':          tval = tval.Left( tval.Length() - 2 ) + gText('\n');          check_digraph = false;          break;                    case 'r':          tval = tval.Left( tval.Length() - 2 ) + gText('\r');          check_digraph = false;          break;                    case 't':          tval = tval.Left( tval.Length() - 2 ) + gText('\t');          check_digraph = false;          break;                    case 'v':          tval = tval.Left( tval.Length() - 2 ) + gText('\v');          check_digraph = false;          break;                    } // switch( c )      }      else      {        check_digraph = true;        if( c == '\"' )        {          tval = tval.Left( tval.Length() - 1 );          quote = false;        }      }    } // while( quote )    return TEXT;  }  if (isdigit(c))   {    gText s(c);    c = nextchar();    while (isdigit(c))   {      s += c;      c = nextchar();    }    if (c == '.')   {      s += c;      c = nextchar();      while (isdigit(c))  {	s += c;	c = nextchar();      }      ungetchar(c);      dval = atof((char *) s);      return FLOAT;    }    else  {      ungetchar(c);      ival = atoI((char *) s);      return INTEGER;    }  }  switch (c)  {    case ',':   return COMMA;    case '.':   c = nextchar();      if (c < '0' || c > '9')  { ungetchar(c);  return DOT; }      else  {	gText s(".");	s += c;        c = nextchar();        while (isdigit(c))  {	  s += c;	  c = nextchar();        }        ungetchar(c);        dval = atof((char *) s);        return FLOAT;      }    case ';':   return SEMI;    case '_':   return UNDERSCORE;    case '(':   return LPAREN;    case ')':   return RPAREN;    case '{':   return LBRACE;    case '}':   return RBRACE;    case '+':   return PLUS;    case '-':   c = nextchar();                if (c == '>')  return RARROW;                else  { ungetchar(c);  return MINUS; }    case '*':   return STAR;    case '/':   return SLASH;    case '%':   return PERCENT;    case '=':   c = nextchar();                if (c == ':')  return TYPEDEF;                else   { ungetchar(c);  return EQU; }      case '#':   return HASH;    case '^':   return CARET;    case '[':   c = nextchar();                if (c == '[')  return DBLLBRACK;                else   {		  ungetchar(c);		  return LBRACK;		}    case ']':   return RBRACK;    case ':':   c = nextchar();                if (c == '=')  return ASSIGN;                else   { ungetchar(c);  return ':'; }      case '!':   c = nextchar();                if (c == '=')  return NEQ;		else   { ungetchar(c);  return LNOT; }    case '<':   c = nextchar();                if (c == '=')  return LEQ;	        else if (c == '<')  return WRITE;                 else if (c != '-')  { ungetchar(c);  return LTN; }                else   { 		  c = nextchar();		  if (c == '>')   return DBLARROW;		  ungetchar(c);		  return LARROW;		}    case '>':   c = nextchar();                if (c == '=')  return GEQ;                else if (c == '>')  return READ;                else   { ungetchar(c);  return GTN; }    case '&':   c = nextchar();                if (c == '&')  return LAND;                else   { ungetchar(c);  return AMPER; }    case '|':   c = nextchar();                if (c == '|')  return LOR;                else   { ungetchar(c);  return '|'; }    case '$':   return DOLLAR;    case '\0':  return EOC;    case CR:    assert(0);    default:    return c;  }}int GCLParse(GSM *p_gsm,	     const gText& line, const gText &file, int lineno,             const gText& rawline){  gsm = p_gsm;  current_expr = line;  current_char = 0;  current_file = file;  current_line = lineno;  current_rawline = rawline;  for (unsigned int i = 0; i < line.Length(); i++)   {    if (!isspace(line[i]))  {	      if (!gcl_yyparse())  {	        Execute();        if (exprtree)   delete exprtree;      }      return 1;    }  }  return 0;}void RecoverFromError(void){  in_funcdecl = false;  formals.Flush();  types.Flush();  refs.Flush();  portions.Flush();}    gclExpression *NewFunction(gclExpression *expr){  gclFunction *func = new gclFunction(*gsm, funcname, 1);  PortionSpec funcspec;  try {    funcspec = TextToPortionSpec(functype);  }  catch (gclRuntimeError &)  {    gsm->ErrorStream() << "Error: Unknown type " << functype << ", " <<       " as return type in declaration of " << funcname << "[]\n";    return new gclConstExpr(new BoolPortion(false));;  }  gclSignature funcinfo =     gclSignature(expr, funcspec, formals.Length());  funcbody = current_rawline;  if( !strstr((const char *) funcbody, "/*Private*/" ) )    funcinfo.Desc = funcbody;  else    funcinfo.Desc = "/*Private*/";  if( funcdesc.Length() > 0 )    funcinfo.Desc += "\n\n" + funcdesc;  funcdesc = "";    func->SetFuncInfo(0, funcinfo);  for (int i = 1; i <= formals.Length(); i++)   {    PortionSpec spec;    if(portions[i])      spec = portions[i]->Spec();    else {      try {	spec = TextToPortionSpec(types[i]);      }      catch (gclRuntimeError &) {	gsm->ErrorStream() << "Error: Unknown type " << types[i] << ", " << 	  PortionSpecToText(spec) << " for parameter " << formals[i] <<	  " in declaration of " << funcname << "[]\n";	return new gclConstExpr(new BoolPortion(false));;      }    }    if (refs[i])      func->SetParamInfo(0, i - 1, 			 gclParameter(formals[i], spec,				       portions[i], BYREF));      else	func->SetParamInfo(0, i - 1, 			   gclParameter(formals[i], spec,					 portions[i], BYVAL));  }  formals.Flush();  types.Flush();  refs.Flush();  portions.Flush();    return new gclFunctionDef(func, expr);}gclExpression *DeleteFunction(void){  gclFunction *func = new gclFunction(*gsm, funcname, 1);  PortionSpec funcspec;  try  {    funcspec = TextToPortionSpec(functype);  }  catch (gclRuntimeError &)  {    gsm->ErrorStream() << "Error: Unknown type " << functype << ", " <<       PortionSpecToText(funcspec) << " as return type in declaration of " <<       funcname << "[]\n";    return new gclConstExpr(new BoolPortion(false));  }  func->SetFuncInfo(0, gclSignature((gclExpression *) 0, funcspec, formals.Length()));  for (int i = 1; i <= formals.Length(); i++)   {    PortionSpec spec;    try {      if (portions[i])	spec = portions[i]->Spec();      else	spec = TextToPortionSpec(types[i]);            if (refs[i])	func->SetParamInfo(0, i - 1, 			   gclParameter(formals[i], spec,			                portions[i], BYREF));      else	func->SetParamInfo(0, i - 1, 			   gclParameter(formals[i], spec,					portions[i], BYVAL));    }    catch (gclRuntimeError &) {      gsm->ErrorStream() << "Error: Unknown type " << types[i] << ", " << 	PortionSpecToText(spec) << " for parameter " << formals[i] <<	" in declaration of " << funcname << "[]\n";      return new gclConstExpr(new BoolPortion(false));    }  }  formals.Flush();  types.Flush();  refs.Flush();  portions.Flush();  return new gclDeleteFunction(func);}#include "base/gstatus.h"#include "gsm.h"int Execute(void){  try  {    Portion *result = gsm->Execute(exprtree);    if (result)  delete result;  }  catch (gclQuitOccurred &) {    throw;  }  catch (gclRuntimeError &E) {    gsm->OutputStream() << "ERROR: " << E.Description() << '\n';  }  catch (gException &E) {    gsm->OutputStream() << "EXCEPTION: " << E.Description() << '\n';  }  return rcSUCCESS;}

⌨️ 快捷键说明

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