SE250:lab-9:hbar055
Option Two
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
i 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 <###> <###>
Thats it for me.........