private LList parse(List<Object> tokens) {
//System.out.println("parse " + tokens);
LList list = new LList();
while(tokens.size() > 0) {
Object token = tokens.remove(0);
/*
* THOFU LANGUAGE
*/
if(token.equals(";")) {
return strip(list);
}
else if(token.equals("[")) {
return list(tokens);
}
else if(token.equals("var")) {
return defination(tokens);
}
else if(token.equals("=")) {
return assignment(list, tokens);
}
else if(token.equals("for")) {
return forLoop(tokens);
}
else if(token.equals("while")) {
return whileLoop(tokens);
}
else if(token.equals("do")) {
return doLoop(tokens);
}
else if(token.toString().startsWith("++")) {
return crementBefore(list, token.toString(), "++", "+");
}
else if(token.toString().endsWith("++")) {
return crementAfter(list, token.toString(), "++", "+");
}
else if(token.toString().startsWith("--")) {
return crementBefore(list, token.toString(), "--", "-");
}
else if(token.toString().endsWith("--")) {
return crementAfter(list, token.toString(), "--", "-");
}
else if(token.equals(".")) {
return chain(list, tokens);
}
else if(token.equals("if")) {
return ifBlock(list, tokens, token);
}
else if(token.equals("function")) {
return function(tokens);
}
else if(token.equals("{")) { // create new let
return block(tokens);
}
else if(token.equals("}")) { // close let
return strip(list);
}
else if(isBinaryOperator(token)) { // any look up for binary operators?
// maybe dynamically editable?
return binary(list, tokens, token);
}
else if(token.equals("(")) {
List<LList> instructions = parenthesis(tokens);
for(LList tmp : instructions) {
if(tmp.size() == 1)
list.add(tmp.get(0));
else
list.add(tmp);
}
}
/*
* JAVA API
*/
else if(token.equals("new")) {
return constructor(list, tokens, token);
}
else if(token.toString().contains(".") && !token.toString().startsWith("\"")) {
// look ahead
Object next = tokens.get(0);
if(next.toString().equals("(")) {
return method(list, tokens, token);
}
else {
return field(list, tokens, token);
}
}
/*
* REST
*/
else {
list.add(type(token));
}
// close working list
if(list.size() == 3) {
tokens.add(0, list);
list = new LList();
}
}
// should never be reached!
throw new RuntimeException("No ; found at end of statement");