dword rbBytecode::LoadToken()
{
	CurrentByte = GetCodeOffset();
	ApplyScheduled( CurrentByte );
	CheckBracket( CurrentByte );

	byte b;
	Arc << b;
	dword token = b;

	if( token >= IdExtended )
	{
		if( (token & 0xF0) == IdExtended )
		{
			byte token2;
			Arc << token2;
			token = ((token-IdExtended)<<8) + token2;
		}

		ParseFunc(token);
	}
	else
	{
		ParseCode(token);
	}
	return token;
}
bool Assembler::AssembleFile(char* a_szAssemblyPath, char* a_szOuputScriptPath, char* a_szScriptName)
{
	std::ofstream l_BinaryFile(a_szOuputScriptPath, std::ofstream::binary | std::ofstream::out);
	m_pAssemblyFile = new std::ifstream(a_szAssemblyPath, std::ifstream::in);


	m_szScriptName = a_szScriptName;

	CollectCode();
	CleanCode();

	if(CollectNatives() && ParseCode())
	{
		ConstructBinary(&l_BinaryFile);
	}
	else
	{
		printf("Couldn't parse code !\n");
	}

	
	m_AssemblyLines.clear();
	m_pAssemblyFile->close();
	l_BinaryFile.close();

	delete m_pAssemblyFile;
	return false;
}
Example #3
0
void Template::ResetDictionaryDefaults()
{
	POSITION pos = m_defaults.GetHeadPosition();
	while (pos)
	{
		DefaultInfo& info = m_defaults.GetNext(pos);

		SetEntry(info.m_entry, ParseCode(info.m_value, NULL, this));
	}
}
Example #4
0
AsmCode* Parser::GenerateCode()
{
	ParseDeclaration();
	NodeStatement* st = ParseCode();
	vector<pair<string, int>> onlyVars;
	for(vector<pair<string, int>>::iterator it = mainTable->get_var()->begin(); it != mainTable->get_var()->end(); ++it)
	{
		if(!((*mainTable->find(it->first)).second)->IsConst())
			onlyVars.push_back(pair<string, int> (it->first, ((*mainTable->find(it->first)).second)->GetType()->GetSize()));
	}
	Code->GenerateData(&onlyVars);
	st->Generate(Code);
	return Code;
}
Example #5
0
DWORD CPEParser::Analize()
{
	// первичный анализ должен быть уже выполнен вызовом PrepareAnalize,
	// и заголовки файла получены

	//скорректировать настройки
	// если используется предпочтительный базовый адрес загрузки, то запомнить его
	if(mSettings.Flags & PEPSF_USE_PREFERRED_BASE_ADDRESS) mSettings.BaseAddress=mSettings.PreferredBaseAddress;

	//спроецировать файл в киберпамять
	if(!MapToCyberMemory()) return FILE_PARSER_ERROR_LOADING;
	//проанализировать разделы файла
	AnalizeGeneral();
	AnalizeImport();
	AnalizeExport();
	//дизассемблировать код
	if(!ParseCode()) return FILE_PARSER_ERROR_ANALIZING;

	return FILE_PARSER_ERROR_SUCCESS;
}
Example #6
0
/**
 * Parse a string representation of a keycode.
 * @param start Start of the input.
 * @param end End of the input.
 * @return A valid keycode or 0.
 */
static uint16 ParseKeycode(const char *start, const char *end)
{
	assert(start <= end);
	uint16 keycode = 0;
	for (;;) {
		const char *cur = start;
		while (*cur != '+' && cur != end) cur++;
		uint16 code = ParseCode(start, cur);
		if (code == 0) return 0;
		if (code & WKC_SPECIAL_KEYS) {
			/* Some completely wrong keycode we don't support. */
			if (code & ~WKC_SPECIAL_KEYS) return 0;
			keycode |= code;
		} else {
			/* Ignore the code if it has more then 1 letter. */
			if (keycode & ~WKC_SPECIAL_KEYS) return 0;
			keycode |= code;
		}
		if (cur == end) break;
		assert(cur < end);
		start = cur + 1;
	}
	return keycode;
}
Example #7
0
bool CRTFParser::ParseBlock (const STextFormatDesc &InitFormat, CString *retsError)

//	ParseBlock
//
//	Parses a block and leaves the input position at the first character after
//	the end of the block.

	{
	//	Better be the beginning of a block

	if (*m_pInput++ != '{')
		{
		*retsError = ERR_BRACE_EXPECTED;
		return false;
		}

	//	Keep track of the current format and text

	STextFormatDesc Format = InitFormat;

	//	Keep looping until we hit the end of the block

	bool bBlockStart = true;
	while (*m_pInput != '}')
		{
		//	End of stream

		if (*m_pInput == '\0')
			{
			*retsError = ERR_UNEXPECTED_EOS;
			return false;
			}

		//	If an escape character then parse an op code

		else if (*m_pInput == '\\' || *m_pInput == '/')
			{
			m_pInput++;

			//	If this is the beginning of the block then parse some codes

			if (bBlockStart)
				{
				CString sCode;
				CString sParam;
				if (!ParseCode(&sCode, &sParam, retsError))
					return false;

				//	Interpret code

				if (strEquals(sCode, CODE_BOLD))
					Format.bBold = true;
				else if (strEquals(sCode, CODE_COLOR))
					{
					DWORD dwRGB = (DWORD)strToInt(sParam, 0);
					Format.wColor = CG16bitImage::RGBValue(GetRValue(dwRGB), GetGValue(dwRGB), GetBValue(dwRGB));
					}
				else if (strEquals(sCode, CODE_TYPEFACE))
					Format.sTypeface = sParam;
				else if (strEquals(sCode, CODE_ITALIC))
					Format.bItalic = true;
				else if (strEquals(sCode, CODE_RTF))
					;
				else
					{
					*retsError = strPatternSubst(ERR_UNKNOWN_CODE, sCode);
					return false;
					}
				}

			//	Parse some escape characters

			else
				{
				switch (*m_pInput)
					{
					case '{':
					case '}':
					case '\\':
					case '/':
						AddSpan(CString(m_pInput, 1), Format);
						break;

					case 'n':
						AddSpan(NULL_STR, Format, true);
						break;

					default:
						{
						*retsError = strPatternSubst(ERR_UNKNOWN_CODE, CString(m_pInput, 1));
						return false;
						}
					}

				m_pInput++;
				}
			}

		//	Special characters

		else if (*m_pInput == '\n')
			{
			AddSpan(NULL_STR, Format, true);
			m_pInput++;
			}

		//	If we have an open brace, then we recurse

		else if (*m_pInput == '{')
			{
			if (!ParseBlock(Format, retsError))
				return false;

			bBlockStart = false;
			}

		//	Otherwise, this is some text

		else
			{
			char *pStart = m_pInput;

			//	Find the end of the span

			while (*m_pInput != '\\' && *m_pInput != '/' && *m_pInput != '{' && *m_pInput != '}' && *m_pInput != '\n' && *m_pInput != '\0')
				m_pInput++;

			//	Add the text as a span

			if (pStart != m_pInput)
				AddSpan(CString(pStart, (int)(m_pInput - pStart)), Format);

			bBlockStart = false;
			}
		}

	m_pInput++;

	//	Done

	return true;
	}
Example #8
0
/*
Read the samples in the pcm file looking
for periods of tones and silence
*/
void ParseWav(unsigned char *pcm) {
  unsigned char *pcm_pos;
  unsigned char *end_pcm;
  unsigned int symbol_start;
  unsigned int symbol_end;
  struct pcm_header *p;
  int silence;
  int count;
  short s;
  char Symbols[MAX_SYMBOLS];
  int sp = 0;
  unsigned int symbol_time;
  char output[MAX_SYMBOLS];
  char output2[MAX_SYMBOLS];
  int i;
  int b;
  int first = 1;

  // init some vars
  bzero(Symbols, MAX_SYMBOLS);
  bzero(output, MAX_SYMBOLS);
  sp = 0;
  Bucket[1].valid = 0;
  Bucket[2].valid = 0;
  Bucket[3].valid = 0;
  p = (struct pcm_header *)pcm;

  // calc the end byte of the pcm data
  end_pcm = pcm+12+(p->DataSize);

  // start with the first sample
  pcm_pos = pcm+12;
  symbol_start = 12;
  symbol_end = 0;
  silence = 1;
  count = 0;
  while (pcm_pos < end_pcm && sp < MAX_SYMBOLS-2) {
    // grab the sample's value
    s = *(short *)pcm_pos;

    // see if it's a new silence or a tone
    if ((s > -10 && s < 10) && (!silence || first)) {
      // got a new silence

      // check 50 sample to be sure
      if (++count < 50) {
        pcm_pos+=2;
        continue;
      }

      // see if this is our first symbol
      if (first) {
        silence = 1;
        count = 0;
        first = 0;
        pcm_pos = pcm+12;
        symbol_start = 12;
        symbol_end = 0;
        continue;
      }

      // yep, found new silence, reset our flag vars
      silence = 1;
      count = 0;

      // calc the length of the previous tone symbol
      symbol_end = (int)(pcm_pos-pcm);
      symbol_time = ((symbol_end-(50*2)-symbol_start))/2;

      // get ready for the next symbol
      symbol_start = symbol_end-(50*2);

      // Assign to a symbol bucket
      Symbols[sp++] = AssignToBucket(symbol_time);

    } else if ((s < -10 || s > 10) && (silence || first)) {
      // got a new tone

      // check 50 sample to be sure
      if (++count < 50) {
        pcm_pos+=2;
        continue;
      }

      // see if this is our first symbol
      if (first) {
        silence = 0;
        count = 0;
        first = 0;
        pcm_pos = pcm+12;
        symbol_start = 12;
        symbol_end = 0;
        continue;
      }

      // yep, found new tone, reset our flag vars
      silence = 0;
      count = 0;

      // calc the length of the previous tone symbol
      symbol_end = (int)(pcm_pos-pcm);
      symbol_time = ((symbol_end-(50*2)-symbol_start))/2;

      // get ready for the next symbol
      symbol_start = symbol_end-(50*2);

      // Assign to a symbol bucket
      Symbols[sp++] = AssignToBucket(symbol_time) * -1;
    } else {
      count = 0;
    }
    pcm_pos+=2;
  }

  // handle the last symbol we were processing
  symbol_end = (int)(pcm_pos-pcm);
  symbol_time = ((short)(symbol_end-symbol_start))/2;
  if (!silence) {
    Symbols[sp++] = AssignToBucket(symbol_time);
  }

  // validate the buckets we discovered
  ValidateBuckets();

  // now that we've parsed the tones and silences
  // use that data to build the symbol string
  sp = 0;
  for (i = 0; i < MAX_SYMBOLS-1; i++) {
    if (Symbols[i] == 0) {
      continue;
    }
    // silence
    if (Symbols[i] < 0) {
      b = Symbols[i]*-1;
      if (Bucket[b].gap != '\0') {
        output[sp++] = Bucket[b].gap;
      }

    // tone
    } else {
      b = Symbols[i];
      if (Bucket[b].mark != '\0') {
        output[sp++] = Bucket[b].mark;
      }
    }
  }
  output[sp++] = '\n';

  // parse the symbols back to characters
  ParseCode(output, output2);

  // output the resulting message
  puts(output2);
  puts("\n");

}