Example #1
0
int 
DEFSP (void)
{
  if (GetSym () == fullstop)
    if (GetSym () == name)
      switch (ident[0])
	{
	case 'B':
	  return 1;

	case 'W':
	  return 2;

	case 'P':
	  return 3;

	case 'L':
	  return 4;

	default:
	  return -1;
	}
    else
      {
	ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
	return -1;
      }
  else
    {
      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
      return -1;
    }
}
Example #2
0
void 
CALLOZ (void)
{
  long constant;
  struct expr *postfixexpr;

  *codeptr++ = 231;		/* RST 20H instruction */
  ++PC;

  if (GetSym () == lparen)
    GetSym ();			/* Optional parenthesis around expression */

  if ((postfixexpr = ParseNumExpr ()) != NULL)
    {
      if (postfixexpr->rangetype & NOTEVALUABLE)
	ReportError (CURRENTFILE->fname, CURRENTFILE->line, 2);		/* CALL_OZ expression must be evaluable */
      else
	{
	  constant = EvalPfixExpr (postfixexpr);
	  if ((constant > 0) && (constant <= 255))
	    {
	      *codeptr++ = constant;	/* 1 byte OZ parameter */
	      ++PC;
	    }
	  else if ((constant > 255) && (constant <= 65535))
	    {
	      *codeptr++ = constant & 255;	/* 2 byte OZ parameter */
	      *codeptr++ = constant >> 8;
	      PC += 2;
	    }
	  else
	    ReportError (CURRENTFILE->fname, CURRENTFILE->line, 4);
	}
Example #3
0
bool Encryption::LoadCrypto(string name)
{
	if(!Load(name.c_str()))
	{
		server_log->Log(log_error, "Failed to load %s from the operating system.", name.c_str());
		return false;
	}
	else
	{
		encrypt_func = (DLLFUNC_Encrypt)GetSym("Encrypt");
		if(encrypt_func == NULL)
		{
			server_log->Log(log_error, "Failed to attach Encrypt.");
			Unload();
			return false;
		}
		decrypt_func = (DLLFUNC_DecryptUsernamePassword)GetSym("DecryptUsernamePassword");
		if(decrypt_func == NULL)
		{
			server_log->Log(log_error, "Failed to attach DecryptUsernamePassword.");
			Unload();
			return false;
		}
		delete_func = (DLLFUNC_HeapDelete)GetSym("_HeapDeleteCharBuffer");
		if(delete_func == NULL)
		{
			server_log->Log(log_error, "Failed to attach _HeapDeleteCharBuffer.");
			Unload();
			return false;
		}
	}
	return true;
}
Example #4
0
void 
DEFS ()
{
  struct expr *postfixexpr;
  struct expr *constexpr;

  long constant,val;

  GetSym ();			/* get numerical expression */
  if ((postfixexpr = ParseNumExpr ()) != NULL)
    {				/* expr. must not be stored in relocatable file */
      if (postfixexpr->rangetype & NOTEVALUABLE)
	ReportError (CURRENTFILE->fname, CURRENTFILE->line, 2);
      else
	{
	  constant = EvalPfixExpr (postfixexpr);

	  if ( sym != comma ) 
	    {
		val = 0;
	    }
	  else 
	    {
		GetSym();
		if ( (constexpr = ParseNumExpr ()) != NULL ) 
		  {
		    if ( constexpr->rangetype & NOTEVALUABLE )
			ReportError(CURRENTFILE->fname,CURRENTFILE->line,2);
		    else
			val = EvalPfixExpr(constexpr);
		    RemovePfixlist(constexpr);
		  }
	    }
	  if (constant >= 0)
	    {
	      if ((PC + constant) <= MAXCODESIZE)
		{
		  PC += constant;

		  while (constant--) *codeptr++ = val;
		}
	      else
		{
		  ReportError (CURRENTFILE->fname, CURRENTFILE->line, 12);
		  return;
		}
	    }
	  else
	    {
	      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 7);
	      return;
	    }
	}
      RemovePfixlist (postfixexpr);	/* remove linked list, expression evaluated */
    }
Example #5
0
/* get the next token, error if not the expected one */
void GetSymExpect(tokid_t expected_tok)
{
	init_module();

	GetSym();
	CurSymExpect(expected_tok);
}
Example #6
0
bool Parser::accept(Symbol s) {
    if (sym == s) {
        GetSym();
        return true;
    }
    return false;
}
Example #7
0
void 
RST (void)
{
  long constant;
  struct expr *postfixexpr;

  GetSym ();
  if ((postfixexpr = ParseNumExpr ()) != NULL)
    {
      if (postfixexpr->rangetype & NOTEVALUABLE)
        ReportError (CURRENTFILE->fname, CURRENTFILE->line, 2);
      else
        {
          constant = EvalPfixExpr (postfixexpr);
          if ((constant >= 0 && constant <= 56) && (constant % 8 == 0))
            {
              if ( (cpu_type & CPU_RABBIT) && 
                   ((constant == 0) || (constant == 8) || (constant == 0x30)))
                {
                  ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
                }
              else
                {
                  *codeptr++ = 199 + constant;	/* RST  00H, ... 38H */
                  ++PC;
                }
            }
          else
            ReportError (CURRENTFILE->fname, CURRENTFILE->line, 4);
        }
      RemovePfixlist (postfixexpr);
    }
}
Example #8
0
bool Parser::acceptOneOf(Symbol* ss) {
    if (symIn(ss)) {
        GetSym();
        return true;
    }
    return false;
}
Example #9
0
Parser::Parser(istream& file) {
    sym = NONE;
    lexer = new Lexer(file);
    bcGen = new BytecodeGenerator();
    nextSym = NONE;

    GetSym();
}
Example #10
0
/*-----------------------------------------------------------------------------
*   Read tokens from the current statement into tokensd[], to be parsed
*	by state machine
*----------------------------------------------------------------------------*/
static void read_token(ParseCtx *ctx)
{
	STR_DEFINE(buffer, STR_SIZE);
	Sym sym_copy;
	int p_index;
	int expr_start_index;

	p_index = ctx->p ? ctx->p - (Sym *)utarray_front(ctx->tokens) : -1;
	expr_start_index = ctx->expr_start ? ctx->expr_start - (Sym *)utarray_front(ctx->tokens) : -1;

	sym_copy = sym;

	/* make text to be used while concatenating tokens to build an expression to parse */
	switch (sym_copy.tok)
	{
	case TK_NUMBER:
		str_sprintf(buffer, "%d", sym_copy.number);
		sym_copy.tstart = token_strings_add(ctx, str_data(buffer));
		sym_copy.tlen = str_len(buffer);
		break;

	case TK_NAME:
	case TK_LABEL:
	case TK_STRING:
		break;

	case TK_END:
		sym_copy.tstart = "";
		sym_copy.tlen = 0;
		break;

	default:;
//		if (!*(sym_copy.text))
//			assert(*(sym_copy.text));
	}
//	sym_copy.string = token_strings_add(sym.string);
	utarray_push_back(ctx->tokens, &sym_copy);

	ctx->p = (Sym *)utarray_front(ctx->tokens) + (p_index >= 0 ? p_index : 0);
	ctx->pe = (Sym *)utarray_back(ctx->tokens) + 1;

	if (sym.tok == TK_END)
		ctx->eof = ctx->pe;
	else
		ctx->eof = NULL;

	ctx->expr_start = expr_start_index >= 0 ? ((Sym *)utarray_front(ctx->tokens)) + expr_start_index : NULL;

	GetSym();

	STR_DELETE(buffer);
}
Example #11
0
	void SymLookup( VDDebugInfo::Context *pctx, const void *ptr, char *buf )
	{
		if( !pctx->Loaded() )
		{
			strcpy( buf, "error" );
			return;
		}

		MEMORY_BASIC_INFORMATION meminfo;
		VirtualQueryEx( g_hParent, ptr, &meminfo, sizeof meminfo );

		char tmp[512];
		long iAddress = VDDebugInfo::VDDebugInfoLookupRVA(pctx, (unsigned int)ptr, tmp, sizeof(tmp));
		if( iAddress >= 0 )
		{
			wsprintf( buf, "%08x: %s [%08lx+%lx+%lx]", ptr, Demangle(tmp),
				pctx->nFirstRVA,
				((unsigned int) ptr) - pctx->nFirstRVA - iAddress,
				iAddress );
			return;
		}

		RString sName = CrashChildGetModuleBaseName( (HMODULE)meminfo.AllocationBase );

		DWORD64 disp;
		SYMBOL_INFO *pSymbol = GetSym( (unsigned int)ptr, disp );

		if( pSymbol )
		{
			wsprintf( buf, "%08lx: %s!%s [%08lx+%lx+%lx]",
				(unsigned long) ptr, sName.c_str(), pSymbol->Name,
				(unsigned long) meminfo.AllocationBase,
				(unsigned long) (pSymbol->Address) - (unsigned long) (meminfo.AllocationBase),
				(unsigned long) disp);
			return;
		}

		wsprintf( buf, "%08lx: %s!%08lx",
			(unsigned long) ptr, sName.c_str(), 
			(unsigned long) meminfo.AllocationBase );
	}
Example #12
0
void 
PushPop_instr (int opcode)
{
  int qq;

  if (GetSym () == name)
    switch (qq = CheckRegister16 ())
      {
      case REG16_BC:
      case REG16_DE:
      case REG16_HL:
        *codeptr++ = opcode + qq * 16;
        ++PC;
        break;

      case REG16_AF:
        *codeptr++ = opcode + 48;
        ++PC;
        break;

      case REG16_IX:
        *codeptr++ = 221;
        *codeptr++ = opcode + 32;
        PC += 2;
        break;

      case REG16_IY:
        *codeptr++ = 253;
        *codeptr++ = opcode + 32;
        PC += 2;
        break;

      default:
        ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
      }
  else
    {
      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
    }
}
Example #13
0
void 
IM (void)
{
  long constant;
  struct expr *postfixexpr;

  if ( (cpu_type & CPU_RABBIT) )
    {
      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
      return;
    }

  GetSym ();
  if ((postfixexpr = ParseNumExpr ()) != NULL)
    {
      if (postfixexpr->rangetype & NOTEVALUABLE)
        ReportError (CURRENTFILE->fname, CURRENTFILE->line, 2);
      else
        {
          constant = EvalPfixExpr (postfixexpr);
          switch (constant)
            {
            case 0:
              *codeptr++ = 237;
              *codeptr++ = 70;	/* IM 0   */
              break;
            case 1:
              *codeptr++ = 237;
              *codeptr++ = 86;	/* IM 1  */
              break;
            case 2:
              *codeptr++ = 237;
              *codeptr++ = 94;	/* IM 2  */
              break;
            }
          PC += 2;
        }
      RemovePfixlist (postfixexpr);	/* remove linked list, because expr. was evaluated */
    }
}
Example #14
0
long 
Parsevarsize (void)
{

  struct expr *postfixexpr;

  long offset = 0, varsize, size_multiplier;

  if (strcmp (ident, "DS") != 0)
    ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
  else
    {
      if ((varsize = DEFSP ()) == -1)
	ReportError (CURRENTFILE->fname, CURRENTFILE->line, 10);
      else
	{
	  GetSym ();

	  if ((postfixexpr = ParseNumExpr ()) != NULL)
	    {
	      if (postfixexpr->rangetype & NOTEVALUABLE)
		{
		  ReportError (CURRENTFILE->fname, CURRENTFILE->line, 2);
		  RemovePfixlist (postfixexpr);
		}
	      else
		{
		  size_multiplier = EvalPfixExpr (postfixexpr);
		  RemovePfixlist (postfixexpr);
		  if (size_multiplier > 0 && size_multiplier <= MAXCODESIZE)
		    offset = varsize * size_multiplier;
		  else
		    ReportError (CURRENTFILE->fname, CURRENTFILE->line, 4);
		}
	    }
	}
    }

  return offset;
}
Example #15
0
/*-----------------------------------------------------------------------------
*   parse the given assembly file, return FALSE if failed
*----------------------------------------------------------------------------*/
static void parseline(ParseCtx *ctx)
{
	int start_num_errors;

	next_PC();				/* update assembler program counter */
	EOL = FALSE;			/* reset END OF LINE flag */

	start_num_errors = get_num_errors();

	scan_expect_opcode();
	GetSym();

	if (get_num_errors() != start_num_errors)		/* detect errors in GetSym() */
		Skipline();
	else if (!parse_statement(ctx))
	{
		if (get_num_errors() == start_num_errors)	/* no error output yet */
			error_syntax();

		Skipline();
	}
	list_end_line();				/* Write current source line to list file */
}
Example #16
0
long 
Parsedefvarsize (long offset)
{
  long varoffset = 0;

  switch (sym)
    {
    case name:
      if (strcmp (ident, "DS") != 0)
	{
	  DefineSymbol (ident, offset, 0);
	  GetSym ();
	}
      if (sym == name)
	  varoffset = Parsevarsize ();
      break;

    default:
      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
    }

  return varoffset;
}
Example #17
0
void 
RET (void)
{
  long constant;

  switch (GetSym ())
    {
    case name:
      if ((constant = CheckCondition ()) != -1)
        *codeptr++ = 192 + constant * 8;	/* RET cc  instruction opcode */
      else
        ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
      break;

    case newline:
      *codeptr++ = 201;
      break;

    default:
      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
      return;
    }
  ++PC;
}
Example #18
0
/* save the current scanner context and parse the given expression */
struct Expr *parse_expr(char *expr_text)
{
	Expr *expr;
	int num_errors;

	save_scan_state();
	{
		src_push();
		{
			SetTemporaryLine(expr_text);
			num_errors = get_num_errors();
			EOL = FALSE;
			scan_expect_operands();
			GetSym();
			expr = expr_parse();		/* may output error */
			if (sym.tok != TK_END && num_errors == get_num_errors())
				error_syntax();
		}
		src_pop();
	}
	restore_scan_state();
	
	return expr;
}
Example #19
0
void 
ReadExpr (long nextexpr, long endexpr)
{
  char type;
  long lowbyte, highbyte, offsetptr;
  long constant, i, fptr;
  struct expr *postfixexpr;
  unsigned char *patchptr;

  do
    {
      type = fgetc (z80asmfile);
      lowbyte = fgetc (z80asmfile);
      highbyte = fgetc (z80asmfile);
      offsetptr = highbyte * 256U + lowbyte;

      /* assembler PC     as absolute address */
      PC = modulehdr->first->origin + CURRENTMODULE->startoffset + offsetptr;

      FindSymbol (ASSEMBLERPC, globalroot)->symvalue = PC;

      i = fgetc (z80asmfile);	/* get length of infix expression */
      fptr = ftell (z80asmfile);	/* file pointer is at start of expression */
      fgets (line, i + 1, z80asmfile);	/* read string for error reference */
      fseek (z80asmfile, fptr, SEEK_SET);	/* reset file pointer to start of expression */
      nextexpr += 1 + 1 + 1 + 1 + i + 1;


      EOL = OFF;		/* reset end of line parsing flag - a line is to be parsed... */

      GetSym ();
      if ((postfixexpr = ParseNumExpr ()) != NULL)
        {			/* parse numerical expression */
          if (postfixexpr->rangetype & NOTEVALUABLE)
            {
              ReportError (CURRENTFILE->fname, 0, 2);
              WriteExprMsg ();
            }
          else
            {
              constant = EvalPfixExpr (postfixexpr);
              patchptr = codearea + CURRENTMODULE->startoffset + offsetptr;	/* absolute patch pos.
                                                                             * in memory buffer */
              switch (type)
                {
                case 'U':
                  *patchptr = (unsigned char) constant;
                  break;

                case 'S':
                  if ((constant >= -128) && (constant <= 255))
                    *patchptr = (char) constant;	/* opcode is stored, now store
                                                     * relative jump */
                  else
                    {
                      ReportError (CURRENTFILE->fname, 0, 7);
                      WriteExprMsg ();
                    }
                  break;

                case 'C':
                  if ((constant >= -32768) && (constant <= 65535))
                    {
                      *patchptr++ = (unsigned short) constant % 256U;
                      *patchptr = (unsigned short) constant / 256U;
                    }
                  else
                    {
                      ReportError (CURRENTFILE->fname, 0, 7);
                      WriteExprMsg ();
                    }

                  if (autorelocate)
                    if (postfixexpr->rangetype & SYMADDR)
                      {
                        /* Expression contains relocatable address */
                        constant = PC - curroffset;

                        if ((constant >= 0) && (constant <= 255))
                          {
                            *relocptr++ = (unsigned char) constant;
                            sizeof_reloctable++;
                          }
                        else
                          {
                            *relocptr++ = 0;
                            *relocptr++ = (unsigned short) (PC - curroffset) % 256U;
                            *relocptr++ = (unsigned short) (PC - curroffset) / 256U;
                            sizeof_reloctable += 3;
                          }

                        totaladdr++;
                        curroffset = PC;
                      }
                  break;

                case 'L':
                  if (constant >= LONG_MIN && constant <= LONG_MAX)
                    for (i = 0; i < 4; i++)
                      {
                        *patchptr++ = constant & 255;
                        constant >>= 8;
                      }
                  else
                    {
                      ReportError (CURRENTFILE->fname, 0, 7);
                      WriteExprMsg ();
                    }
                  break;
                }
            }
          RemovePfixlist (postfixexpr);
        }
      else 
        {
          WriteExprMsg ();
        }
    }
Example #20
0
void 
DEFGROUP (void)
{
  struct expr *postfixexpr;
  long constant, enumconst = 0;

  writeline = OFF;		/* DEFGROUP definitions are not output'ed to listing file */

  while (!feof (z80asmfile) && GetSym () != lcurly)
    {
      Skipline (z80asmfile);
      EOL = OFF;
      ++CURRENTFILE->line;
    }

  if (sym == lcurly)
    {
      while (!feof (z80asmfile) && sym != rcurly)
	{
	  if (EOL == ON)
	    {
	      ++CURRENTFILE->line;
	      EOL = OFF;
	    }
	  else
	    {
	      do
		{
		  GetSym ();
		  switch (sym)
		    {
		    case rcurly:
		    case semicolon:
		    case newline:
		      break;

		    case name:
		      strcpy (stringconst, ident);	/* remember name */
		      if (GetSym () == assign)
			{
			  GetSym ();

			  if ((postfixexpr = ParseNumExpr ()) != NULL)
			    {
			      if (postfixexpr->rangetype & NOTEVALUABLE)
				ReportError (CURRENTFILE->fname, CURRENTFILE->line, 2);
			      else
				{
				  constant = EvalPfixExpr (postfixexpr);
				  enumconst = constant;
				  DefineSymbol (stringconst, enumconst++, 0);
				}
			      RemovePfixlist (postfixexpr);
			    }
			  GetSym ();	/* prepare for next identifier */
			}
		      else
			DefineSymbol (stringconst, enumconst++, 0);
		      break;

		    default:
		      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
		      break;
		    }
		}
	      while (sym == comma);	/* get enum definitions separated by comma in current line */

	      Skipline (z80asmfile);	/* ignore rest of line */
	    }
	}
    }
}
Example #21
0
void 
DEFVARS (void)
{
  struct expr *postfixexpr;

  long offset;
  enum flag globaldefv;

  writeline = OFF;		/* DEFVARS definitions are not output'ed to listing file */
  GetSym ();

  if ((postfixexpr = ParseNumExpr ()) != NULL)
    {				/* expr. must not be stored in relocatable file */
      if (postfixexpr->rangetype & NOTEVALUABLE)
	{
	  ReportError (CURRENTFILE->fname, CURRENTFILE->line, 2);
	  RemovePfixlist (postfixexpr);
	  return;
	}
      else
	{
	  offset = EvalPfixExpr (postfixexpr);	/* offset expression must not contain undefined symbols */
	  RemovePfixlist (postfixexpr);
	}

      if ((offset != -1) && (offset != 0))
	{
	  DEFVPC = offset;
	  globaldefv = ON;
	}
      else
	{
	  if (offset == -1)
	    {
	      globaldefv = ON;
	      offset = DEFVPC;
	    }
	  else
	    {
	      /* offset = 0, use temporarily without smashing DEFVPC */
	      globaldefv = OFF;
	    }
	}
    }
  else
    return;			/* syntax error - get next line from file... */

  while (!feof (z80asmfile) && sym != lcurly)
    {
      Skipline (z80asmfile);

      EOL = OFF;
      ++CURRENTFILE->line;
      GetSym ();
    }

  if (sym == lcurly)
    {
      while (!feof (z80asmfile) && GetSym () != rcurly)
	{
	  if (EOL == ON)
	    {
	      ++CURRENTFILE->line;
	      EOL = OFF;
	    }
	  else
	    offset += Parsedefvarsize (offset);
	}

      if (globaldefv == ON)
	{
	  DEFVPC = offset;
	}
    }
}
Example #22
0
void 
EX (void)
{
  if (GetSym () == lparen)
    if (GetSym () == name)
      if (CheckRegister16 () == REG16_SP)	/* EX  (SP) */
        if (GetSym () == rparen)
          if (GetSym () == comma)
            if (GetSym () == name)
              switch (CheckRegister16 ())
                {
                case REG16_HL:
                  if ( (cpu_type & CPU_RABBIT) )
                    {
                      /* Instruction code changed */
                      *codeptr++ = 0xED;
                      *codeptr++ = 0x54;
                      PC+=2;
                    }
                  else
                    {
                      *codeptr++ = 227;	/* EX  (SP),HL  */
                      ++PC;
                    }
                  break;

                case REG16_IX:
                  *codeptr++ = 221;
                  *codeptr++ = 227;	/* EX  (SP),IX  */
                  PC += 2;
                  break;

                case REG16_IY:
                  *codeptr++ = 253;
                  *codeptr++ = 227;	/* EX  (SP),IY  */
                  PC += 2;
                  break;

                default:
                  ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
                }
            else
              ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
          else
            ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
        else
          ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
      else
        ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
    else
      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
  else if (sym == name)
    {
      switch (CheckRegister16 ())
        {
        case REG16_DE:
          if (GetSym () == comma)	/* EX  DE,HL   */
            if (GetSym () == name)
              if (CheckRegister16 () == 2)
                {
                  *codeptr++ = 235;
                  ++PC;
                }
              else
                ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
            else
              ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
          else
            ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
          break;

        case 4:
          if (GetSym () == comma)	/* EX  AF,AF'   */
            if (GetSym () == name)
              if (CheckRegister16 () == 4)
                {
                  *codeptr++ = 8;
                  ++PC;
                }
              else
                ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
            else
              ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
          else
            ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
          break;

        default:
          ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
        }
    }
  else
    ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
}
Example #23
0
void 
OUT (void)
{
  long reg;

  if ( (cpu_type & CPU_RABBIT) )
    {
      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
      return;
    }

  if (GetSym () == lparen)
    {
      GetSym ();
      if (CheckRegister8 () == 1)
        {			/* OUT (C) */
          if (GetSym () == rparen)
            if (GetSym () == comma)
              if (GetSym () == name)
                switch (reg = CheckRegister8 ())
                  {
                  case 6:
                  case 8:
                  case 9:
                  case -1:
                    ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
                    break;

                  default:
                    *codeptr++ = 237;
                    *codeptr++ = 65 + reg * 8;	/* OUT (C),r  */
                    PC += 2;
                    break;
                  }
              else
                ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
            else
              ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
          else
            ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
        }
      else
        {
          *codeptr++ = 211;
          if (!ExprUnsigned8 (1))
            return;
          PC += 2;
          if (sym == rparen)
            if (GetSym () == comma)
              if (GetSym () == name)
                {
                  if (CheckRegister8 () != 7)
                    ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
                }
              else
                ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
            else
              ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
          else
            ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
        }
    }
  else
    ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
}
Example #24
0
void 
IN (void)
{
  long inreg;

  if ( (cpu_type & CPU_RABBIT) )
    {
      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
      return;
    }
  
  if (GetSym () == name)
    {
      switch (inreg = CheckRegister8 ())
        {
        case 8:
        case 9:
        case -1:
          ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
          break;

        default:
          if (GetSym () != comma)
            {
              ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
              break;
            }
          if (GetSym () != lparen)
            {
              ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
              break;
            }
          GetSym ();
          switch (CheckRegister8 ())
            {
            case 1:
              *codeptr++ = 237;
              *codeptr++ = 64 + inreg * 8;	/* IN r,(C) */
              PC += 2;
              break;

            case -1:
              if (inreg == 7)
                {
                  *codeptr++ = 219;
                  if (ExprUnsigned8 (1))
                    if (sym != rparen)
                      ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
                  PC += 2;
                }
              else
                ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
              break;

            default:
              ReportError (CURRENTFILE->fname, CURRENTFILE->line, 11);
              break;
            }
          break;
        }
    }
  else
    ReportError (CURRENTFILE->fname, CURRENTFILE->line, 1);
}
Example #25
0
void DisplayGrid (void)
{
	printf("_____________________\n");
	printf("| %c | %c | %c | %c | %c |\n", GetSym(grid[0][4]),GetSym(grid[1][4]),GetSym(grid[2][4]),GetSym(grid[3][4]),GetSym(grid[4][4]));
	printf("---------------------\n");
	printf("| %c | %c | %c | %c | %c |\n", GetSym(grid[0][3]),GetSym(grid[1][3]),GetSym(grid[2][3]),GetSym(grid[3][3]),GetSym(grid[4][3]));
	printf("---------------------\n");
	printf("| %c | %c | %c | %c | %c |\n", GetSym(grid[0][2]),GetSym(grid[1][2]),GetSym(grid[2][2]),GetSym(grid[3][2]),GetSym(grid[4][2]));
	printf("---------------------\n");
	printf("| %c | %c | %c | %c | %c |\n", GetSym(grid[0][1]),GetSym(grid[1][1]),GetSym(grid[2][1]),GetSym(grid[3][1]),GetSym(grid[4][1]));
	printf("---------------------\n");
	printf("| %c | %c | %c | %c | %c |\n", GetSym(grid[0][0]),GetSym(grid[1][0]),GetSym(grid[2][0]),GetSym(grid[3][0]),GetSym(grid[4][0]));
	printf("---------------------\n");
	printf("\n");
}
Example #26
0
File: html.cpp Project: pikma/Snap
void THtmlLx::MoveToStrOrEof(const TStr& Str){
  do {
    GetSym();
  } while ((Sym!=hsyEof)&&((Sym!=hsyStr)||(ChA!=Str)));
}
Example #27
0
TLxSym TILx::GetSym(const TFSet& Expect){
  CmtStr.Clr();
  if (!PrevSymStStack.Empty()){
    // symbols already on the stack
    PrevSymStStack.Top().Restore(*this); PrevSymStStack.Pop();
  } else
  if (Expect.In(syLn)){
    // symbol is the whole line string
    if (Ch==TCh::EofCh){
      Sym=syEof;
    } else {
      Str.Clr();
      if (IsBof()){GetCh();}
      while (!ChDef->IsTerm(Ch)){Str.AddCh(Ch); GetCh();}
      bool _IsRetEoln=IsRetEoln; IsRetEoln=true;
      GetSym(TFSet()|syEoln|syEof); Sym=syLn;
      IsRetEoln=_IsRetEoln;
    }
  } else
  if (IsTabSep){
    // symbol is between tab characters
    if (IsBof()){GetCh();}
    if (Ch==TCh::TabCh){ // tab character
      Sym=syTab; GetCh();
    } else
    if (ChDef->IsTerm(Ch)){ // eoln & eof characters
      bool _IsRetEoln=IsRetEoln; IsRetEoln=true; IsTabSep=false;
      GetSym(TFSet()|syEoln|syEof);
      IsRetEoln=_IsRetEoln; IsTabSep=true;
    } else {
      Str.Clr();
      while ((!ChDef->IsTerm(Ch))&&(Ch!=TCh::TabCh)){
        Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh();}
      Sym=syStr; QuoteP=false;
    }
  } else {
    // usual symbol
    while (ChDef->IsSpace(Ch)){GetCh();}
    SymLnN=LnN; SymLnChN=LnChN; SymChN=ChN;

    if (ChDef->IsAlpha(Ch)){
      if (IsUniStr){Sym=syStr;} else {Sym=syIdStr;}
      Str.Clr(); UcStr.Clr(); QuoteP=false;
      do {Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch));}
      while (ChDef->IsAlNum(GetCh()));
      if (!RwStrH.Empty()){
        TStr RwStr=Str; if (!IsCsSens){RwStr=UcStr;}
        int SymKeyId=RwStrH.GetKeyId(RwStr);
        if (SymKeyId!=-1){Sym=TLxSym(int(RwStrH[SymKeyId]));}
      }
      if (Expect.In(syBool)){
        Sym=syBool; IAssert(TBool::IsValStr(Str));
        Bool=TBool::GetValFromStr(Str);
      }
    } else
    if ((Ch=='"')||(Ch=='\'')){
      if (IsUniStr){Sym=syStr;} else {Sym=syQStr;}
      Str.Clr(); UcStr.Clr(); QuoteP=true; QuoteCh=Ch;
      GetCh();
      forever{
        while ((Ch!=QuoteCh)&&(Ch!='\\')&&(Ch!=TCh::EofCh)){
          Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh();}
        if (Ch==TCh::EofCh){
          Sym=syUndef; break;
        } else if (Ch==QuoteCh){
          GetCh(); break;
        } else {
          GetCh();
          switch (Ch){
            case '"': Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break;
            case '\\': Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break;
            case '\'': Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break;
            case '/': Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break;
            case 'b': Str.AddCh('\b'); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break;
            case 'f': Str.AddCh('\f'); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break;
            case 'n': Str.AddCh('\n'); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break;
            case 'r': Str.AddCh('\r'); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break;
            case 't': Str.AddCh('\t'); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break;
            case 'u': {
              // unicode character, represented using 4 hexadecimal digits
              GetCh(); EAssertR(TCh::IsHex(Ch), "Invalid hexadecimal digit in unicode escape");
              int UChCd = TCh::GetHex(Ch);
              GetCh(); EAssertR(TCh::IsHex(Ch), "Invalid hexadecimal digit in unicode escape");
              UChCd = 16 * UChCd + TCh::GetHex(Ch);
              GetCh(); EAssertR(TCh::IsHex(Ch), "Invalid hexadecimal digit in unicode escape");
              UChCd = 16 * UChCd + TCh::GetHex(Ch);
              GetCh(); EAssertR(TCh::IsHex(Ch), "Invalid hexadecimal digit in unicode escape");
              UChCd = 16 * UChCd + TCh::GetHex(Ch);
              // get as UTF8 encoded characters
              TUnicode::EncodeUtf8(UChCd, Str);
			  TUnicode::EncodeUtf8(UChCd, UcStr); }
              GetCh(); break; 
            default: Sym=syUndef; break;
          }
          if (Sym==syUndef){
            throw PExcept(new TExcept("Invalid Escape Sequence in Quoted String"));}
        }
      }
    } else
    if ((ChDef->IsNum(Ch))||(IsSigNum&&((Ch=='+')||(Ch=='-')))){
      Str.Clr(); bool IntP=true;
      do {Str.AddCh(Ch);} while (ChDef->IsNum(GetCh()));
      if (Expect.In(syFlt)){
        if (Ch=='.'){
          Str.AddCh(Ch); IntP=false;
          while (ChDef->IsNum(GetCh())){Str.AddCh(Ch);}
        }
        if ((Ch=='e')||(Ch=='E')){
          Str.AddCh(Ch); GetCh(); IntP=false;
          if ((Ch=='+')||(Ch=='-')){Str.AddCh(Ch); GetCh();}
          while (ChDef->IsNum(Ch)){Str.AddCh(Ch); GetCh();}
        }
      }
      UcStr=Str;
      if (IntP&&(Expect.In(syInt))){
        Sym=syInt; Int=atoi(Str.CStr());
      } else {
        Sym=syFlt; Flt=atof(Str.CStr());
      }
    } else
    if ((Ch==TCh::CrCh)||(Ch==TCh::LfCh)){
      Sym=syEoln;
      if (Ch==TCh::CrCh){if (GetCh()==TCh::LfCh){GetCh();}} else
      if (Ch==TCh::LfCh){if (GetCh()==TCh::CrCh){GetCh();}}
      LnN++; LnChN=0; if (!IsRetEoln){GetSym(Expect);}
    } else
    if (Ch=='/'){
      GetCh();
      if ((IsCmtAlw)&&(Ch=='/')){
        TChA _CmtStr;
        do {_CmtStr+=GetCh();} while (!ChDef->IsTerm(Ch));
        _CmtStr.Pop(); _CmtStr.Trunc();
        if (Ch==TCh::CrCh){
          if (GetCh()==TCh::LfCh){GetCh();}
        } else
        if (Ch==TCh::LfCh){
          if (GetCh()==TCh::CrCh){GetCh();}
        }
        if (IsRetEoln){Sym=syEoln;} else {GetSym(Expect);}
        CmtStr=_CmtStr;
      } else
      if (Ch=='*'){
        TChA _CmtStr;
        do {
          while (GetCh()!='*'){_CmtStr+=Ch;}
          _CmtStr+=GetCh();
        } while (Ch!='/');
        _CmtStr.Pop(); _CmtStr.Pop(); _CmtStr.Trunc();
        GetCh(); GetSym(Expect);
        CmtStr=_CmtStr;
      } else {
        Sym=sySlash;
      }
    } else
    if (Ch==TCh::EofCh){
      Sym=syEof;
    } else {
      switch (Ch){
        case '.':
          if (GetCh()=='.'){Sym=syDPeriod; GetCh();}
          else {Sym=syPeriod;} break;
        case ',': Sym=syComma; GetCh(); break;
        case ':':
          if (GetCh()==':'){Sym=syDColon; GetCh();}
          else {Sym=syColon;} break;
        case ';': Sym=sySemicolon; GetCh(); break;
        case '+': Sym=syPlus; GetCh(); break;
        case '-': Sym=syMinus; GetCh(); break;
        case '*': Sym=syAsterisk; GetCh(); break;
        case '/': Sym=sySlash; GetCh(); break;
        case '%': Sym=syPercent; GetCh(); break;
        case '!': Sym=syExclamation; GetCh(); break;
        case '|': Sym=syVBar; GetCh(); break;
        case '&': Sym=syAmpersand; GetCh(); break;
        case '=': Sym=syEq; GetCh(); break;
        case '<':
          GetCh();
          if (Ch=='='){Sym=syLEq; GetCh();}
          else if (Ch=='>'){Sym=syNEq; GetCh();}
          else {Sym=syLss;} break;
        case '>':
          if (GetCh()=='='){Sym=syGEq; GetCh();}
          else {Sym=syGtr;} break;
        case '?': Sym=syQuestion; GetCh(); break;
        case '#':
          if (IsCmtAlw){
            TChA _CmtStr;
            do {_CmtStr+=GetCh();} while (!ChDef->IsTerm(Ch));
            _CmtStr.Pop(); _CmtStr.Trunc();
            if (Ch==TCh::CrCh){
              if (GetCh()==TCh::LfCh){GetCh();}
            } else
            if (Ch==TCh::LfCh){
              if (GetCh()==TCh::CrCh){GetCh();}
            }
            if (IsRetEoln){Sym=syEoln;} else {GetSym(Expect);}
            CmtStr=_CmtStr;
          } else {
            Sym=syHash; GetCh();
          }
          break;
        case '(': Sym=syLParen; GetCh(); break;
        case ')': Sym=syRParen; GetCh(); break;
        case '[': Sym=syLBracket; GetCh(); break;
        case ']': Sym=syRBracket; GetCh(); break;
        case '{': Sym=syLBrace; GetCh(); break;
        case '}': Sym=syRBrace; GetCh(); break;
        default: Sym=syUndef; GetCh(); break;
      }
    }
  }
Example #28
0
File: html.cpp Project: pikma/Snap
void THtmlLx::MoveToBTagOrEof(const TStr& TagNm){
  do {
    GetSym();
  } while ((Sym!=hsyEof)&&((Sym!=hsyBTag)||(UcChA!=TagNm)));
}
Example #29
0
TSqlDmLxSym TSqlDmLx::GetSym(const TFSet& Expect){
  if (!PrevSymStStack.Empty()){
    // symbols already on the stack
    PrevSymStStack.Top().Restore(*this); PrevSymStStack.Pop();
  } else {
    // usual symbol
    while (ChDef.IsSpace(Ch)){GetCh();}
    SymLnN=LnN; SymLnChN=LnChN; SymChN=ChN;

    if (ChDef.IsAlpha(Ch)){ // name
      Str.Clr(); UcStr.Clr();
      do {Str.AddCh(Ch); UcStr.AddCh(ChDef.GetUc(Ch));}
      while (ChDef.IsAlNum(GetCh()));
      Sym=TSqlDmLxSymStr::GetRwSym(UcStr);
      if (Sym==dsyUndef){Sym=dsyName;}
    } else
    if (Ch=='['){ // bracketed name
      Str.Clr(); UcStr.Clr(); GetCh();
      while ((Ch!=']')&&(Ch!=TCh::EofCh)){
        Str.AddCh(Ch); UcStr.AddCh(ChDef.GetUc(Ch)); GetCh();}
      if (Ch==TCh::EofCh){Sym=dsyUndef;}
      else {Sym=dsyName; GetCh();}
    } else
    if (Ch=='\''){ // string in single quotes
      Str.Clr(); UcStr.Clr(); GetCh();
      while ((Ch!='\'')&&(Ch!=TCh::EofCh)){
        Str.AddCh(Ch); UcStr.AddCh(ChDef.GetUc(Ch)); GetCh();}
      if (Ch==TCh::EofCh){Sym=dsyUndef;}
      else {Sym=dsyStr; GetCh();}
    } else
    if (ChDef.IsNum(Ch)){ // integer or float
      Str.Clr();
      do {Str.AddCh(Ch);} while (ChDef.IsNum(GetCh()));
      if (Ch=='.'){
        Str.AddCh(Ch);
        while (ChDef.IsNum(GetCh())){Str.AddCh(Ch);}
      }
      if ((Ch=='e')||(Ch=='E')){
        Str.AddCh(Ch); GetCh();
        if ((Ch=='+')||(Ch=='-')){Str.AddCh(Ch); GetCh();}
        while (ChDef.IsNum(Ch)){Str.AddCh(Ch); GetCh();}
      }
      UcStr=Str;
      if (Expect.In(syFlt)){Sym=dsyFlt; Flt=atof(Str.CStr());}
      else {Sym=dsyInt; Int=atoi(Str.CStr());}
    } else
    if (Ch=='/'){ // slash or // commenatry or /* */ commentary
      GetCh();
      if (Ch=='/'){
        do {GetCh();} while (!ChDef.IsEof(Ch));
        if (Ch==TCh::CrCh){
          if (GetCh()==TCh::LfCh){GetCh();}
        } else
        if (Ch==TCh::LfCh){
          if (GetCh()==TCh::CrCh){GetCh();}
        }
        GetSym(Expect);
      } else
      if (Ch=='*'){
        do {while (GetCh()!='*'){}} while (GetCh()!='/');
        GetCh(); GetSym(Expect);
      } else {
        Sym=dsySlash;
      }
    } else
    if (Ch=='-'){ // minus or -- commenatry
      GetCh();
      if (Ch=='-'){
        do {GetCh();} while (!ChDef.IsEof(Ch));
        if (Ch==TCh::CrCh){
          if (GetCh()==TCh::LfCh){GetCh();}
        } else
        if (Ch==TCh::LfCh){
          if (GetCh()==TCh::CrCh){GetCh();}
        }
        GetSym(Expect);
      } else {
        Sym=dsyMinus;
      }
    } else
    if (Ch==TCh::EofCh){ // end-of-file
      Sym=dsyEof;
    } else { // other symbols
      switch (Ch){
        case ',': Sym=dsyComma; GetCh(); break;
        case '.':
          if (ChDef.IsNum(GetCh())){
            PutCh('.'); PutCh('0'); return GetSym(Expect);}
          else {Sym=dsyPeriod;}
          break;
        case ';': Sym=dsySemicolon; GetCh(); break;
        case '<':
          GetCh();
          if (Ch=='='){Sym=dsyLEq; GetCh();}
          else if (Ch=='>'){Sym=dsyNEq; GetCh();}
          else {Sym=dsyLss;} break;
        case '=': Sym=dsyEq; GetCh(); break;
        case '>':
          if (GetCh()=='='){Sym=dsyGEq; GetCh();}
          else {Sym=dsyGtr;} break;
        case '+': Sym=dsyPlus; GetCh(); break;
        case '-': Sym=dsyMinus; GetCh(); break;
        case '*': Sym=dsyAsterisk; GetCh(); break;
        case '/': Sym=dsySlash; GetCh(); break;
        case '(': Sym=dsyLParen; GetCh(); break;
        case ')': Sym=dsyRParen; GetCh(); break;
        case '{': Sym=dsyLBrace; GetCh(); break;
        case '}': Sym=dsyRBrace; GetCh(); break;
        default: Sym=dsyUndef; GetCh(); break;
      }
    }
  }

  if ((!Expect.In(Sym))&&(!Expect.Empty())){
   TStr MsgStr=
    TStr("Unexpected symbol (")+Str+") ["+GetFPosStr()+"]";
   throw TExcept::Throw(MsgStr);
  }
  return Sym;
}
Example #30
0
File: html.cpp Project: pikma/Snap
void THtmlLx::MoveToBTag3OrEof(const TStr& TagNm1, const TStr& TagNm2, const TStr& TagNm3){
  do {
    GetSym();
  } while ((Sym!=hsyEof)&&((Sym!=hsyBTag)||((UcChA!=TagNm1)&&(UcChA!=TagNm2)&&(UcChA!=TagNm3))));
}