ASTLispNode.java
No OneTemporary

File Metadata

Created
Mon, Aug 24, 10:33 AM

ASTLispNode.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.xreate.grammatic.lisp;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.Map;
public class ASTLispNode {
public String caption;
public ArrayList<ASTLispNode> parameters = Lists.newArrayList();
protected Map<String, ASTLispNode> index;
public ASTLispNode(String c){
caption = c;
}
public ASTLispNode add(ASTLispNode node){
parameters.add(node);
return node;
}
public ASTLispNode get(String node){
if (null == index){
buildIndex();
}
return index.get(node);
}
protected void buildIndex(){
index = Maps.newHashMap();
for (ASTLispNode param : parameters){
index.put(param.caption, param);
}
}
}
class ASTLispConstantNode extends ASTLispNode{
public int value;
public ASTLispConstantNode(String c) {
super(c);
value = Integer.parseInt(c);
}
}
class NodeFunctionVarsList {
ASTLispNode node;
NodeFunctionVarsList(ASTLispNode node){
this.node = node;
}
String[] getVarNames(){
int size = node.parameters.size();
String[] result = new String[size];
for(int i=0; i<size; i++){
result[i] = node.parameters.get(i).get("name").parameters.get(0).caption;
}
return result;
}
}

Event Timeline