Introduction
This lab constitutes the implementation of a recursive descent parser discussed in lecture #30.
Divide the lab into 3 groups. Each group should set up a public share directory for all the lab mates to copy the code.
public abstract class AToken {
protected String _lexeme;
protected AToken(String lex) { _lexeme = lex; }
public String toString() { return_lexeme;}
public abstract Object execute(ATokVisitor v, Object inp);
}
public class IdToken extends AToken{
// constructor, etc.
public Object execute(ATokVisitor v, Object inp) {
return v.idCase(this, inp);)
}
}
// other concrete token classes to be written.
public abstract class ATokVisitor {
/**
* This is the case when the host is a concrete IdToken.
* Throws an IllegalArgumentException as default behavior.
* @param host a concrete IdToken.
* @param inp the input needed for this ATokVisitor to perform
its task.
*/
protected abstract Object defaultCase(AToken host, Object inp) {
// In many concrete cases, the code
will look something like:
// throw new
IllegalArgumentException("Wrong token!");
}
public Object idCase(IdToken host, Object inp) {
return defaultCase(host, inp);
}
// etc..., a method for each concrete token case to be
written
}
This should be trivial. After this group is done, it should split in
two subgroups: one would join group 2 and the other would join group 3 in
order to communicate their results to the other groups.
public class StreamTokWrapper implements ITokenizer
{
private StreamTokenizer _st;
// constructor and methods, etc...
}
To test the code, download the solution to homework #3, unzip it, and move the various java files into their appropriate subdirectories to match the packaging.
Have fun!
Dung X. Nguyen
revised 03/29/2004