Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
FILE HOSTS PREMIUM ACCOUNT
ALL FILE HOST PREMIUM ACCOUNTS
Zynga Slingo Trainer v5.12
iTunes Gift Card Generator V3.1 2012
Diablo 3 GOLD Coins FREE
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Empires & Allies Hack Cheat Trainer v5.4.1
Eve Onnline 60 Days Time Card Generator v2
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Better way to get content via jQuery $.get()
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
Pastable version of
Simple interpreter
<pre class='prettyprint' language='java'>import java.io.*; import java.lang.Character; // import java.util.HashMap; import javax.swing.*; public class Cog extends JFrame { public static String[] defName = new String[1000]; public static int[] defLine = new int[1000]; public static int defCount = 0; public static String[] varVal = new String[1000]; public static String[] varName = new String[1000]; public static int varCount = 0; public static int curLine; public static String[] strScript; public static int globI = 0; public static void main(String args[]) { try { BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); System.out.print("Which file to open? (Case-sensitive)\n"); FileInputStream fr = new FileInputStream(new File(br.readLine())); DataInputStream ds = new DataInputStream(new BufferedInputStream(fr)); System.out.println(ds.available()); String tmp = ""; for (int i2 = ds.available(); i2 > 0; i2--) { if (ds.available() != 0) { tmp += ds.readLine() + "\n"; } } strScript = tmp.split("\n"); getDefs(); if (getDef("start") > -1) { globI = getDef("start"); System.out.println("Found start on " + getDef("start")); } else if (getDef("main") > -1) { globI = getDef("main"); System.out.println("Found main on " + getDef("main")); } else { System.out.println("Failed to start"); } for (globI = globI; globI < strScript.length; globI++) { try { analyzeLine(strScript[globI]); curLine++; } catch (Exception e2) { e2.printStackTrace(); } } } catch (IOException e) { e.printStackTrace(); } } public static void analyzeLine(String s) { if (!s.startsWith("#")) { if (s.trim().startsWith("@")) { String[] tmp = s.split("="); for (int i = 0; i < tmp.length; i++) { String[] tmp2 = tmp[i].split("@"); if (tmp2.length > 1) { if (tmp2[1].equalsIgnoreCase("author")) { System.out.println("Written by " + tmp[i + 1]); } else if (tmp2[1].equalsIgnoreCase("name")) { System.out.println("Script name " + tmp[i + 1]); } } } /* } else if (s.trim().startsWith("def")) { String[] tmp = s.split(" "); for (int i = 0; i < tmp.length; i++) { if (tmp[i].endsWith("{")) { setDef(left(tmp[i].length() - 1, tmp[i]), curLine); } } */ } else if (s.trim().startsWith("goto")) { String tmp = between(s.trim(), "(", ")"); globI = getDef(tmp); } else if (s.trim().startsWith("var")) { String[] t = s.split("var"); String[] tmp = t[1].split(";"); for (int i = 0; i < tmp.length; i++) { String[] tmp2 = tmp[i].split("="); for (int i2 = 0; i2 < tmp2.length - 1; i2++) { if (tmp2[i2 + 1].contains("}")) { setVar(tmp2[i2], left(tmp2[i2 + 1].length() - 1, tmp2[i2 + 1])); } else if (tmp2[i2].contains("{")) { setVar(right(1, tmp2[i2]), tmp2[i2 + 1]); } else { setVar(tmp2[i2], tmp2[i2 + 1]); } } } } else if (s.trim().startsWith("log")) { // String tmp = right(4, s.trim()); // String tmp2 = left(tmp.length() - 1, tmp); System.out.println(between(s.trim(), "(", ")")); } else if (s.trim().startsWith("for")) { String tmp = between(s.trim(), "for(", ")"); String[] tmp2 = tmp.split("="); String[] tmp3 = tmp2[1].split(":"); int intFinish = 0; for (int i = curLine; i < strScript.length; i++) { if (strScript[i].trim().startsWith("next")) { intFinish = i; } } int iStart = Integer.valueOf(tmp3[0].trim()).intValue(); int iEnd = Integer.valueOf(tmp3[1].trim()).intValue(); int tmpi = globI + iEnd; int tmp2z = globI + 1; // JOptionPane.showMessageDialog(null, Integer.toString(globI) + ":" + Integer.toString(intFinish)); curLine = globI; for (int i = iStart; i < iEnd; i++) { // run how many times for (int i2 = curLine + 1; i2 < intFinish; i2++) { // what to run analyzeLine(strScript[i2]); globI++; curLine++; } // JOptionPane.showMessageDialog(null, "i: " + Integer.toString(i)); curLine = globI - iEnd; globI = curLine; System.out.println(i); } curLine = globI; // curLine = tmp2z; } else if (s.trim().startsWith("when")) { String tmp = between(s.trim(), "(", ")"); System.out.println(s); String[] tmp2 = tmp.split(";"); System.out.println("Going to " + tmp2[1] + " when " + tmp2[0]); if (tmp.contains("=>")) { String[] tmp3 = tmp2[0].split(">="); if (Integer.valueOf(getVar(tmp3[0].trim())).intValue() >= Integer.valueOf(tmp3[1].trim()).intValue()) { globI = getDef(tmp2[1]); } } else if (tmp.contains("<=")) { String[] tmp3 = tmp2[0].split("<="); if (Integer.valueOf(getVar(tmp3[0].trim())).intValue() <= Integer.valueOf(tmp3[1].trim()).intValue()) { globI = getDef(tmp2[1]); } } else if (tmp.contains("!=")) { String[] tmp3 = tmp2[0].split("!="); if (Integer.valueOf(getVar(tmp3[0].trim())).intValue() != Integer.valueOf(tmp3[1].trim()).intValue()) { globI = getDef(tmp2[1]); } } else if (tmp.contains("<")) { String[] tmp3 = tmp2[0].split("<"); if (Integer.valueOf(getVar(tmp3[0].trim())).intValue() < Integer.valueOf(tmp3[1].trim()).intValue()) { globI = getDef(tmp2[1]); } } else if (tmp.contains(">")) { String[] tmp3 = tmp2[0].split(">"); if (Integer.valueOf(getVar(tmp3[0].trim())).intValue() > Integer.valueOf(tmp3[1].trim()).intValue()) { globI = getDef(tmp2[1]); } } else if (tmp.contains("=")) { String[] tmp3 = tmp2[0].split("="); String tmo = getVar(tmp3[0].trim()); if (tmo.equals(tmp3[1].trim())) { globI = getDef(tmp2[1]); } } } else if (s.trim().startsWith("if")) { String tmp = between(s.trim(), "(", ")"); String[] tmp2 = new String[] { tmp}; if (tmp.contains(">=")) { tmp2 = tmp.split(">="); } else if (tmp.contains("<=")) { tmp2 = tmp.split("<="); } else if (tmp.contains("!=")) { tmp2 = tmp.split("!="); if (tmp2[0].trim() != tmp2[1].trim()) { System.out.println( tmp2[0].trim() + " does not equal " + tmp2[1].trim()); } } else if (tmp.contains("<")) { tmp2 = tmp.split("<"); } else if (tmp.contains(">")) { tmp2 = tmp.split(">"); } else if (tmp.contains("=")) { tmp2 = tmp.split("="); if (tmp2[1].trim().equals(getVar(tmp2[0].trim()))) { System.out.println( "" + tmp2[0].trim() + " equals " + tmp2[1].trim()); } } } else { for (int i = 0; i < varCount; i++) { if (s.trim().startsWith(varName[i])) { String tmp = s.trim(); String[] tmp2; if (tmp.contains("+")) { tmp2 = tmp.split("+"); } else if (tmp.contains("-")) { tmp2 = tmp.split("-"); } else if (tmp.contains("=")) { tmp2 = tmp.split("="); System.out.println( "Now " + tmp2[0].trim() + " equals " + tmp2[1].trim()); } } } } } } public static void setDef(String dName, int dLine) { defLine[defCount] = dLine; defName[defCount] = dName.trim(); defCount++; } public static int getDef(String dName) { for (int i = 0; i < defCount; i++) { if (dName.equals(defName[i])) { return defLine[i]; } } return -1; } public static void getDefs() { for (int i = 0; i < strScript.length; i++) { if (strScript[i].trim().startsWith("def")) { String[] tmp = strScript[i].split(" "); for (int i2 = 0; i2 < tmp.length; i2++) { if (tmp[i2].endsWith("{")) { setDef(left(tmp[i2].length() - 1, tmp[i2]), i); } } } } } public static void setVar(String vName, String vVal) { /* boolean inUse = false; for (int i = 0; i < varCount; i++) { System.out.println(varName[i]); if (varName[i] == vName) { inUse = true; } } if (inUse = false) {*/ varVal[varCount] = vVal.trim(); varName[varCount] = vName.trim(); varCount++; /* } else { System.out.println(vName + " is already defined"); }*/ } public static String getVar(String vName) { for (int i = 0; i < varCount; i++) { if (vName.equals(varName[i])) { return varVal[i]; } } return null; } public static String between(String e, String s1, String s2) { return mid(e.indexOf(s1) + 1, e.indexOf(s2) - e.indexOf(s1) - 1, e); } public static String mid(int offset, int toread, String s) { String tmp = ""; char[] ch = s.toCharArray(); for (int i = offset; i < offset + toread; i++) { tmp = tmp + ch[i]; } return tmp; } public static String left(int offset, String s) { String tmp = ""; char[] ch = s.toCharArray(); for (int i = 0; i < offset; i++) { tmp = tmp + ch[i]; } return tmp; } public static String right(int offset, String s) { String tmp = ""; char[] ch = s.toCharArray(); for (int i = offset; i < s.length(); i++) { tmp = tmp + ch[i]; } return tmp; } } [THIS IS THE DEMO SCRIPT YOU SHOULD TEST WITH!] @name=Demo @author=PPL var{Username = PPL;Password = Demo;invFull = true} def start{ for(i = 0:2) log(LOL) log(LOOL) log(LOOOL) next } def main{ obj_rock = findObject(rockType) if(obj_rock != null) log(Mining...) endif }</pre> <a href="http://www.refactormycode.com/codes/337-simple-interpreter" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>