コード例 #1
0
ファイル: console.c プロジェクト: R6500/STM32F3_Gizmo
// Runs several tests if enabled
static void consoleRunTests(void)
 {
 // Only for development
 // List all registered codes if it is enabled in conditional compilation
 #ifdef TEST_REGISTER
   registerList();
 #endif // TEST_REGISTER

 // Only for development
 // Test analog elements if it is enabled in conditional compilation
 #ifdef TEST_ANALOG
   analogTest();
 #endif //TEST_ANALOG

 // Only for development
 // Test Gyroscope if it is enabled in conditional compilation
 #ifdef TEST_GYRO
   gyrTest();
 #endif // TEST_GYRO

 // Only for development
 // Test Accelerometer if it is enabled in conditional compilation
 #ifdef TEST_ACCEL
   accelTest();
 #endif // TEST_ACCEL

 // Only for development
 // Test Accelerometer if it is enabled in conditional compilation
 #ifdef TEST_MAGNET
   magnetTest();
 #endif // TEST_MAGNET
 }
コード例 #2
0
int evaluateSyntax(int scode){
	char *scodeStr=syntaxString[scode-NUMOFTOKEN];
	int *temp=syntaxInner[scode-NUMOFTOKEN];
	int j=1;
	if(currentToken<0){
		printf("EOF\n");return -1;
	}
	/*evaluate SPROGRAM*/
	if(scode==SPROGRAM){
		logPutOut(" evaluateSyntax(%s) line:%d\n",scodeStr,lastLineNumber);
		for(j=1;j<=5;j++){
			if(evaluateWord(temp[j])<0){
				errPrint("evaluateSyntax(%s)->(%d)",scodeStr,temp[j]);
			}
			if(j==2){
				setupProgram(tmpString);
#ifdef CSL
			    sprintf(cName,"%s.%s",filename,FILETYPE);
				if((cFile=fopen(cName,"w"))==NULL){
					exit(-1);
				}
				TAGCOMB("$$",idList.prog->name->name);
				START(tag);
				LAD("\t","gr0","0");
				CALL("\t","L1");
				tagnum++;
				CALL("\t","FLUSH");
				SVC("\t","0");
				fclose(cFile);
#endif
			}
		}
#ifdef CSL
		if((cFile=fopen(cName,"a"))==NULL) exit(-1);
		END("");
		//printTextFile("cFile","library.txt");
        fclose(cFile);
#endif
		return(scode);
	}
	/*evaluate SBROCK*/
	else if(scode==SBROCK){
		scope=idList.prog->name->name;
		logPutOut(" evaluateSyntax(%s) line:%d\n",scodeStr,lastLineNumber);
		do{
			if(currentToken==TVAR){ //except check
				pPrint(ALLOWINDENT);
				if(evaluateWord(SVARDECLARE)<0){
					errPrint("evaluateSyntax(%s)->(%d)",scodeStr,SVARDECLARE);
				}
			}else if(currentToken==TPROCEDURE){ //except check
				pPrint(ALLOWINDENT);
				if(evaluateWord(SSUBPROGDECLARE)<0){
					errPrint("evaluateSyntax(%s)->(%d)",scodeStr,TPROCEDURE);
				}
			}else{
				j++;
			}
		}while(j==1);
        pPrint(RESETINDENT);
#ifdef CSL
		if((cFile=fopen(cName,"a"))==NULL) exit(-1);
//        TAGNAME("L");
        TAGCOMB("L","1");
        TAGPRINT(tag);
        fclose(cFile);
#endif
		if(evaluateWord(temp[3])<0){
			errPrint("evaluateSyntax(%s)->(%d)",scodeStr,temp[3]);
		}
		return(scode);
	}
	/*evaluate SVARDECLARE*/
	else if(scode==SVARDECLARE){
		logPutOut(" evaluateSyntax(%s) line:%d\n",scodeStr,lastLineNumber);
		int tempType;
		for(j=1;j<=3;j++){
			if(evaluateWord(temp[j])<0){
				errPrint("no var(var declaretion)\n");
			}
			if(j==1){
				pPrint(ADDINDENT,1);
			}
		}
		if((tempType=evaluateWord(temp[j++]))<0){//j=4
			errPrint("must be type\n");
		}
		int arrayNum=0;
		if(tempType==SARRAY){
			arrayNum=tempArray.arrayNum;
			tempType=tempArray.type;
		}
		int k;
		for(k=0;k<tempListCount;k++){
#ifdef CSL
			if((cFile=fopen(cName,"a"))==NULL) exit(-1);
			if(arrayNum==0){
				if(scope==idList.prog->name->name){
					TAGCOMB("$",tempList->word);
				}else{
					TAGCOMB2("$",tempList->word,"\%",scope);
				}
				DC(tag,"0");
			}else{
				int arr;
				for(arr=0;arr<=arrayNum;arr++){
					if(scope==idList.prog->name->name){
						TAGCOMBARRAY("$",tempList->word,arr);
					}else{
						TAGCOMBARRAY2("$",tempList->word,arr,"\%",scope);
					}
					DC(tag,"0");
				}
			}
			fclose(cFile);
#endif
			if(registerList(tempList->word,tempType,arrayNum,lastLineNumber,POSI_VAR,scope)<0){
				errPrint("double variable\n");
			}
			tempList=tempList->next;
		}
		clearWordList();
		if(evaluateWord(temp[j++])<0){//j=5
			errPrint("must be ;\n");
		}
		while(1){
			int i=j=6;
				if(validateTopOfSyntax(temp[i])<0){// if there is no first word, it is correct
					break; //if nothing, its correct
				}else{
				pPrint(ALLOWINDENT);
				for(i=j;i<=temp[0];i++){
					if((tempType=evaluateWord(temp[i]))<0){// varlist
						printf("errEI1\n");return -1;
					}
					if(i==8){
						int arrayNum=0;
						if(tempType>SARRAY){
							arrayNum=tempType-SARRAY;
							tempType=SARRAY;
						}
						int k;
						for(k=0;k<tempListCount;k++){
#ifdef CSL
			if((cFile=fopen(cName,"a"))==NULL) exit(-1);
			if(arrayNum==0){
				if(scope==idList.prog->name->name){
					TAGCOMB("$",tempList->word);
				}else{
					TAGCOMB2("$",tempList->word,"\%",scope);
				}
				DC(tag,"0");
			}else{
				int arr;
				for(arr=0;arr<=arrayNum;arr++){
					if(scope==idList.prog->name->name){
						TAGCOMBARRAY("$",tempList->word,arr);
					}else{
						TAGCOMBARRAY2("$",tempList->word,arr,"\%",scope);
					}
					DC(tag,"0");
				}
			}
			fclose(cFile);
#endif
							if(registerList(tempList->word,tempType,arrayNum,lastLineNumber,POSI_VAR,scope)<0){
								errPrint("double variable\n");
							}
							tempList=tempList->next;
						}
						clearWordList();
					}
				}
			}
		}
	}
	/*evaluate SVARLIST*/
	else if(scode==SVARLIST){//1:{2} patern