<commit_before>package parse;

import java.util.ArrayList;
import java.util.List;

import parse.Lexer.Token;
import commands.Command;
import commands.CommandOneInput;
import commands.CommandTwoInputs;
import commands.CommandZeroInputs;
import commands.Forward;
import commands.turtle.Constant;
public class Parser {
	private String myInput;
	public Parser(String input) {
		myInput=input;
	}
	
	public void doParse(){
		List<Token> tokens= makeTokenList();
		List<Command> commandList = makeCommandList(tokens);
		
		List<Node> NodeList = new ArrayList<Node>();
		while(!commandList.isEmpty()){
			NodeList.add(buildTree(commandList));
		}
		
	}
	
	private List<Command> makeCommandList(List<Token> tokens){
		List<Command> commandList = new ArrayList<Command>();
		for(Token token: tokens){
			commandList.add(getCommandType(token));
		}
		return commandList;
	}
	
	private Node buildTree(List<Command> commandList){
		
		Command root = commandList.get(0);
		commandList.remove(0);
		Node Node = new Node(root);
		if(root instanceof CommandZeroInputs){
			return Node;
		}
		if(root instanceof CommandOneInput){
			Node.setLeftChild(commandList.get(0));
			commandList.remove(0);
			return Node;
		}
		else if(root instanceof CommandTwoInputs){
			Node.setLeftChild(commandList.get(0));
			Node.setRightChild(commandList.get(1));
			commandList.remove(0); commandList.remove(0);
			return Node;
		}
		return Node;
		
	}
	
	private List<Token> makeTokenList(){
		Lexer lexer = new Lexer();
		return lexer.lex(myInput);
	}
	
	
	private Command getCommandType(Token token){
		if(token.type.name().equals("CONSTANT")){
			Command command = new Constant();
			return command;
		}
		//This is added because the try statement is not working. So the only command that will be recognized is Forward for now
		if(token.data.equals("Forward")){
			Command command = new Forward();
			return command;
		}
		try {
			Command command = (Command) Class.forName(token.data).newInstance();
			return command;
			
			
			
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();<commit_msg>now commands are dynamically created, but commands must be in the command package<commit_after>package parse;

import java.util.ArrayList;
import java.util.List;

import parse.Lexer.Token;
import commands.Command;
import commands.CommandOneInput;
import commands.CommandTwoInputs;
import commands.CommandZeroInputs;
import commands.Forward;
import commands.turtle.Constant;
public class Parser {
	private String myInput;
	public Parser(String input) {
		myInput=input;
	}
	
	public void doParse(){
		List<Token> tokens= makeTokenList();
		List<Command> commandList = makeCommandList(tokens);
		
		List<Node> NodeList = new ArrayList<Node>();
		while(!commandList.isEmpty()){
			NodeList.add(buildTree(commandList));
		}
		
	}
	
	private List<Command> makeCommandList(List<Token> tokens){
		List<Command> commandList = new ArrayList<Command>();
		for(Token token: tokens){
			commandList.add(getCommandType(token));
		}
		return commandList;
	}
	
	private Node buildTree(List<Command> commandList){
		
		Command root = commandList.get(0);
		commandList.remove(0);
		Node Node = new Node(root);
		if(root instanceof CommandZeroInputs){
			return Node;
		}
		if(root instanceof CommandOneInput){
			Node.setLeftChild(commandList.get(0));
			commandList.remove(0);
			return Node;
		}
		else if(root instanceof CommandTwoInputs){
			Node.setLeftChild(commandList.get(0));
			Node.setRightChild(commandList.get(1));
			commandList.remove(0); commandList.remove(0);
			return Node;
		}
		return Node;
		
	}
	
	private List<Token> makeTokenList(){
		Lexer lexer = new Lexer();
		return lexer.lex(myInput);
	}
	
	
	private Command getCommandType(Token token){
		if(token.type.name().equals("CONSTANT")){
			Command command = new Constant();
			return command;
		}
		//All commands must be in the commands package
		try {
			Command command = (Command) Class.forName("commands."+token.data).newInstance();
			return command;
			
			
			
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
{'fraction_non_alphanumeric': 0.11525189786059352, 'fraction_numerical': 0.003680699332873246, 'mean_word_length': 4.407960199004975, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2447645', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1298, 'n_words': 324}