Beispiel #1
0
void factor()
{
    void expression();
    if (syn == 10 || syn == 11)
    {
        scaner();
    }
    else if ( syn == 27)
    {
        scaner();
        expression();
        if (syn == 28)
        {
            scaner();
        }
        else
        {
            printf("\")\"错误");
            kk = 1;
        }
    }
    else
    {
        printf("输出表达式错误!");
        kk = 1;
    }
    return;
}
Beispiel #2
0
void statement()
{
    void expression();
    if ( syn == 10)
    {
        scaner();
        if (syn == 18)
        {
            scaner();
            expression();

        }
        else
        {
            printf("赋值号错误!");
            kk = 1;
        }
    }
    else
    {
        printf("语句错误!");
        kk = 1;
    }
    return ;
}
Beispiel #3
0
void errorHandler(){

	if(!endFlag) printf("%s", line);

	if(syn==10) {
		printf("yucu error");
		kk = 1;
	}

	if(syn==6 && !endFlag){
	    printf("yucu error");
		kk = 1;
	}

	while(!(syn==26 || syn==6)){
		scaner();
	}

	if(syn==6 && endFlag) {
		kk = 1;
		return;
	}
	scaner();

	statement();
}
Beispiel #4
0
void lrparser()
{
    void yucu();
    if (syn == 1)
    {
        scaner();
        yucu();
        if (syn == 6)
        {
            scaner();
            if (syn == 0 && (kk == 0))
            {
                printf("success!");
            }
            else
            {
                if (kk!= 1)
                {
                    printf("缺end!");
                    kk = 1;

                }
                else
                {
                    printf("begin!");
                    kk = 1;
                }
                return;
            }
        }
    }
}
//正常情况下使用的 词法扫描器,返回新扫描到的词,Syn 返回返回词的 种别码
WORD* LexicalScanner(int &Syn){
    WORD* oneword = new WORD;
    oneword = scaner();
    Syn = oneword->typenum;
    if(Syn==-1)        //Syn=-1时为种别码识别错误时的值
    {
        printf("\nLine [%3d] error:无法识别 %s\n",currentLine,oneword->word);
        cError++;
        oneword = scaner();
        Syn = oneword->typenum;

    }
    else if(Syn ==-2) //Syn=-2时为由一个'/'导致的注释错误
    {
        printf("\nLine [%3d] error:存在多余符号'/' 或者 由仅有的一个'/'导致的错误注释 \n",
                currentLine-1,oneword->word);
        cError++;
        oneword = scaner();
        Syn = oneword->typenum;
    }
    if(Syn==1001){
        printf("\nLine [%3d] error:注释没有结尾\n",currentLine);
        cError++;
    }

    return (oneword);
}
Beispiel #6
0
void factor(){
	
	if(syn == 10 || syn == 11){
		scaner();
		return ;
	}else if(syn == 27){
		scaner();
		expression();

		if(syn == 28){
			scaner();
		}else{
			printf(") error");
			kk = 1;
			errorHandler();
		}

	}else{
		printf("factor expression error");
		kk = 1;
		errorHandler();

	}	

	return ;

}
Beispiel #7
0
long Cx_StringTable::LoadFiles(const std::wstring& path)
{
    if (path.empty())
    {
        return 0;
    }

    long count = 0;
    std::vector<std::wstring> files;
    x3::CScanFilesByExtension scaner(&files, L".xml");

    x3::ScanFiles(&scaner, path.c_str(), false);
    m_loaded = true;

    std::vector<std::wstring>::const_iterator it = files.begin();
    for (; it != files.end(); ++it)
    {
        if (RegisterFile(*it) > 0)
        {
            count++;
        }
    }
    
    if (0 == count && m_groups.empty())
    {
        X3LOG_INFO2(L"@StringTable:IDS_NO_STRFILE", path);
    }

    return count;
}
Beispiel #8
0
void MyRobot::scaner_turn_around()
{
    // Get and enable the camera device
    _forward_camera = getCamera("camera_f");
    _forward_camera->enable(_time_step);
    // Get current image from forward camera
    const unsigned char *image = _forward_camera->getImage();

    const double *compass_val = _my_compass->getValues();
    _compass_angle = convert_bearing_to_degrees(compass_val);
    //If the robot detect something green.
    if (scaner(image) > 20)
    {
        /*Finded angle person, if it is the first person we will safe this angle in _compass_angle_green[1]
        if its the second it will be saved in _compass_angle_green[0]*/
        _compass_angle_green[0] = _compass_angle;
    }
    else
    {
        _mode = FAST_TURN_AROUND;
        if (_compass_angle_green[0] != 1000.0)
        {
            if (_compass_angle_green[1] == 1000.0)
            {
                _compass_angle_green[1] = _compass_angle_green[0]-2;
                _compass_angle_green[0] = 1000.0;
            }
        }
    }
    if(_compass_angle_green[0]!=1000.0 && _compass_angle_green[1]!=1000.0){

        _mode = STOP;
    }
}
//出错情况下使用的 词法扫描器,返回新扫描到的词,Syn 返回返回词的 种别码
//扫描跳至下一个  } 的地方 或者是特殊句型开始处
WORD* ScanWithErrorToBlockEnd(int &Syn)
{
    WORD* oneword = new WORD;
    oneword = scaner();
    Syn = oneword->typenum;

    //扫描不到 } ,则继续扫描
    while( Syn != 39 )//}
    {
        if(Syn==1000)break; //如果程序结束了,跳出扫描
        oneword = scaner();
        Syn = oneword->typenum;
    }

    return (oneword);
}
//出错情况下使用的 词法扫描器,返回新扫描到的词,Syn 返回返回词的 种别码
//扫描跳至下一个 ; 或者 } 的地方 或者是特殊句型开始处
WORD* ScanWithError(int &Syn)
{
    WORD* oneword = new WORD;
    oneword = scaner();
    Syn = oneword->typenum;

    //扫描不到 ; 或者 } 的地方 或者是特殊句型开始处,则继续扫描
    while( !(Syn==41 || Syn== 39|| (Syn==14 || Syn==20 || Syn==22)) )
    {
        if(Syn==1000)break; //如果程序结束了,跳出扫描
        oneword = scaner();
        Syn = oneword->typenum;
    }

    return (oneword);
}
long Cx_StringTable::LoadFiles(const std::wstring& path)
{
	long count = 0;
	std::vector<std::wstring> files;
	CScanFilesByExtension scaner(&files, L".xml");

	ScanFiles(&scaner, path.c_str(), false);
	m_loaded = true;

	std::vector<std::wstring>::const_iterator it = files.begin();
	for (; it != files.end(); ++it)
	{
		if (RegisterFile(*it) > 0)
		{
			count++;
		}
	}
	
	if (0 == count)
	{
		LOG_INFO2(LOGHEAD L"IDS_NO_STRFILE", path);
	}

	return count;
}
Beispiel #12
0
void expression()
{
	term();
	while(syn==13 || syn==14)   //'+'|'-'
	{
		scaner();
		term();
	}
}
Beispiel #13
0
void yucu()
{
	statement();
	while(syn==26)		//';'
	{
		scaner();
		statement();
	}
}
Beispiel #14
0
void expression(){

	term();
	while(syn == 13 || syn == 14){
		scaner();
		term();
	}
	return ;
}
Beispiel #15
0
void term()
{
	factor();
	while(syn==15 || syn==16)   //'*'|'/'
	{
		scaner();
		factor();
	}
}
Beispiel #16
0
void term(){

	factor();
	while(syn == 15 || syn == 16){
		scaner();
		factor();
	}

	return ; 
}
Beispiel #17
0
void yucu()
{
    void statement();
    statement();
    while (syn == 26)
    {
        scaner();
        statement();
    }
    return;
}
Beispiel #18
0
void statement()
{
	if(syn==10)      //字母
	{
		scaner();
		if(syn==18)  //'='
		{
			scaner();
			expression();
		}
		else
		{
			kk=1;
			return;
		}
	}
	else
	{
		kk=1;
		return;
	}
}
Beispiel #19
0
void yucu(){

	statement();
	while(syn == 26){
		scaner();
		statement();
	}

	endFlag = 1;
	errorHandler();

	return ;
}
Beispiel #20
0
         void CIniImpl::parse()
         {
            TRACE_FUN( Routine, "CIniImpl::parse" );

            CLexScaner scaner( &stream() );
            CCategoryParserDriver driver( file(),
                                          scaner,
                                          category(),
                                          synchronization(),
                                          errorRepository() );

            parser theParser( driver );
            theParser.parse();
         }
Beispiel #21
0
void lrparser()
{   
	if(syn==1)		//"main"
	{
		scaner();
		if(syn==27){	//'('
			scaner();
			if(syn==28){	//')'
				scaner();
				if(syn==29){	//'{
					scaner();
					yucu();
					int len = strlen(prog);
					if(syn==0 && kk==0&&prog[len-3]!='}'){
						printf("成功!\n");
						return;
					}
				}
			}
		}
	}
	printf("语法错误!\n");
}
Beispiel #22
0
void factor()
{
	if(syn==10 || syn==11)   //字母或数字
	{
		scaner();
	}
	else 
		if(syn==27)      //'('
		{
			scaner();
			expression();
			if(syn==28)      //')'
				scaner();
			else
			{
				kk=1;
			}
		}
		else
		{
			kk=1;
		}
}
Beispiel #23
0
void statement(){

	if(syn == 10){

		scaner();
		if(syn == 18){

			scaner();
			expression();
		}else{
			printf("expression error");
			kk = 1;
			errorHandler();
		}

	}else if(syn == 6){
		return ;
	}else{
		printf("statement error");
		kk = 1;
		errorHandler();
	}
}
Beispiel #24
0
 void main(){

	if((file = fopen("e:\\newoutput.txt", "r"))==NULL){
		printf("Can't open file");
		exit(0);
	}

	line = (char*)malloc(sizeof(char)*30);

	scaner();

	lyparser();

}
Beispiel #25
0
void lyparser(){
	if(syn == 1){
		scaner();
		yucu();

		if(syn == 6){

			scaner();
			if(syn == 0 && kk == 0) printf("success");

		}else {
			if(kk!=1) printf("lack of end");
			kk = 1;
		}

	}else{
		printf("error with begin");
		kk = 1;
		yucu();
	}

	return ;

}
Beispiel #26
0
void main()
{
	p=0;
	FILE *fp;
	if((fp=fopen("data.txt","r"))==NULL){
        printf("无法打开文件!");
        exit(0);
     }
	fscanf(fp,"%[^$]s",prog);		//从流中按格式读取
	fclose(fp);
	printf("Your words:\n%s\n",prog);
	scaner();
	lrparser();
	printf("\npress # to exit:");
	scanf("%[^#]s",prog); 
}
Beispiel #27
0
int main()
{
    p = 0;
    printf("\n please input string :\n");

    FILE * thesource = freopen(source_file,"r",stdin);
    char ch = 0;
    do
    {
        //输入源程序字符串,送到缓冲区prog[p++]中;
        ch = getchar();
        prog[p++] = ch;
    }while(ch!='#');
    prog[p] = 0;
    p = 0;
   // printf("%s",prog);
    do
    {
        scaner();
        switch(syn)
        {
            case 11:
                {
                    printf("(%d,%d)\n",syn,sum);
                };break;
            case -1:
                {
                    printf("error!\n");
                };break;
            default:
                {
                    printf("(%d,%s)\n",syn,token);
                }
        }
    }while(syn != 0);
    fclose(thesource);
    return 0;
}
Beispiel #28
0
int main(int argc, char* argv[])
{
	string temp;
	string fin_file_name, fout_file_name;

	if (!(argc == 2 || argc == 3))
	{
		cout << "Need command line arguments: <input file> [<output file>]." << endl;
		return 1;
	}
	//открытие файлов
	if (argc > 1)
	{
		fin_file_name = Tooem(argv[1]);
	}
	ifstream fin(fin_file_name, ios::in);
	if (!fin)  
	{
		cout << "Error opening file: " << fin_file_name << "!" << endl;
		return 1;
	}
	if (argc > 2)
	{
		fout_file_name = Tooem(argv[2]);
	}
	if (fin_file_name == fout_file_name)
	{
		cout << "Command line arguments is same: <input file> <output file>." << endl;
		return 1;
	}

	ofstream f;
	if (!fout_file_name.empty())
	{
		f.open(fout_file_name, ios::out);
		if (!f)  
		{
			cout << "Error opening file: " << fout_file_name << "!" << endl;
			return 1;
		}
	}
	Error e;
	sPtr(Scaner) scaner(new Scaner);// динамич. указатель на сканер
	e.Accept(dynamic_pointer_cast<Scaner>(scaner));

	while (!fin.eof())
	{
		getline(fin, temp);
		scaner->SetString(temp);
	}
	if (e.HasErrors())
	{
		f << e;
	}
	else
	{
		sPtr(Token) t;
		size_t max_value_len = scaner->GetMaxTokenLength(); // для выравнивания
		f << "<Token List: >" << endl;;
		while (true)
		{
			t = scaner->PopToken();
			if (t->type != T_EOF)
			{
				f << t->ToString(max_value_len) << endl;
			}
			else
			{
				break;
			}
		}
		scaner->ResetTokenPos();
		f << endl << "<ID List: >" << endl;
		set<string> IdList = scaner->GetIdList();
		for (set<string>::const_iterator it = IdList.cbegin(); it != IdList.cend(); ++it)
		{
			f << *it << endl;
		}
	}
	return 0;
}