예제 #1
0
int checkRepeatExpression(char *expression)
{
	Rewind();

	char *first = nextToken();
	char *second = nextToken();
	char *third = nextToken();
	char *fourth = nextToken();
	char *fifth = nextToken();

	if (checkREPEAT(first, strlength(first))&&
		checkN(second, strlength(second))&&
		checkTIMES(third, strlength(third))&&
		checkCommandList(fourth, strlength(fourth))&&
		checkEND(fifth, strlength(fifth))) 
	{
		free(first);
		free(second);
		free(third);
		free(fourth);
		free(fifth);
		return 1;
	} else 
	{
		free(first);
		free(second);
		free(third);
		free(fourth);
		free(fifth);
		return 0;
	}

	return 1;
}
예제 #2
0
int checkWhileExpression(char *expression)
{
	Rewind();

	char *first = nextToken();
	char *second = nextToken();
	char *third = nextToken();
	char *fourth = nextToken();
	char *fifth = nextToken();
	char *sixth = nextToken();

	if (checkWHILE(first, strlength(first))&&
		checkNOT(second, strlength(second))&&
		isValidCommand(third)&&
		checkDO(fourth, strlength(fourth))&&
		checkCommandList(fifth, strlength(fifth))&&
		checkEND(sixth, strlength(sixth))) 
	{
		free(first);
		free(second);
		free(third);
		free(fourth);
		free(fifth);
		free(sixth);
		return 1;
	} else 
	{
		free(first);
		free(second);
		free(third);
		free(fourth);
		free(fifth);
		free(sixth);
		return 0;
	}
}
예제 #3
0
command_stream_t
make_command_stream (int (*get_next_byte) (void *),
		     void *get_next_byte_argument)
{
	//exit(1);
  /* FIXME: Replace this with your implementation.  You may need to
     add auxiliary functions and otherwise modify the source code.
     You can also use external functions defined in the GNU C Library.  */
	//printf("make_command_stream");

	char* fileString = getTextFromFile(get_next_byte, get_next_byte_argument);
	//printString(fileString);
	//checkParen(fileString);

	//printf("before makeCommandList");
	command_t commList = makeCommandList(fileString);
	//printString(fileString);
	//printf("sizeList: %d\n", g_commandListLength);
	//printCommandList(commList, g_commandListLength);
	//printCommandList(commList, g_commandListLength);
	//printString(fileString);
	checkCommandList(commList);

	//printCommandList(commList, g_commandListLength);
	checkParen(commList);
	//printCommandList(commList, g_commandListLength);
	
	int numSequenceCommands = countSequenceCommands(commList);

	int* rootList = malloc(sizeof(int)*numSequenceCommands);
	int rootListIndex = 0;
	int i = 0;
	//int index = -1;
	int index = buildTree(commList, i, rootListIndex, rootList);
	while(index != -1)
	{
		rootListIndex++;
		//printf("rootListIndex: %d\n", rootListIndex);
	//	printf("last index: %d\n", index);
		index = buildTree(commList, index+1, rootListIndex, rootList);
	}
	int j;
	for(j = 0; j < numSequenceCommands+1; j++)
	{
		//printf("index %d: %d\n", j, rootList[j]);
	}

	int k;
	command_t* finalCommList = malloc(sizeof(command_t)*(numSequenceCommands+1));
	int kmax = numSequenceCommands;
	//printf("numSequenceCommands: %d\n", numSequenceCommands);
	int last = g_commandListLength-1;
	/*for(last; last> 0; last--)
	{
		if(commList[last].type != IGNORE_COMMAND && commList[last].type != NEW_LINE && commList[last].type != SEQUENCE_COMMAND)
		{
			break;
		}
		if(commList[last].type == SEQUENCE_COMMAND)
		{
			kmax--;
		}
	}*/
	/*if(commList[g_commandListLength-2].type == SEQUENCE_COMMAND)
	{
		printf("kmax--");
		kmax--;
	}
	else
	{

	}*/
	for(k = 0; k < kmax; k++)
	{
		//printf("add to final comm list: %d\n", k);
		int index = rootList[k];
		finalCommList[k] = &commList[index];
	}

	int x;
	for(x = 0; x < kmax; x++)
	{
		//printf("print  final comm list: %d\n", x);
		//print_command(finalCommList[x]);
	}
	
	command_stream_t treeList = malloc(sizeof(struct command_stream));
	treeList->treeHead = finalCommList;
	treeList->size = kmax;
	/*//int size = sizeof(command_t);
	//int k = sizeof(int*);
	//printf("size of int*: %d\n", k);
	//printf(typeof(command_t));
	//printf("size of command_t: %d\n", sizeof(command_t));
	*/
	/*int i;
	for(i = 0; i < 3; i++)
	{
		printf("commList[%d].status: %d", i, commList[i].status);
	}*/
	
  //error (1, 0, "command reading not yet implemented");
	/*char* ch = malloc(sizeof(char)*2);
	ch[0] = 't';
	ch[1] = 'e';
	printf("%s\n", ch);*/
	//free(rootList);
	free(fileString);
  return treeList;
  return 0;
}