Пример #1
0
int FindSymbol(char str[],int pos)	/*找到一个符号或括号,进行相应的处理*/
{
	int h,k;
	char word[MAXTOKEN];
	word[0]=str[pos];
	word[1]='\0';
	pos++;
	if ((h=hashtable[Hash(word)])==-1)	/*在lexicon中找不到该符号*/
	{
		printf("表达式中存在不能识别的符号\n");
		return -1;
	}
	else if (Leading()==1)				/*若之前有"("、一元或二元运算符*/
	{
		if (Kind(h)==RIGHTPAREN)		/*当前符号为")"*/
		{
			printf("不应为右括号\n");
			return -1;
		}
		else if (Kind(h)!=BINARYOP)		/*当前符号不为二元运算符,将其添加到infix中*/
			PutToken(h);
		else		/*当前符号为二元运算符*/
		{
			if (strcmp(word,"+")==0);		/*为"+"时,应是一元"+",不做任何事件*/
			else if (strcmp(word,"-")==0)	/*为"-"时,应是一元"-",将"~"添加到infix中*/
				PutToken(hashtable[Hash("~")]);
			else		/*其他二元运算符为非法*/
			{
				printf("  >>二元运算符不正确\n");
				return -1;
			}
		}
	}
	else	/*Leading()=0时*/
	{
		if (Kind(h)==BINARYOP || Kind(h)==RIGHTPAREN) /*将二元运算符或")"添加到infix中*/
			PutToken(h);
		else
		{
			printf("二元运算符不正确\n");
			return -1;
		}
	}
	if ((k=Kind(h))==LEFTPAREN)
		parencount++;
	else if (k==RIGHTPAREN)
		if (--parencount<0)		/*左、右括号不匹配*/
		{
			printf("太多的右括号\n");
			return -1;
		}
	return pos;
}
Пример #2
0
Value_type GetValue(int h)  /*从lexicon[h]获取值*/
{
	if (Kind(h)!=OPERAND)
		printf("  >>不是一个操作数\n");
	else
		return(lexicon[h].info.val);
}
void QtQuickAppWizard::createInstances(ExtensionSystem::IPlugin *plugin)
{
    Core::BaseFileWizardParameters base = baseParameters();
    QList<Core::BaseFileWizardParameters> list;
    Core::BaseFileWizardParameters parameter;

    const QString basicDescription = tr("Creates a Qt Quick 1 application project that can contain "
                                        "both QML and C++ code and includes a QDeclarativeView.\n\n");

    Core::FeatureSet basicFeatures;
    basicFeatures = Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_1);

    parameter = base;
    parameter.setDisplayName(tr("Qt Quick 1 Application (Built-in Elements)"));
    parameter.setDescription(basicDescription + tr("The built-in elements in the QtQuick 1 namespace allow "
                                                   "you to write cross-platform applications with "
                                                   "a custom look and feel.\n\nRequires <b>Qt 4.7.0</b> or newer."));
    parameter.setRequiredFeatures(basicFeatures);
    list << parameter;

    parameter = base;
    parameter.setDisplayName(tr("Qt Quick 2 Application (Built-in Elements)"));
    parameter.setDescription(tr("Creates a Qt Quick 2 application project that can contain "
                                "both QML and C++ code and includes a QQuickView.\n\n"
                                "The built-in elements in the QtQuick 2 namespace allow "
                                "you to write cross-platform applications with "
                                "a custom look and feel.\n\nRequires <b>Qt 5.0</b> or newer."));
    parameter.setRequiredFeatures(Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_2));
    list << parameter;

    parameter = base;
    parameter.setDisplayName(tr("Qt Quick 1 Application for MeeGo Harmattan"));
    parameter.setDescription(basicDescription +  tr("The Qt Quick Components for MeeGo Harmattan are "
                                                    "a set of ready-made components that are designed "
                                                    "with specific native appearance for the MeeGo Harmattan "
                                                    "platform.\n\nRequires <b>Qt 4.7.4</b> or newer, and the "
                                                    "component set installed for your Qt version."));
    parameter.setRequiredFeatures(basicFeatures | Core::Feature(QtSupport::Constants::FEATURE_QTQUICK_COMPONENTS_MEEGO)
                                  | QtSupport::Constants::FEATURE_QT_QUICK_1_1);
    list << parameter;

    parameter = base;
    parameter.setDisplayName(tr("Qt Quick 1 Application (from Existing QML File)"));
    parameter.setDescription(basicDescription +  tr("Creates a deployable Qt Quick application from "
                                                    "existing QML files. All files and directories that "
                                                    "reside in the same directory as the main .qml file "
                                                    "are deployed. You can modify the contents of the "
                                                    "directory any time before deploying.\n\nRequires <b>Qt 4.7.0</b> or newer."));
    parameter.setRequiredFeatures(basicFeatures);
    list << parameter;

    QList<QtQuickAppWizard*> wizardList = Core::createMultipleBaseFileWizardInstances<QtQuickAppWizard>(list, plugin);

    Q_ASSERT(wizardList.count() == 4);

    for (int i = 0; i < wizardList.count(); i++) {
        wizardList.at(i)->setQtQuickKind(Kind(i));
    }
}
Пример #4
0
int Leading()	/*判断是否为开头位置*/
{
	int k;
	if (inlength<=-1)
		return 1;
	else
		return (k=Kind(infix[inlength]))==LEFTPAREN || k==UNARYOP || k==BINARYOP;
}
Пример #5
0
// Initialize the keywords in the given world.
void JS::Token::initKeywords(World &world)
{
    const char *const*keywordName = kindNames + keywordsBegin;
    for (Kind kind = keywordsBegin; kind != keywordsEnd; kind = Kind(kind+1)) {
        String s = widenCString(*keywordName++);
        world.identifiers[s].tokenKind = kind;
    }
}
Пример #6
0
/*attacked() returns 1 if square 'target' is attacked by color 'color'
  and 0 otherwise*/
int attacked(const int target, const int color) {
	int c;
	unsigned __int64 all;
	all = Bitboard(BLACK) | Bitboard(WHITE);

	for (c = 0;c < 16;c++) {
			if (Active(color, c)) {
				assert(Name(color,0)==king);
				if (c>0) assert(Name(color,c)!=king);					
					
					if (Kind(color, c)&table_attack[target - Position(color, c) + 128]) {
							if (IsNoSlide(color, c))
								return 1;

							if ((all&(bit_ray[Position(color, c)][target])) == 0)
								return 1;
							}

					}

			}

	switch (color) {
			case BLACK:

				if (File(target) != FilaA && IsBPawn(target + UP_L))
					return 1;

				if (File(target) != FilaH && IsBPawn(target + UP_R))
					return 1;

				break;

			case WHITE:
				if (File(target) != FilaA && IsWPawn(target + DOWN_L))
					return 1;

				if (File(target) != FilaH && IsWPawn(target + DOWN_R))
					return 1;

				break;

			case EMPTY:
				printf("Bad color board detect in attacked(): %d",color);
				assert(0);
				break;

			default:
				printf("Bad color board detect in attacked(): %d",color);
				assert(0);

				break;
			}

	return 0;
	}
Пример #7
0
    void Variable::SetOwner(Function* ownerFunction)
    {
        if (Kind() != VariableKind::Output)
            LogicError("Variable::SetOwner: Owner can only be set for Output Variables!");

        if (m_dataFields->m_ownerFunction != nullptr)
            LogicError("Variable::SetOwner: An Output Variable whose owner has previously been set, cannot be reset!");

        m_dataFields->m_ownerFunction = ownerFunction;
    }
Пример #8
0
QString Weapon::FullName() const {
    if ( Kind() != WEAPON ) return Block::FullName();

    TrString stoneName = QObject::tr("Pebble");
    TrString ironName  = QObject::tr("Spike");
    switch ( Sub() ) {
    case STONE: return stoneName;
    case IRON:  return ironName;
    case BONE:
    case SKY:
    case SUB_NUT: return TrManager::SubNameUpper(Sub());
    default:      return Block::FullName();
    }
}
Пример #9
0
int FindWord(char str[],int pos)	/*找到一个单词,进行相应的处理*/
{
	int h;
	char word[MAXTOKEN];
	pos=ExtractWord(str,pos,word);
	h=hashtable[Hash(word)];
	if (h!=-1)	/*在哈希表中找到时*/
	{
		if (Leading()==1)
		{
			if (Kind(h)==BINARYOP)
			{
				printf("二元运算符位置不正确\n");
				return -1;
			}
			else
				PutToken(h);
		}
		else
		{
			if (Kind(h)!=BINARYOP)
			{
				printf("应为二元运算符\n");
				return -1;
			}
			else
				PutToken(h);
		}
		return pos;
	}
	else	/*h==-1时*/
	{
		printf("  >>不正确的标识符\n");
		return -1;
	}
}
Пример #10
0
//---------------------------------------------------------------------------
//
void NFTM::Variable::Dump(NFTM::OutputStream *os) {
    if (os) {
        //os->Write("****** Variable::Dump is BROKEN *****\n");
        os->Write("\t\tvar %s is %s%s\n", Name(), IsNull() ? "null " : "", Kind());
        if (!IsNull() && IsText()) {
            char minibuf[64 + 1];
            NFTM::StrCopy(minibuf, u.text->text, 64);
            char *s = minibuf;
            while (*s && *s != '\n') {
                s++;
            }
            *s = 0;
            os->Write("\t\t\t%s\n", minibuf);
        }
    }
}
Пример #11
0
    /*virtual*/ Dictionary Variable::Serialize() const
    {
        if (IsOutput())
        {
            LogicError("Output variables cannot be saved");
        }
        Dictionary dict;

        dict[versionKey] = CurrentVersion();
        dict[typeKey] = s_variableTypeValue;
        dict[uidKey] = Uid();
        dict[kindKey] = static_cast<size_t>(Kind());
        dict[dataTypeKey] = static_cast<size_t>(GetDataType());
        const auto& dynamicAxes = DynamicAxes();
        vector<DictionaryValue> dictionaryValueVector; 
        dictionaryValueVector.reserve(dynamicAxes.size());
        for (const auto& axis : dynamicAxes)
            dictionaryValueVector.push_back(axis);

        dict[dynamicAxisKey] = dictionaryValueVector;
        dict[isSparseKey] = IsSparse();
        if (!Name().empty())
            dict[nameKey] = Name();
        dict[needsGradientKey] = NeedsGradient();
        dict[shapeKey] = Shape();
        if (IsParameter() || IsConstant())
        {
            NDArrayView* value = Value().get();
            if (value == nullptr)
            {
                LogicError("Uninitialized Parameter variable cannot be saved");
            }

            // TODO: add a dictionary value constructor with an rvalue parameter.
            dict[valueKey] = DictionaryValue(*value);
        }
        
        return dict;
    }
Пример #12
0
Value_type EvaluatePostfix()   /*计算后缀表达式值*/
{
	Kind_type type;
	int h;
	Value_type x,y;
	double St[MAXSTACK];
	int top=-1;
	postlength=-1;
	do
	{
		GetToken1(h);
		switch(type=Kind(h))
		{
		case OPERAND:
			top++;
			St[top]=GetValue(h);
			break;
		case UNARYOP:
			x=St[top];
			top--;
			top++;
			St[top]=DoUnary(h,x);
			break;
		case BINARYOP:
			y=St[top];top--;
			x=St[top];top--;
			top++;
			St[top]=DoBinary(h,x,y);
			break;
		case ENDEXPR:
			x=St[top];top--;
			if (top>-1)  /*栈不空,出错*/
				printf("  >>不正确的表达式\n");
			break;
		}
	} while (type!=ENDEXPR);
	return(x);
}
Пример #13
0
//============================================================================
// Execute(stack)
//
bool NFTM::Variable::Execute(NFTM::SymbolTable *symtab, NFTM::Stack *stack) {
    if (stack) {
        NFTM::OutputStream *errlog = symtab->ErrorLog();
        
        switch (kind) {
            case vtFUNCTION:
                if (isNull) {
                    if (errlog) {
                        errlog->Write("\nerror:\t%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
                        errlog->Write("\tunable to execute null word %s\n", Name());
                    }
                    return false;
                }
                return u.function->Execute(symtab, stack);
            case vtBOOLEAN:
                stack->PushBoolean(isNull ? false : u.boolean);
                break;
            case vtNULL:
                stack->PushNull();
                break;
            case vtNUMBER:
            case vtSTACK:
            case vtTEXT:
            case vtOTHER:
                if (errlog) {
                    errlog->Write("\nerror:\t%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
                    errlog->Write("\tinternal error - variable.execute doesn't understand %s (%d)\n", Kind(), kind);
                }
                return false;
        }
    }
    return true;
}
Пример #14
0
void
DataTransferItem::FillInExternalData()
{
  if (mData) {
    return;
  }

  NS_ConvertUTF16toUTF8 utf8format(mType);
  const char* format = utf8format.get();
  if (strcmp(format, "text/plain") == 0) {
    format = kUnicodeMime;
  } else if (strcmp(format, "text/uri-list") == 0) {
    format = kURLDataMime;
  }

  nsCOMPtr<nsITransferable> trans =
    do_CreateInstance("@mozilla.org/widget/transferable;1");
  if (NS_WARN_IF(!trans)) {
    return;
  }

  trans->Init(nullptr);
  trans->AddDataFlavor(format);

  if (mDataTransfer->GetEventMessage() == ePaste) {
    MOZ_ASSERT(mIndex == 0, "index in clipboard must be 0");

    nsCOMPtr<nsIClipboard> clipboard =
      do_GetService("@mozilla.org/widget/clipboard;1");
    if (!clipboard || mDataTransfer->ClipboardType() < 0) {
      return;
    }

    nsresult rv = clipboard->GetData(trans, mDataTransfer->ClipboardType());
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return;
    }
  } else {
    nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
    if (!dragSession) {
      return;
    }

    nsresult rv = dragSession->GetData(trans, mIndex);
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return;
    }
  }

  uint32_t length = 0;
  nsCOMPtr<nsISupports> data;
  nsresult rv = trans->GetTransferData(format, getter_AddRefs(data), &length);
  if (NS_WARN_IF(NS_FAILED(rv) || !data)) {
    return;
  }

  // Fill the variant
  RefPtr<nsVariantCC> variant = new nsVariantCC();

  eKind oldKind = Kind();
  if (oldKind == KIND_FILE) {
    // Because this is an external piece of data, mType is one of kFileMime,
    // kPNGImageMime, kJPEGImageMime, or kGIFImageMime. Some of these types
    // are passed in as a nsIInputStream which must be converted to a
    // dom::File before storing.
    if (nsCOMPtr<nsIInputStream> istream = do_QueryInterface(data)) {
      RefPtr<File> file = CreateFileFromInputStream(istream);
      if (NS_WARN_IF(!file)) {
        return;
      }
      data = do_QueryObject(file);
    }

    variant->SetAsISupports(data);
  } else {
    // We have an external piece of string data. Extract it and store it in the variant
    MOZ_ASSERT(oldKind == KIND_STRING);

    nsCOMPtr<nsISupportsString> supportsstr = do_QueryInterface(data);
    if (supportsstr) {
      nsAutoString str;
      supportsstr->GetData(str);
      variant->SetAsAString(str);
    } else {
      nsCOMPtr<nsISupportsCString> supportscstr = do_QueryInterface(data);
      if (supportscstr) {
        nsAutoCString str;
        supportscstr->GetData(str);
        variant->SetAsACString(str);
      }
    }
  }

  SetData(variant);

#ifdef DEBUG
  if (oldKind != Kind()) {
    NS_WARNING("Clipboard data provided by the OS does not match predicted kind");
  }
#endif
}
Пример #15
0
void LexStream::Dump()
{
    FILE* tokfile;
    // +1 for '\0' +4 for length(".tok")
    char* tokfile_name = new char[FileNameLength() + 5];
    strcpy(tokfile_name, FileName());
    strcat(tokfile_name, StringConstant::U8S_DO_tok);

    if ((tokfile = SystemFopen(tokfile_name, "w")) == NULL)
    {
        Coutput << "*** Cannot open LexStream dump output file "
                << tokfile_name << endl;
        return;
    }

    RereadInput();
    SetUpComments();

    TokenIndex tok = 0;
    for (CommentIndex com = FirstComment(tok);
         com > 0 && com < NumComments() && PrecedingToken(com) == tok; com++)
    {
        fprintf(tokfile, "*%5d ", com);
        fprintf(tokfile, "%s", FileName());
        fprintf(tokfile, ", line %d.%d: ",
                FindLine(comments[com].location),
                FindColumn(comments[com].location - 1) + 1);
        for (const wchar_t* s = CommentString(com); *s; s++)
            fprintf(tokfile, "%c", *s);
        fprintf(tokfile, "\n");
    }
    do
    {
        tok = Gettoken();
        fprintf(tokfile, "%6d ", tok);
        fprintf(tokfile, " %s", FileName());
        fprintf(tokfile, ", %cline %d.%d: %s %s  ",
                (AfterEol(tok) ? '*' : ' '),
                Line(tok), (Kind(tok) == TK_EOF ? 0 : Column(tok)),
                token_type(Kind(tok)),
                (tokens[tok].Deprecated() ? "(d)" : " "));
        for (const wchar_t* s = NameString(tok); *s; s++)
            fprintf(tokfile, "%c", *s);
        fprintf(tokfile, "\n");

        for (CommentIndex com = FirstComment(tok);
             com > 0 && com < NumComments() && PrecedingToken(com) == tok; com++)
        {
            fprintf(tokfile, "*%5d ", com);
            fprintf(tokfile, " %s", FileName());
            fprintf(tokfile, ", line %d.%d: ",
                    FindLine(comments[com].location),
                    FindColumn(comments[com].location - 1) + 1);
            for (const wchar_t* s = CommentString(com); *s; s++)
                fprintf(tokfile, "%c", *s);
            fprintf(tokfile, "\n");
        }
    } while (Kind(tok) != TK_EOF);

    DestroyInput();
    fprintf(tokfile, "\n");
#ifdef UNIQUE_NAMES
    fprintf(tokfile, "\nThe unique names are:\n\n");
    for (int i = 0; i < control.name_table.symbol_pool.length(); i++)
    {
        fprintf(tokfile, "%4d ", i);
        for (const wchar_t* s = control.name_table.symbol_pool[i].name();
             *s; s++)
        {
            fprintf(tokfile, "%c", *s);
        }
        fprintf(tokfile, "\n");
    }
#endif // UNIQUE_NAMES

    if (tokfile)
        fclose(tokfile);
    delete [] tokfile_name;
}
Пример #16
0
void Translate()  /*将中缀表达式infix转换成后缀表达式postfix*/
{
	int St[MAXSTACK];int top=-1;		/*定义栈及栈指针*/
	int h,h1;
	Kind_type type;
	postlength=-1;
	inlength=-1;
	int endright;	/*取1或0.1:表示一个运算符处理完毕(需考虑优先级)*/
	do
	{
		GetToken(h);
		switch(type=Kind(h))
		{
		case OPERAND:	/*为运算符,直接添加到postfix中*/
			PutToken1(h);
			break;
		case LEFTPAREN:	/*为"(",将其进栈*/
			top++;
			St[top]=h;
			break;
		case RIGHTPAREN:	/*为")",出栈运算符添加到postfix中直到遇到"("*/
			h=St[top];top--;
			while (top>-1 && Kind(h)!=LEFTPAREN)
			{
				PutToken1(h);
				h=St[top];top--;
			}
			break;
		case UNARYOP:		/*为一元或二元运算符*/
		case BINARYOP:
			endright=0;
			do
			{
				if (top==-1)	/*栈空*/
					endright=1;
				else if (Kind(St[top])==LEFTPAREN)
					endright=1;
				else if (Priority(St[top])<Priority(h))
					endright=1;
				else if (Priority(St[top])==Priority(h) && Priority(h)==MAXPRIORITY)
					endright=1;
				else
				{
					h1=h;		/*将当前h放在当前高优先运算符的后面*/
					endright=0;
					h=St[top];top--;
					PutToken1(h);
					h=h1;
				}
			} while (endright==0);
			top++;St[top]=h;
			break;
		case ENDEXPR:
			while (top>-1)
			{
				h=St[top];top--;
				PutToken1(h);
			}
			break;
		}
	} while (type!=ENDEXPR);
	PutToken1(0);	/*在postfix中添加ENDEXPR*/
}
Пример #17
0
/*
check_condition() sets tree.check[Side][Ply] if king of side to move is in check
and it sets tree.verify[Ply] if it is in check or under 'x-ray' attack
*/
void check_condition() {
	int c, from, dir, target, tmp_incheck, tmp_xattack, num_pieces, prob_xattack;
	unsigned __int64 all;
	tmp_incheck = 0;
	tmp_xattack = 0;
	target = Position(Side, 0);
	all = Bitboard(BLACK) | Bitboard(WHITE);
	assert(Name(Side,0)==king);
	
	for (c = 0;c < 16;c++) {
			if (Active(Xside, c)) {
				assert(Name(Xside,0)==king);
				if (c>0) assert(Name(Xside,c)!=king);

				/*controlla se il pezzo puo' attaccare*/

					if (Kind(Xside, c)&table_attack[target - Position(Xside, c) + 128]) {
							/*se e' un pezzo no-slide è sotto scacco*/

							if (IsNoSlide(Xside, c)) {
									tmp_incheck++;
									break;
									}
							/*se e' un pezzo slide dobbiamo controllare*/
							if ((all&(bit_ray[Position(Xside, c)][target])) == 0) {
									tmp_incheck++;
									break;
									}

							from = Position(Xside, c);
							dir = direction[target - from + 128];
							num_pieces = 0;
							prob_xattack = 0;
							from += dir;

							while (from != target) {
									if (Piece(from) != no_piece) {
											num_pieces++;

											if (num_pieces == 1 && Color(from) == Side)
												prob_xattack = 1;

											if (num_pieces > 1)
												break;
											}

									from += dir;
									}

							if (num_pieces == 1 && prob_xattack == 1)
								tmp_xattack++;
							}

					}

			}

	switch (Xside) {
			case BLACK:

				if (File(target) != FilaA && IsBPawn(target + UP_L)) {
						tmp_incheck++;
						break;
						}

				if (File(target) != FilaH && IsBPawn(target + UP_R))
					tmp_incheck++;

				break;

			case WHITE:
				if (File(target) != FilaA && IsWPawn(target + DOWN_L)) {
						tmp_incheck++;
						break;
						}

				if (File(target) != FilaH && IsWPawn(target + DOWN_R))
					tmp_incheck++;

				break;

			case EMPTY:
				printf("Bad color board detect in checkcondition(): %d",Xside);
				assert(0);
				break;

			default:
				printf("Bad color board detect in checkcondition(): %d",Xside);
				assert(0);

				break;
			}
	/*E' sotto scacco?*/
	tree.check[Side][Ply] = tmp_incheck;

	/*Nella makemove() dobbiamo verificare la legalita'?*/
	tree.verify[Ply] = tmp_incheck + tmp_xattack;
	}