Ejemplo n.º 1
0
int main(int argc, const char * argv[])
{
    Token *token = NULL;
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file = init_lister(argv[1], source_name, date);
    Print print(source_name, date);
    Scanner scanner(source_file, source_name, date, print);
    IdentifierBinaryTree tree;
    
    do
    {
        token = scanner.getToken();
        print.printToken(token);
        if (token->getCode() == IDENTIFIER)
        {
            tree.addIdentifier((Identifier*)token, scanner.getLineNumber());
        }
        else if (token->getCode() != PERIOD && token->getCode() != END_OF_FILE)
        {
            delete token;
        }
    }
    while (token->getCode() != PERIOD && token->getCode() != END_OF_FILE);
    
    print.printTree(tree.getTreeRoot());
    delete token;
    fclose(source_file);
    return 0;
}
Ejemplo n.º 2
0
int main(int argc, const char * argv[])
{
    /******************************************
     This is not a correct implementation, you will need to modfy this
     so that it satisfies the project problem.  Currently, this just
     prints every token and then deletes every token.
     *****************************************/
    Token *token = NULL;
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file = init_lister(argv[1], source_name, date);
    Print print(source_name, date);
    Scanner scanner(source_file, source_name, date, print);
    do
    {
        token = scanner.getToken();
        print.printToken(token);
        if (token->getCode() != PERIOD && token->getCode() != END_OF_FILE)
        {
            delete token;
        }
    }
    while (token->getCode() != PERIOD && token->getCode() != END_OF_FILE);
    delete token;
    print.printBT();
    fclose(source_file);
    return 0;
}
Ejemplo n.º 3
0
//2014.02.21.20
int main(int argc, const char *argv[]) {

	FILE *source_file;
	char source_name[MAX_FILE_NAME_LENGTH];
	char date[DATE_STRING_LENGTH];

	/* Missing Code Here */

	// check number of command-line arguments
	if (argc != 2) {
		puts("There should be two arguments");
		return 1;
	} // end if

	// get the file pointer
	source_file = init_lister(argv[1], source_name, date);

	// get line by line
	while (get_source_line(source_file, source_name, date)) {

	} // end while

	// fclose closes file
	fclose(source_file);
	//return zero for success
	return 0;
}
Ejemplo n.º 4
0
int main(int argc, const char * argv[])
{
    /******************************************
     This is not a correct implementation, you will need to modfy this
     so that it satisfies the project problem.  Currently, this just
     prints every token and then deletes every token.
     *****************************************/
    Token *token = NULL;
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file = init_lister(argv[1], source_name, date);
    Print print(source_name, date);
    Scanner scanner(source_file, source_name, date, print);

    do
    {
        token = scanner.getToken();
        print.printToken(token);

    }
    while (token->getCode() != PERIOD && token->getCode() != END_OF_FILE);

    puts("Cross Reference Information");
    printf("Identifier\t\t\t\t%s\n", "Line Numbers");
    printf("----------\t\t\t\t%s\n", "------------");
    print.printTree(scanner.tree);

    delete token;
    fclose(source_file);
    return 0;
}
Ejemplo n.º 5
0
int main(int argc, const char * argv[])
{
    /******************************************
     This is not a correct implementation, you will need to modfy this
     so that it satisfies the project problem.  Currently, this just
     prints every token and then deletes every token.
     *****************************************/
    Token *token = NULL;
	TreeNode *root = NULL; // root of Binary Tree
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file = init_lister(argv[1], source_name, date);
    Print print(source_name, date);
    Scanner scanner(source_file, source_name, date, print);
    
    do
    {
        token = scanner.getToken();
        print.printToken(token);
		if(token->getCode() == IDENTIFIER && root == NULL)
		{
			TreeNode *rootNode;
			rootNode = new TreeNode(token,token->getLineNumber());
			root = rootNode;
		}
		else
		{
			if(token->getCode() == IDENTIFIER)
			{
				TreeNode *newNode;
				newNode = new TreeNode(token,token->getLineNumber());
				root->insertNode(token,token->getLineNumber());
			}
		}
        if (token->getCode() != PERIOD && token->getCode() != END_OF_FILE
			&& token->getCode() != IDENTIFIER)
        {
            delete token;
        }
    }
    while (token->getCode() != PERIOD && token->getCode() != END_OF_FILE);
    
	cout << "\nCross Reference Information\nIdentifier\t\tLine Numbers\n";
	cout << "-----------		------------\n";
	print.printBinaryTree(root);

    delete token;
    fclose(source_file);
    return 0;
}
Ejemplo n.º 6
0
int main (int argc, const char *argv[])
{
    FILE *source_file;
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    
	source_file = init_lister(argv[1], source_name, date); //calls init_lister to initialize file
	
	while(get_source_line(source_file, source_name, date)) //runs until there are no more lines
	{
		
	}
	
    return 0;
}
Ejemplo n.º 7
0
int main(int argc, const char * argv[])
{
    /******************************************
     This is not a correct implementation, you will need to modfy this
     so that it satisfies the project problem.  Currently, this just
     prints every token and then deletes every token.
     *****************************************/
    Token *token = NULL;
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file = init_lister(argv[1], source_name, date);
    Print print(source_name, date);
    Scanner scanner(source_file, source_name, date, print);

	////
	Token* identifierSearchTreeHead = NULL;
	////
    
    do
    {
		//token: "Token* token"
        token = scanner.getToken();
        print.printToken(token);
        if (token->getCode() != PERIOD && token->getCode() != END_OF_FILE)
        {
			//?????????????????TODO: add identifiers to binary tree and add line numbers where
			//						the identifier shows up to a linked list stored in the identifier token
			if(token->getCode() == IDENTIFIER){
				Token::addTokenNodeToBinarySearchTree(identifierSearchTreeHead, token, scanner.getLineNumber());
			}else if(token->getCode() != PERIOD && token->getCode() != END_OF_FILE){
				delete token;
			}
        }
    }
    while (token->getCode() != PERIOD && token->getCode() != END_OF_FILE);


	//print line number info for identifier tokens
	cout << "\nCross Reference Information\n";
	cout << "Identifier\t\tLine Numbers\n";
	cout << "-----------\t\t------------\n";
	cout << Token::getBinarySearchTreeLinesStringsInOrder(identifierSearchTreeHead);

    delete token;
	delete identifierSearchTreeHead;
    fclose(source_file);
    return 0;
}
Ejemplo n.º 8
0
int main(int argc, const char * argv[])
{
    char token;
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file = init_lister(argv[1], source_name, date);
    init_scanner(source_file, source_name, date);
    
    do
    {
        token = get_token();
    }
    while (token != '.'); //loop ends when a period is found returning the char 0
    
    return 0;
}
Ejemplo n.º 9
0
	int func_main (int argc, char *filename) {

        
        //Initialization of variables
        FILE *file = NULL;
        char source_file_name[MAX_FILE_NAME_LENGTH] = {'\0'};
        char date[DATE_STRING_LENGTH] = {'\0'};
        
        //Get date/time, Open File
        file = init_lister(filename, source_file_name, date);
        
        //Read/Print lines
        while (get_source_line(file, source_file_name, date));
        
        return 0;
        
    }
Ejemplo n.º 10
0
int main(int argc, const char * argv[])
{
    /******************************************
     This is not a correct implementation, you will need to modfy this
     so that it satisfies the project problem.  Currently, this just
     prints every token and then deletes every token.
     *****************************************/
    Token *token = NULL;
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file = init_lister(argv[1], source_name, date);
    Print print(source_name, date);
    Scanner scanner(source_file, source_name, date, print);
    
    Tree newTree;//create tree
    
    do
    {
        token = scanner.getToken();
        print.printToken(token);

        if (token->getCode() == IDENTIFIER)//check if it is an identifier
        {
            newTree.addNode(token, scanner.getLineNum());//if identifier, add to tree
        }
        else if (token->getCode() != PERIOD && token->getCode() != END_OF_FILE)
        {
            delete token;//if not, delete token
        }
    }
    while (token->getCode() != PERIOD && token->getCode() != END_OF_FILE);//scan until end of file
    
    //newTree.recursiveDeleteTree(newTree.getRoot());
    while(!newTree.isEmpty())
    {
        newTree.recursivePrintTree(newTree.getRoot(),print);//recursively print tree
    }
    delete token;
    fclose(source_file);
    
    return 0;
}
Ejemplo n.º 11
0
int main(int argc, const char * argv[])
{
    Token *token;
    Token *token_list; //This needs to be implemented as a linked list in scanner.h.
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file = init_lister(argv[1], source_name, date);
    init_scanner(source_file, source_name, date);
    
    do
    {
        token = get_token();
        add_token_to_list(token_list, token);
        print_token(token);
    }
    while (???);//What is the sentinal value that ends this loop?
    
    quit_scanner(source_file, token_list);
    return 0;
}
Ejemplo n.º 12
0
int main(int argc, const char *argv[])
{
   Token *token;
   // Token *token_list; //This needs to be implemented as a linked list in scanner.h.
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file;
    source_file = init_lister(argv[1], source_name, date);
    init_scanner(source_file, source_name, date);
    do
    {
        token = get_token();
       // add_token_to_list(token_list, token);
        print_token(token);
    }
    while ((* token).tCode != END_OF_FILE);
    
    //quit_scanner(source_file, token_list);
    return 0;
}
Ejemplo n.º 13
0
int main(int argc, const char * argv[]) {
	Token *token;
	Token *token_list; 
	char source_name[MAX_FILE_NAME_LENGTH];
	char date[DATE_STRING_LENGTH];

	FILE *source_file = init_lister(argv[1], source_name, date);
	init_scanner(source_file, source_name, date);
	init_scanner2(source_name, date);
	token_list = malloc(sizeof(Token));
	token_list->nextptr = NULL;
	do {
		token = get_token();
		add_token_to_list(token_list, token);
		print_token(token);
	} while (token->token_string[0] != '.'); 

	quit_scanner(source_file, token_list);
	return 0;
}
Ejemplo n.º 14
0
int main(int argc, const char * argv[])
{
    /******************************************
     This is not a correct implementation, you will need to modfy this
     so that it satisfies the project problem.  Currently, this just
     prints every token and then deletes every token.
     *****************************************/
    Token *token = NULL;		// not sure if this may throw errors or not: how to properly allocate in memory? need to keep root of binaryTree in mind
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file = init_lister(argv[1], source_name, date);
    Print print(source_name, date);
    Scanner scanner(source_file, source_name, date, print);
    int identifierCount = 0;
	//BinaryTree tree = BinaryTree();					// not sure how to properly initialize/set the root of the tree
    BinaryTree tree;
    
    do
	{
        token = scanner.getToken();
        print.printToken(token);
	
	    // BinaryTree stuff goes here
	    // If token is IDENTIFIER type, sends token pointer to tree to check if it exists
		if (token->getCode() == IDENTIFIER) {
			++identifierCount;
			tree.addToken(token);
		}
		if (token->getCode() != PERIOD && token->getCode() != END_OF_FILE && token->getCode() != IDENTIFIER)
		{
			delete token;
		}
	}while (token->getCode() != PERIOD && token->getCode() != END_OF_FILE);
    
    delete token;
    fclose(source_file);
    return 0;
}
Ejemplo n.º 15
0
int main(int argc, const char * argv[])
{
    Token *token = NULL;
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    FILE *source_file = init_lister(argv[1], source_name, date);
    Print print(source_name, date);
    Scanner scanner(source_file, source_name, date, print);
    bTree tree;   //call default constructor of bTree
	
	UnitTests run;
	int testing = 1; // Set to 1 to run unit tests
	if(testing) {
		if(!run.testAddToTree()) { printf("Failed testAddToTree\n"); }
		if(!run.testAddToList()) { printf("Failed testAddToList\n"); }
		if(!run.testDeleteList()) { printf("Failed testDeleteList\n"); }
		if(!run.testDestroyTree()) { printf("Failed testDestroyTree\n"); }
		if(!run.testSet()) { printf("Failed testSet\n"); }
		if(!run.testGetToken(source_name, date, print)) { printf("Failed testGetToken\n"); }
		if(!run.testCode()) { printf("Failed testCode\n"); }
		if(!run.testType()) { printf("Failed testType\n"); }
		if(!run.testIntLiteral()) { printf("Failed testIntLiteral\n"); }
		if(!run.testRealLiteral()) { printf("Failed testRealLiteral\n"); }
		if(!run.testStringLiteral()) { printf("Failed testStringLiteral\n"); }
		if(!run.testTokenString()) { printf("Failed testTokenString\n"); }
	}

    do
    {
        token = scanner.getToken();
        print.printToken(token);
        if (token->getCode() != PERIOD && token->getCode() != END_OF_FILE)
        {
            if(token->getCode() == IDENTIFIER)
            {

                /*
                    call the add method of bTree class on the identifer token,
                    bTree will further find the proper place in the tree structure
                    and either add it alphabetically or add a line number to the linked list.
                    The current line number is also fetched and passed to add()
                */

                tree.addToTree(token, scanner.getLineNumber());

            }
            else
                delete token;
        }
    }
    while (token->getCode() != PERIOD && token->getCode() != END_OF_FILE);

    //print the reference information header strings
    print.printReferenceHeader();

    //code to recursively print the binery tree and then delete the tokens
    tree.printTree();

    //delete the last token which is the period after everything has been printed
    delete token;
    //then close the src file
    fclose(source_file);
    return 0;
}