SE250:lab-9:jpar277

From Marks Wiki
Revision as of 05:20, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (9 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

like holy crap all the options are hard as! I had a quick read over the options, this one seemed the easiest ... although, the 3rd option seemed more relevant to the compsys assignment ... on that topic, has anyone started it? The very first step - loading program memory from address $0f00 is rather hard >.>

So the task (I think) is to get the tokenised statement and then convert it to full.

OK, back to topic, the first part just like the past 2-3 labs, was getting the code to compile without any errors. In the parser.c file, you had to move the "Tree* t;" from inside the for loop to the declarations area (above or below the "int i;" line)

Next problem was with the functions "Stmt" and "StmtSeq". Because Stmt doesn't get called, we can leave it empty for now. Just to see the program run without any problems, for StmtSeq I just put "return tokens;" my output at this stage is

Parse("a=1"):
        Incomplete parse
└
        └
Parse("a=1;b=2;k;k;k"):
        Incomplete parse
░
        ░
Parse("ia>btwtda=a*2ek"):
        Incomplete parse
£
        £
Parse("ict{x=1;wtda=a*2}ek"):
        Incomplete parse
ä
        ä
Parse("junk that won't parse"):
        Incomplete parse
h
        h

so now I just have to get the function working properly ... if only I knew what it was supposed to do >.>

So after some reading/research we (mcar147, tlou006 and myself) came to realise the StmtSeq calls the Stmt function.

In the Stmt function, we need to get the tokens recognising the statements and fill in the other data, arity and arg.


So after hours of trial and error ... we didn't get very far ... this is the code we ended with

	Tree* t;
	Token tok;
	int i;

	for (i = 0; i < sizeof(tokens); i++) {
		tok = current(tokens);

		if (tok == "i"){
			t = mkNode;
		} else if (tok == "d") {
			t->name = 'd';
			t->arity = 1;
		} else if (tok == "e") {
			t->name = 'e';
			t->arity = 1;
		} else if (tok == "p") {
			t->name = 'p';
			t->arity = 1;
		} else if (tok == "s") {
			t->name = 'k';
			t->arity = 0;
		} else if (tok == "t") {
			t->name = 't';
			t->arity = 2;
		} else if (tok == "w") {
			t->name = 'w';
			t->arity = 2;
		} else {
			t = 0;
		}
	}

	return t;

We came to realise that we need to use the current function to look at 1 token at a time because the tokens variable is holding an array of tokens. We didn't quite get how to use the tree ... so it didn't work

but because we had the else statement to "catch" errors ... we got this output

Parse("a=1"):
        Incomplete parse
<###>
        <###>
Parse("a=1;b=2;k;k;k"):
        Incomplete parse
<###>
        <###>
Parse("ia>btwtda=a*2ek"):
        Incomplete parse
<###>
        <###>
Parse("ict{x=1;wtda=a*2}ek"):
        Incomplete parse
<###>
        <###>
Parse("junk that won't parse"):
        Incomplete parse
<###>
        <###>

Its really confusing trying to understand whats happening with the code, theres no commenting to guide us ... if you follow the functions, it leads to another function ... and after you go through about 2 or 3, you get lost and forget what you were following @_@