Ejemplo n.º 1
0
static bool
ParseLine(Airspaces &airspace_database, TCHAR *line,
          TempAirspaceType &temp_area)
{
  const TCHAR *value;

  // Strip comments
  TCHAR *comment = _tcschr(line, _T('*'));
  if (comment != nullptr)
    *comment = _T('\0');

  // Only return expected lines
  switch (line[0]) {
  case _T('D'):
  case _T('d'):
    switch (line[1]) {
    case _T('P'):
    case _T('p'):
      value = ValueAfterSpace(line + 2);
      if (value == nullptr)
        break;

    {
      GeoPoint temp_point;
      if (!ReadCoords(value, temp_point))
        return false;

      temp_area.points.push_back(temp_point);
      break;
    }

    case _T('C'):
    case _T('c'):
      temp_area.radius = Units::ToSysUnit(fixed(_tcstod(&line[2], nullptr)),
                                          Unit::NAUTICAL_MILES);
      temp_area.AddCircle(airspace_database);
      temp_area.Reset();
      break;

    case _T('A'):
    case _T('a'):
      ParseArcBearings(line, temp_area);
      break;

    case _T('B'):
    case _T('b'):
      return ParseArcPoints(line, temp_area);

    default:
      return true;
    }
    break;

  case _T('V'):
  case _T('v'):
    // Need to set these while in count mode, or DB/DA will crash
    if ((value = StringAfterPrefixCI(SkipSpaces(line + 1), _T("X="))) != nullptr) {
      if (!ReadCoords(value, temp_area.center))
        return false;
    } else if (StringAfterPrefixCI(SkipSpaces(line + 1), _T("D=-"))) {
      temp_area.rotation = -1;
    } else if (StringAfterPrefixCI(SkipSpaces(line + 1), _T("D=+"))) {
      temp_area.rotation = +1;
    }
    break;

  case _T('A'):
  case _T('a'):
    switch (line[1]) {
    case _T('C'):
    case _T('c'):
      value = ValueAfterSpace(line + 2);
      if (value == nullptr)
        break;

      temp_area.AddPolygon(airspace_database);
      temp_area.Reset();

      temp_area.type = ParseType(value);
      break;

    case _T('N'):
    case _T('n'):
      value = ValueAfterSpace(line + 2);
      if (value != nullptr)
        temp_area.name = value;
      break;

    case _T('L'):
    case _T('l'):
      value = ValueAfterSpace(line + 2);
      if (value != nullptr)
        ReadAltitude(value, temp_area.base);
      break;

    case _T('H'):
    case _T('h'):
      value = ValueAfterSpace(line + 2);
      if (value != nullptr)
        ReadAltitude(value, temp_area.top);
      break;

    case _T('R'):
    case _T('r'):
      value = ValueAfterSpace(line + 2);
      if (value != nullptr)
        temp_area.radio = value;
      break;

    default:
      return true;
    }

    break;

  }
  return true;
}
Ejemplo n.º 2
0
void EditorConfig::ParseConfig(const String &filePath)
{
	ClearConfig();

    YamlParser *parser = YamlParser::Create(filePath);
    if(parser)
    {
		YamlNode *rootNode = parser->GetRootNode();
		if(rootNode)
		{
			Vector<YamlNode*> &yamlNodes = rootNode->AsVector();
			int32 propertiesCount = yamlNodes.size();
			for(int32 i = 0; i < propertiesCount; ++i)
			{
				YamlNode *propertyNode = yamlNodes[i];
				if(propertyNode)
				{
					YamlNode *nameNode = propertyNode->Get("name");
					YamlNode *typeNode = propertyNode->Get("type");
					YamlNode *defaultNode = propertyNode->Get("default");
					if(nameNode && typeNode)
					{
						String nameStr = nameNode->AsString();
						String typeStr = typeNode->AsString();
						int32 type = ParseType(typeStr);
						if(type)
						{
							bool isOk = true;
							for(uint32 n = 0; n < propertyNames.size(); ++n)
							{
								if(propertyNames[n] == nameStr)
								{
									isOk = false;
									Logger::Error("EditorConfig::ParseConfig %s ERROR property %d property %s already exists", filePath.c_str(), i, nameStr.c_str());
									break;
								}
							}

							if(isOk)
							{
								properties[nameStr] = new PropertyDescription();
								properties[nameStr]->name = nameStr;
								properties[nameStr]->type = type;
								switch(type)
								{
								case PT_BOOL:
									{
										bool defaultValue = false;
										if(defaultNode)
										{
											defaultValue = defaultNode->AsBool();
										}
										properties[nameStr]->defaultValue.SetBool(defaultValue);
									}
									break;
								case PT_INT:
									{
										int32 defaultValue = 0;
										if(defaultNode)
										{
											defaultValue = defaultNode->AsInt();
										}
										properties[nameStr]->defaultValue.SetInt32(defaultValue);
									}
									break;
								case PT_STRING:
									{
										String defaultValue;
										if(defaultNode)
										{
											defaultValue = defaultNode->AsString();
										}
										properties[nameStr]->defaultValue.SetString(defaultValue);
									}
									break;
								case PT_FLOAT:
									{
										float32 defaultValue = 0.0f;
										if(defaultNode)
										{
											defaultValue = defaultNode->AsFloat();
										}
										properties[nameStr]->defaultValue.SetFloat(defaultValue);
									}
									break;
								case PT_COMBOBOX:
									{
										int32 defaultValue = 0;
										if(defaultNode)
										{
											defaultValue = defaultNode->AsInt();
										}
										properties[nameStr]->defaultValue.SetInt32(defaultValue);

										YamlNode *comboNode = propertyNode->Get("list");
										if(comboNode)
										{
											Vector<YamlNode*> comboValueNodes = comboNode->AsVector();
											int32 comboValuesCount = comboValueNodes.size();
											for(int32 i = 0; i < comboValuesCount; ++i)
											{
												properties[nameStr]->comboValues.push_back(comboValueNodes[i]->AsString());
											}
										}
									}
									break;
                                case PT_COLOR_LIST:
                                    {
                                        int32 defaultValue = 0;
                                        if(defaultNode)
                                        {
                                            defaultValue = defaultNode->AsInt();
                                        }
                                        properties[nameStr]->defaultValue.SetInt32(defaultValue);
                                        
                                        YamlNode *colorListNode = propertyNode->Get("list");
                                        if(colorListNode)
                                        {
                                            Vector<YamlNode*> colorListNodes = colorListNode->AsVector();
                                            int32 colorListValuesCount = colorListNodes.size();
                                            for(int32 i = 0; i < colorListValuesCount; ++i)
                                            {
                                                YamlNode* colorNode = colorListNodes[i];
                                                if(!colorNode || colorNode->GetCount() != 4)
                                                    continue;
                                                
                                                Color color(colorNode->Get(0)->AsFloat()/255.f,
                                                            colorNode->Get(1)->AsFloat()/255.f,
                                                            colorNode->Get(2)->AsFloat()/255.f,
                                                            colorNode->Get(3)->AsFloat()/255.f);

                                                properties[nameStr]->colorListValues.push_back(color);
                                            }
                                        }
                                    }
                                    break;
								}
								propertyNames.push_back(nameStr);
							} //isOk
						}
						else
						{
							Logger::Error("EditorConfig::ParseConfig %s ERROR property %d unknown type %s", filePath.c_str(), i, typeStr.c_str());
						}
					}
					else
					{
						Logger::Error("EditorConfig::ParseConfig %s ERROR property %d type or name is missing", filePath.c_str(), i);
					}
				}
				else
				{
					Logger::Error("EditorConfig::ParseConfig %s ERROR property %d is missing", filePath.c_str(), i);
				}
			}
		} 
		// else file is empty - ok, no custom properties

		parser->Release();
	}
	// else file not found - ok, no custom properties
}
Ejemplo n.º 3
0
CVariant CDBusUtil::ParseType(DBusMessageIter *itr)
{
  CVariant value;
  const char *    string  = NULL;
  dbus_int32_t    int32   = 0;
  dbus_uint32_t   uint32  = 0;
  dbus_int64_t    int64   = 0;
  dbus_uint64_t   uint64  = 0;
  dbus_bool_t     boolean = false;
  double          doublev = 0;

  int type = dbus_message_iter_get_arg_type(itr);
  switch (type)
  {
  case DBUS_TYPE_OBJECT_PATH:
  case DBUS_TYPE_STRING:
    dbus_message_iter_get_basic(itr, &string);
    value = string;
    break;
  case DBUS_TYPE_UINT32:
    dbus_message_iter_get_basic(itr, &uint32);
    value = (uint64_t)uint32;
    break;
  case DBUS_TYPE_BYTE:
  case DBUS_TYPE_INT32:
    dbus_message_iter_get_basic(itr, &int32);
    value = (int64_t)int32;
    break;
  case DBUS_TYPE_UINT64:
    dbus_message_iter_get_basic(itr, &uint64);
    value = (uint64_t)uint64;
    break;
  case DBUS_TYPE_INT64:
    dbus_message_iter_get_basic(itr, &int64);
    value = (int64_t)int64;
    break;
  case DBUS_TYPE_BOOLEAN:
    dbus_message_iter_get_basic(itr, &boolean);
    value = (bool)boolean;
    break;
  case DBUS_TYPE_DOUBLE:
    dbus_message_iter_get_basic(itr, &doublev);
    value = (double)doublev;
    break;
  case DBUS_TYPE_ARRAY:
    DBusMessageIter array;
    dbus_message_iter_recurse(itr, &array);

    value = CVariant::VariantTypeArray;

    do
    {
      CVariant item = ParseType(&array);
      if (!item.isNull())
        value.push_back(item);
    } while (dbus_message_iter_next(&array));
    break;
  }

  return value;
}
Ejemplo n.º 4
0
static
int
W16PrintfCore(
    PPRINTF_BUFFER pBuffer,
    int bMSCompat,
    const wchar16_t* pwszFormat,
    va_list args
    )
{
    size_t sLen = 0;
    const wchar16_t* pwszPos = pwszFormat;
    const wchar16_t* pwszTokenStart = pwszFormat;
    unsigned int dwFlags = 0;
    unsigned int dwLengthModifier = 0;
    unsigned int dwType = 0;
    size_t sWidth = 0;
    ssize_t iPrecision = -1;
    // Enough room for all supported fixed sized types
    char szArgBuffer[100];
    wchar_t wszArgBuffer[1];
    wchar16_t w16szArgBuffer[100];
    // Enough room for all supported format specifiers
    char szFormatBuffer[20];
    char *pszFormatBufferPos = NULL;

    while (*pwszPos)
    {
        if (*pwszPos == '%')
        {
            pBuffer->pfnWriteWc16s(
                    pBuffer,
                    pwszTokenStart,
                    pwszPos - pwszTokenStart);

            pwszPos++;

            // Put the format specifier (% included) into a multibyte
            // string incase regular printf needs to be called
            pszFormatBufferPos = szFormatBuffer;
            *pszFormatBufferPos++ = '%';

            pwszTokenStart = pwszPos;
            dwFlags = ParseFlags(&pwszPos);
            // update multibyte format
            // subtract for % * . * null
            if (pwszPos - pwszTokenStart > sizeof(szFormatBuffer) - 5)
            {
                errno = ENOMEM;
                return -1;
            }
            sLen = wc16stombs(
                    pszFormatBufferPos,
                    pwszTokenStart,
                    pwszPos - pwszTokenStart);
            if (sLen == (size_t)-1)
            {
                return -1;
            }
            pszFormatBufferPos += sLen;

            if (*pwszPos == '*')
            {
                pwszPos++;
                sWidth = va_arg(args, size_t);
            }
            else
            {
                sWidth = (size_t)wc16stoull(pwszPos, &pwszPos, 10);
            }
            *pszFormatBufferPos++ = '*';

            iPrecision = -1;
            if (*pwszPos == '.')
            {
                pwszPos++;
                if (*pwszPos == '*')
                {
                    pwszPos++;
                    iPrecision = va_arg(args, ssize_t);
                }
                else if (*pwszPos != '-')
                {
                    iPrecision = (ssize_t)wc16stoull(pwszPos, &pwszPos, 10);
                }
            }
            *pszFormatBufferPos++ = '.';
            *pszFormatBufferPos++ = '*';

            pwszTokenStart = pwszPos;

            dwLengthModifier = ParseLengthModifier(&pwszPos);
            dwType = ParseType(&pwszPos, &dwType);

            if (pszFormatBufferPos - szFormatBuffer +
                    pwszPos - pwszTokenStart > sizeof(szFormatBuffer) - 1)
            {
                errno = ENOMEM;
                return -1;
            }
            sLen = wc16stombs(
                    pszFormatBufferPos,
                    pwszTokenStart,
                    pwszPos - pwszTokenStart);
            if (sLen == (size_t)-1)
            {
                return -1;
            }
            pszFormatBufferPos += sLen;
            *pszFormatBufferPos = 0;

            if (bMSCompat && (dwType == TYPE_STRING || dwType == TYPE_CHAR))
            {
                if (dwLengthModifier == LENGTH_LONG)
                {
                    dwLengthModifier = LENGTH_W16CHAR_T;
                }
                else if (dwLengthModifier == LENGTH_SHORT)
                {
                    dwLengthModifier = LENGTH_CHAR;
                }
                else
                {
                    if (dwFlags & FLAG_UPPER_CASE)
                    {
                        dwLengthModifier = LENGTH_CHAR;
                    }
                    else
                    {
                        dwLengthModifier = LENGTH_W16CHAR_T;
                    }
                }
            }

            switch (dwType)
            {
                case TYPE_OCTAL:
                case TYPE_UNSIGNED_INTEGER:
                case TYPE_HEX:
                case TYPE_INTEGER:
                    if (dwLengthModifier == LENGTH_LONG_LONG)
                    {
                        long long llArg = va_arg(args, long long);
                        sLen = snprintf(
                                    szArgBuffer,
                                    sizeof(szArgBuffer),
                                    szFormatBuffer,
                                    sWidth,
                                    iPrecision,
                                    llArg);
                    }
                    else
                    {
                        long lArg = va_arg(args, long);
                        sLen = snprintf(
                                    szArgBuffer,
                                    sizeof(szArgBuffer),
                                    szFormatBuffer,
                                    sWidth,
                                    iPrecision,
                                    lArg);
                    }
                    if (sLen > sizeof(szArgBuffer) || (ssize_t) sLen < 0)
                    {
                        errno = ENOMEM;
                        return -1;
                    }
                    pBuffer->pfnWriteMbs(pBuffer, szArgBuffer, sLen);
                    break;

                case TYPE_DOUBLE:
                case TYPE_AUTO_DOUBLE:
                case TYPE_HEX_DOUBLE:
                case TYPE_SCIENTIFIC:
                    if (dwLengthModifier == LENGTH_LONG_DOUBLE)
                    {
                        long double ldArg = va_arg(args, long double);
                        sLen = snprintf(
                                    szArgBuffer,
                                    sizeof(szArgBuffer),
                                    szFormatBuffer,
                                    sWidth,
                                    iPrecision,
                                    ldArg);
                    }
Ejemplo n.º 5
0
ExprNode* Parser :: ParseFactor(){
    ExprNode *root = nullptr;
    Token *token = scan.Get();
    if(isEq(token, _SEPARATION, ";"))
        return 0;
    switch (token->Type){
        case _INTEGER:
            root = new IntNode(token);
            break;

        case _FLOAT:
            root = new FloatNode(token);
            break;

        case _IDENTIFIER:
        {
            Symbol *sym = symStack->find_symbol(token->Value);
            if(!sym && parsingFunc)
                sym = parsingFunc->params->find_symbol(token->Value);
            string exc = "Identifier \"" + token->Value + "\" not defined";
            errorIf(!sym, exc.c_str(), token);
            errorIf(!dynamic_cast<VarSymbol*>(sym) && !dynamic_cast<FuncSymbol*>(sym), "Unknown symbol", token);
            errorIf(!sym, "Identifier is undefined", token);
		
             root = new IdentifierNode(token, dynamic_cast<VarSymbol*>(sym));
			if (dynamic_cast<PointerSymbol*>(sym->getType()))
				root = new PointerNode(root);
			

            if(isEq(scan.GetNext() ,_SEPARATION ,"("))
                root = ParseFuncCall(root);
            
            //scan.Next();
            return root;
        }

        case _CHAR:
            root = new CharNode(token);
            break;

        case _STRING:

            root = new StringNode(token);
			root->SetIndex(++index);
            stringConsts.push_back(dynamic_cast<StringNode*>(root));
            break;

        case _KEYWORD:
        {

            string kw = token->Value;
            if(kw == "printf" || kw == "scanf"){
                errorIf( scan.GetNext()->Value != "(", "Open bracket expected", token);
                scan.Next();
                StringNode *format = dynamic_cast<StringNode*>(ParseExpr(priorityTable[","] + 1));
                errorIf(!format, "Expected string format", token);
                IONode *node = new IONode(dynamic_cast<Token*>(token), format);
                if(scan.Get()->Value == ","){
                    scan.Next();
                    while(true){
                        ExprNode *arg = ParseExpr(priorityTable[","] + 1);
                        errorIf (!arg, "Argument expected", token);
                        node->addArg(arg);
                        if(scan.Get()->Value == ")")
                            break;
                        if(scan.Get()->Value == ",")
                            scan.Next();
                    }
                }
                scan.Next();
                root = node;
            }
            else if(kw == "char" || kw == "int" || kw == "float"){
               // scan.Next();
                SymbolType* type = ParseType();
                errorIf(isEq(scan.Get(), _SEPARATION, "("), "Expected open bracket '('", token);
                scan.Next();
                root = new CastNode(token, ParseExpr(), type);
                // errorIf((isEq(scan.GetNext(), _SEPARATION, ")") && !scan.isEnd()), "Expected closing bracket", token);
            }
            else
                throw MyException("You can use keywords just such as char, int and float in expressions");
        }
            break;




        case _OPERATION:
			if (token->Value == "*"){
				scan.Next();
				auto temp = ParseExpr(priorityTable["--"]);
			//	if (dynamic_cast<PointerNode*>(temp))
//				root = dynamic_cast<PointerNode*>(temp)->name;
	//				root = temp;
		//		else
					root = new PointerNode(temp);
				
			}else
				
            if(unary[token->Value]){
                scan.Next();
                root = new UnOpNode(token, ParseExpr(priorityTable["--"]));
            } else
                throw MyException("Wrong expression", token);
            break;

        case _SEPARATION :
            if(isEq(scan.Get(), _SEPARATION, "(")){
                scan.Next();
                root = ParseExpr();
                if(dynamic_cast<CastNode*>(root)){
                    return root;
                }
                if(!isEq(scan.Get(), _SEPARATION, ")"))
                    throw MyException("Expected closing bracket");
            }
            else
                throw MyException("Wrong expression", token);
            break;
    }
    if (!(token->Type == _OPERATION && unary[token->Value]) && token->Value != "printf" && token->Value != "scanf")
        scan.Next();
    root->getType();
    return root;
}
Ejemplo n.º 6
0
SymProc* Parser::ProcFunc(bool isFunc)
{
	t = sc.GetNextToken();
	SymType* Type = NULL;
	SymProc* sub = NULL;
	if (t.GetType() != identifier)
		throw Error("incorrect procedure name", t);
	SymTable* argTable = NULL;
	vector<string>* argNames = new vector<string>;
	_Table::iterator it = table->find(t.GetValue());
	string name = t.GetValue();
	t = sc.GetNextToken();
	argTable = ParseArguments(argNames);
	TableStack.PushTable(argTable);
	if (isFunc)
	{
		if (t.GetValue() != ":")
			throw Error("type expected", t);
		Type = ParseType(false);
		t = sc.GetNextToken();
	}
	t = RequireToken(";", "\";\" expected");
	if (it != table->end())
	{
		if (!(it->second->IsProc()) || !(((SymProc*)it->second)->IsForward()))
			throw Error("incorrect procedure definition", t);
		SymTable* argTableF = ((SymProc*)it->second)->GetArgTable();
		vector<string>* argNamesF = ((SymProc*)it->second)->GetArgNames();
		for (size_t i=0; i<argNames->size(); ++i)
		{
			if ((*argNames)[i] != (*argNamesF)[i] ||
				!SymComp(argTable->find((*argNames)[i])->second , argTableF->find((*argNamesF)[i])->second))
				throw Error("Header does not match previouse definition", t);
		}
		if (isFunc)
			sub = ParseProcDecl(name, argNames, argTable, true, Type);
		else
			sub = ParseProcDecl(name, argNames, argTable, false, Type);
		t = RequireToken(";", "\";\" expected");
	}
	else
	{
		if (t.GetValue() == "forward")
		{
			t = sc.GetNextToken();
			if (t.GetValue() != ";")
				throw Error("\";\" expected", t);
			if (isFunc)
			{
				sub = new SymFunc(name, argNames, argTable, NULL, true, NULL);
				((SymFunc*)sub)->SetType(Type);
			}
			else
				sub = new SymProc(name, argNames, argTable, NULL, true);
			sub->print(os, false);
			table->insert(pair<string, SymProc*> (name, sub));
			TableStack.PopTable();
		}
		else
		{
			sub = ParseProcDecl(name, argNames, argTable, isFunc, Type);
			if (isFunc)
				((SymFunc*)sub)->SetType(Type);
			sub->GetBody()->print(os, 0);
		}
		t = sc.GetNextToken();
	}
	return sub;
}
Ejemplo n.º 7
0
ExprNode* Parser  :: ParseDeclaration(SymbolType* sym_type){
    if (isEq(scan.Get(), _SEPARATION, ";")){
        scan.Next();
        return nullptr;
    }


    SymbolType* t_symbol;
    if (!sym_type) {
        t_symbol = ParseType();
    }else
        t_symbol = sym_type;

    VarSymbol* var = nullptr;
    BinOpNode *node = nullptr;
    while(true){
        Token *token;

        token = scan.Get();
        
        if(isEq(token, _SEPARATION, ";" )&& (t_symbol->isStruct() || dynamic_cast<TypedefSymbol*>(t_symbol)))
            break;

        if (isEq(scan.Get(), _SEPARATION,"("))
            var =  ParseComplexDeclaration(t_symbol);
        else
            var = ParseIdentifier(t_symbol);

        if(symStack->tables.back()->find_symbol(var->name) == 0)
            symStack->add_symbol(var);


        if(isEq(scan.Get(), _OPERATION, "=")){
            Token *asgn = scan.Get();
            scan.Next();
            ExprNode* Assing_operand = ParseExpr(priorityTable[","] + 1);

            node = new BinOpNode(asgn, new IdentifierNode(token, var), Assing_operand);
            if(dynamic_cast<ConstSymbolType*> (var->getType()))
                errorIf(!var->getType()->getType()->canConvertTo(node->right->getType()),"Cannot perform conversion",scan.Get() );
            else
                node->getType();
            blocks.top()->AddStatement(node);

        }
        if(isEq(scan.Get() ,_SEPARATION, ";") || isEq(scan.Get() ,_SEPARATION, "{"))
            break;
        
        errorIf(!isEq(scan.Get(), _OPERATION, ","), "Comma Expected");
        scan.Next();
    }
    if(isEq (scan.Get(),_SEPARATION,"{")){

        FuncSymbol *func = dynamic_cast<FuncSymbol*>(var->type);
        errorIf(!func, "Unexpected brace", scan.Get());
        errorIf((symStack->tables.size() != 1), "Can not define the function in the block", scan.Get());
        parsingFunc = func;
        func->body = ParseBlock();
        parsingFunc = 0;
        CheckReturn(func);

        if(func->name == "main")
            main_func = func;
        scan.Next();

    }
    else
        scan.Next();
    return node;
}
Ejemplo n.º 8
0
static bool
ParseLine(Airspaces &airspace_database, const TCHAR *line,
          TempAirspaceType &temp_area)
{
  const TCHAR *value;

  // Only return expected lines
  switch (line[0]) {
  case _T('A'):
  case _T('a'):
    switch (line[1]) {
    case _T('C'):
    case _T('c'):
      value = value_after_space(line + 2);
      if (value == NULL)
        break;

      if (!temp_area.Waiting)
        temp_area.AddPolygon(airspace_database);

      temp_area.reset();

      temp_area.Type = ParseType(value);
      temp_area.Waiting = false;
      break;

    case _T('N'):
    case _T('n'):
      value = value_after_space(line + 2);
      if (value != NULL)
        temp_area.Name = value;
      break;

    case _T('L'):
    case _T('l'):
      value = value_after_space(line + 2);
      if (value != NULL)
        ReadAltitude(value, &temp_area.Base);
      break;

    case _T('H'):
    case _T('h'):
      value = value_after_space(line + 2);
      if (value != NULL)
        ReadAltitude(value, &temp_area.Top);
      break;

    default:
      return true;
    }

    break;

  case _T('D'):
  case _T('d'):
    switch (line[1]) {
    case _T('A'):
    case _T('a'):
      CalculateSector(line, temp_area);
      break;

    case _T('B'):
    case _T('b'):
      CalculateArc(line, temp_area);
      break;

    case _T('C'):
    case _T('c'):
      temp_area.Radius = Units::ToSysUnit(fixed(_tcstod(&line[2], NULL)),
                                          unNauticalMiles);
      temp_area.AddCircle(airspace_database);
      temp_area.reset();
      break;

    case _T('P'):
    case _T('p'):
      value = value_after_space(line + 2);
      if (value == NULL)
        break;

    {
      GeoPoint TempPoint;

      if (!ReadCoords(value, TempPoint))
        return false;

      temp_area.points.push_back(TempPoint);
      break;
    }
    default:
      return true;
    }

    break;

  case _T('V'):
  case _T('v'):
    // Need to set these while in count mode, or DB/DA will crash
    if (string_after_prefix_ci(&line[2], _T("X="))) {
      if (!ReadCoords(&line[4],temp_area.Center))
        return false;
    } else if (string_after_prefix_ci(&line[2], _T("D=-"))) {
      temp_area.Rotation = -1;
    } else if (string_after_prefix_ci(&line[2], _T("D=+"))) {
      temp_area.Rotation = +1;
    }
  }

  return true;
}
Ejemplo n.º 9
0
DeclaracionFuncion* Sintactico::ParseFunctionDeclaration()
{
	if ( proximo_token.GetTipo() == kw_procedimiento )
	{
		proximo_token = analizador_lexico->ObtenerSiguienteToken();

		if ( proximo_token.GetTipo() == id )
		{
			string nom_procedimiento = proximo_token.GetLexema();
			proximo_token = analizador_lexico->ObtenerSiguienteToken();

			InformacionSemantica::GetInstance()->SetContexto(nom_procedimiento);
			InformacionInterpretacion::GetInstance()->SetContexto(nom_procedimiento);

			list<Parametro*> lista_params = ParseProcedureParam();
			ListaVariables* lista_vars = ParseVariableDeclarations();

			Sentencia* cuerpo_funcion = ParseCompoundStatement();

			//PENDIENTE: Verificar si es correcto

			
			list<Parametro*>::iterator it = lista_params.begin();

			for ( ; it != lista_params.end() ; it++ )
			{
				lista_vars->insert((*it)->GetNombre(),(*it)->GetTipo() );
			}

			InformacionInterpretacion::GetInstance()->InicializarVariables(nom_procedimiento,lista_vars);
			return new DeclaracionFuncion(nom_procedimiento,lista_params,cuerpo_funcion,NULL);
		}
		else
			throw SyntaxException("No se encontro un id valido",analizador_lexico->GetLineaActual());
	}
	else if ( proximo_token.GetTipo() == kw_funcion )
	{
		proximo_token = analizador_lexico->ObtenerSiguienteToken();
		if ( proximo_token.GetTipo() == id )
		{
			string nom_funcion = proximo_token.GetLexema();
			proximo_token = analizador_lexico->ObtenerSiguienteToken();

			list<Parametro*>lista_params = ParseFunctionParam();
			Tipo* t = ParseType();

			if ( proximo_token.GetTipo() == punt_puntocoma )
			{
				proximo_token = analizador_lexico->ObtenerSiguienteToken();
				InformacionSemantica::GetInstance()->SetContexto( nom_funcion );
				InformacionInterpretacion::GetInstance()->SetContexto(nom_funcion);
				ListaVariables* lista_vars = ParseVariableDeclarations();


				Sentencia* cuerpo_funcion = ParseCompoundStatement();

				list<Parametro*>::iterator it = lista_params.begin();
				
				for ( ; it != lista_params.end() ; it++ )
				{
					lista_vars->insert((*it)->GetNombre(),(*it)->GetTipo() );
				}

				InformacionSemantica::GetInstance()->InsertarVarEnContexto(nom_funcion,nom_funcion,t);

				//lista_vars->insert(nom_funcion,t);
				InformacionInterpretacion::GetInstance()->InicializarVariables(nom_funcion,lista_vars);
				return new DeclaracionFuncion(nom_funcion,lista_params,cuerpo_funcion,t);
			}
			else
				throw SyntaxException("Falta un punto y coma",analizador_lexico->GetLineaActual());
		}
		else
			throw SyntaxException("Falta el id",analizador_lexico->GetLineaActual());
	}
	else
		throw SyntaxException("Se esperaba una declaracion de funcion o procedimiento",analizador_lexico->GetLineaActual());

	//InformacionInterpretacion::GetInstance()->SetContexto("@GLOBAL");
}
Ejemplo n.º 10
0
Tipo* Sintactico::ParseType()
{
	switch ( proximo_token.GetTipo() )
	{
	case id:
		{
			
			string nom_tipo = proximo_token.GetLexema();
			proximo_token = analizador_lexico->ObtenerSiguienteToken();
			map<string,Tipo*>tablaTipos = InformacionSemantica::GetInstance()->GetTablaTipos();
			map<string,Tipo*>::iterator it;
			it = tablaTipos.find(nom_tipo);

			if ( it == tablaTipos.end() )
				throw SemanticException("El tipo " +nom_tipo+" no esta definido");
			return it->second;
		}
		
	case kw_array:
		proximo_token = analizador_lexico->ObtenerSiguienteToken();
		if ( proximo_token.GetTipo() == punt_corchizq )
		{
			proximo_token = analizador_lexico->ObtenerSiguienteToken();
			list<LimitesRango*> dim_list = ParseDimensionList();

			if ( proximo_token.GetTipo() == punt_corchder )
			{
				proximo_token = analizador_lexico->ObtenerSiguienteToken();

				if ( proximo_token.GetTipo() == kw_of )
				{
					proximo_token = analizador_lexico->ObtenerSiguienteToken();
					Tipo* t = ParseType();

					return new Arreglo(dim_list,t);
				}
				else
					throw SyntaxException("No se encontro la kw OF",analizador_lexico->GetLineaActual());

			}
			else
				throw SyntaxException("No se encontro el token de corchete derecho",analizador_lexico->GetLineaActual());
		}
		else
			throw SyntaxException("No se encontro el token de corchete izquierdo",analizador_lexico->GetLineaActual());
		break;

	case kw_record:
		{
			proximo_token = analizador_lexico->ObtenerSiguienteToken();
			ListaVariables* lista_var = ParseVariableDeclarationList();

			if ( proximo_token.GetTipo() == kw_end )
				proximo_token = analizador_lexico->ObtenerSiguienteToken();
			else
				throw SyntaxException("No se encontro la kw END",analizador_lexico->GetLineaActual());

			return new Registro(lista_var);
		}

	case kw_entero:
		{
			proximo_token = analizador_lexico->ObtenerSiguienteToken();
			map<string,Tipo*>tablaTipos = InformacionSemantica::GetInstance()->GetTablaTipos();
			map<string,Tipo*>::iterator it;
			it = tablaTipos.find("INTEGER");
			return it->second;
		}

	case kw_real:
		{
			proximo_token = analizador_lexico->ObtenerSiguienteToken();
			map<string,Tipo*>tablaTipos = InformacionSemantica::GetInstance()->GetTablaTipos();
			map<string,Tipo*>::iterator it;
			it = tablaTipos.find("REAL");
			return it->second;
		}

	case kw_string:
		{
			proximo_token = analizador_lexico->ObtenerSiguienteToken();
			map<string,Tipo*>tablaTipos = InformacionSemantica::GetInstance()->GetTablaTipos();
			map<string,Tipo*>::iterator it;
			it = tablaTipos.find("STRING");
			return it->second;
		}

	case kw_bool:
		{
			proximo_token = analizador_lexico->ObtenerSiguienteToken();
			map<string,Tipo*>tablaTipos = InformacionSemantica::GetInstance()->GetTablaTipos();
			map<string,Tipo*>::iterator it;
			it = tablaTipos.find("BOOLEAN");
			return it->second;
		}

	case kw_char:
		{
			proximo_token = analizador_lexico->ObtenerSiguienteToken();
			map<string,Tipo*>tablaTipos = InformacionSemantica::GetInstance()->GetTablaTipos();
			map<string,Tipo*>::iterator it;
			it = tablaTipos.find("CHAR");
			return it->second;
		}
	default:
		throw SyntaxException("Token de tipo invalido",analizador_lexico->GetLineaActual());

	}//FIN switch
}
Ejemplo n.º 11
0
asCScriptNode *asCParser::ParseParameterList()
{
	asCScriptNode *node = new asCScriptNode(snParameterList);

	sToken t1;
	GetToken(&t1);
	if( t1.type != ttOpenParanthesis )
	{
		Error(ExpectedToken("("), &t1);
		return node;
	}

	node->UpdateSourcePos(t1.pos, t1.length);

	GetToken(&t1);
	if( t1.type == ttCloseParanthesis )
	{
		node->UpdateSourcePos(t1.pos, t1.length);

		// Statement block is finished
		return node;
	}
	else
	{
		RewindTo(&t1);

		for(;;)
		{
			// Parse data type
			node->AddChildLast(ParseType(true));
			if( isSyntaxError ) return node;

			node->AddChildLast(ParseTypeMod(true));
			if( isSyntaxError ) return node;

			// Parse identifier
			GetToken(&t1);
			if( t1.type == ttIdentifier )
			{
				RewindTo(&t1);

				node->AddChildLast(ParseIdentifier());
				if( isSyntaxError ) return node;

				GetToken(&t1);
			}

			// Check if list continues
			if( t1.type == ttCloseParanthesis )
			{
				node->UpdateSourcePos(t1.pos, t1.length);

				return node;
			}
			else if( t1.type == ttListSeparator )
				continue;
			else
			{
				Error(ExpectedTokens(")", ","), &t1);
				return node;
			}
		}
	}
	return 0;
}