├── _config.yml ├── DError.java ├── DPreload.java ├── DCode.java ├── DRes.java ├── dni ├── DRegister.java ├── DSystem.java ├── DTest.java └── DArray.java ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── DNode.java ├── DAttribute.java ├── README.md ├── Main.java ├── DMathExpression.java ├── DTools.java ├── DObject.java ├── DClassExpression.java ├── DComplier.java ├── DReference.java ├── DFunction.java ├── DRuntime.java ├── DVariable.java ├── DClass.java └── DExpression.java /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /DError.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | 3 | public class DError { 4 | public DError(DComplier complier,String type,int line,int position){ 5 | complier.onError(""); 6 | } 7 | public DError(DComplier complier,String type){ 8 | if(type.equals("type")) 9 | complier.onError("Type error"); 10 | System.exit(0); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DPreload.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | 3 | import static com.dexer.dscript.DClass.*; 4 | import static com.dexer.dscript.DFunction.*; 5 | import static com.dexer.dscript.DComplier.*; 6 | import static com.dexer.dscript.DRes.*; 7 | class DPreload { 8 | public static void load(){ 9 | 10 | //getClassByName("Thread").addFunction(new DFunction("run",); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DCode.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | 3 | public class DCode { 4 | private String code; 5 | public DCode(String code){ 6 | this.code=code.replaceAll("\\n",""); 7 | } 8 | 9 | public void setCode(String code) { 10 | this.code = code.replaceAll("\\n",""); 11 | } 12 | 13 | public String getCode() { 14 | return code; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /DRes.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | public class DRes { 8 | static ArrayList vars = new ArrayList<>(); 9 | static HashMap threadMap = new HashMap<>(); 10 | static ArrayList cls = new ArrayList<>(); 11 | static ArrayList objs = new ArrayList<>(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /dni/DRegister.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript.dni; 2 | 3 | import com.dexer.dscript.DFunction; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | import static com.dexer.dscript.DFunction.*; 8 | public class DRegister { 9 | static Map map=new HashMap(); 10 | static{ 11 | DArray.load(); 12 | DTest.load(); 13 | DSystem.load(); 14 | } 15 | static void registerNativeMethods(Map map_){ 16 | map.putAll(map_); 17 | } 18 | public static NativeCode gain(String className,String methodName){ 19 | 20 | return map.get(className+"$"+methodName); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /dni/DSystem.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript.dni; 2 | 3 | import com.dexer.dscript.DComplier; 4 | import com.dexer.dscript.DFunction; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class DSystem { 10 | public static void load(){ 11 | Map map=new HashMap(); 12 | map.put("System$output",new DFunction.NativeCode(){ 13 | @Override 14 | public DFunction.ParamIns run(DFunction.ParamIns[] pi, String id) { 15 | System.out.println(pi[0].value); 16 | return null; 17 | } 18 | }); 19 | map.put("System$exit",new DFunction.NativeCode(){ 20 | @Override 21 | public DFunction.ParamIns run(DFunction.ParamIns[] pi, String id) { 22 | DComplier.complier.close(); 23 | return null; 24 | } 25 | }); 26 | DRegister.registerNativeMethods(map); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /DNode.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class DNode { 6 | private String id; 7 | private String type; 8 | private String content; 9 | private String condition="none"; 10 | private ArrayList sub_nodes=new ArrayList<>(); 11 | public void setType(String type) { 12 | this.type = type; 13 | } 14 | 15 | public void setCondition(String condition) { 16 | this.condition = condition; 17 | } 18 | 19 | public void setContent(String content) { 20 | this.content = content; 21 | } 22 | public void setId(String id){ 23 | this.id=id; 24 | } 25 | public String getType() { 26 | return type; 27 | } 28 | 29 | public String getCondition() { 30 | return condition; 31 | } 32 | 33 | public String getContent() { 34 | return content; 35 | } 36 | 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | public int getSize() { 42 | return sub_nodes.size(); 43 | } 44 | 45 | public ArrayList getSubNodes() { 46 | return sub_nodes; 47 | } 48 | 49 | public void addSubNode(DNode node){ 50 | sub_nodes.add(node); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /DAttribute.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | import static com.dexer.dscript.DClass.*; 3 | import static com.dexer.dscript.DFunction.*; 4 | public class DAttribute { 5 | public static final int STATIC=12; 6 | public static final int DYMASTIC=24; 7 | public static final int NATIVE=6; 8 | public static final int PUBLIC=1; 9 | public static final int PROTECTED=2; 10 | public static final int PRIVATE=3; 11 | private String name; 12 | private int vis; 13 | private int state; 14 | private ParamIns val; 15 | //NATIVE STATIC 14 16 | //NATIVE DYNASTIC 30 17 | DAttribute(String name,ParamIns val, int state,int vis){ 18 | this.state=state; 19 | this.name=name; 20 | this.vis=vis; 21 | this.val=val; 22 | 23 | } 24 | 25 | public ParamIns getVal() { 26 | return val; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | public int getState(){ 33 | return state; 34 | } 35 | 36 | public int getVisibility() { 37 | return vis; 38 | } 39 | 40 | public void setVal(ParamIns val) { 41 | this.val = val; 42 | } 43 | 44 | public void setName(String name) { 45 | this.name = name; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /dni/DTest.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript.dni; 2 | 3 | import com.dexer.dscript.DFunction; 4 | import com.dexer.dscript.DFunction.*; 5 | import com.dexer.dscript.DObject; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import static com.dexer.dscript.DClass.getObjectById; 11 | 12 | public class DTest{ 13 | public static void load(){ 14 | Map map=new HashMap(); 15 | map.put("Demo$getInfo",new DFunction.NativeCode(){ 16 | @Override 17 | public DFunction.ParamIns run(DFunction.ParamIns[] pi, String id) { 18 | System.out.println(123); 19 | return null; 20 | } 21 | }); 22 | map.put("MyClass$insert",new DFunction.NativeCode(){ 23 | @Override 24 | public DFunction.ParamIns run(DFunction.ParamIns[] pi, String id) { 25 | DObject obj=getObjectById(id); 26 | ParamIns ins=obj.getAttribute("string",DFunction.PUBLIC); 27 | StringBuilder sb=new StringBuilder(ins.value.substring(1,ins.value.length()-1)); 28 | System.out.println(sb.insert(2,pi[0].value.substring(1,pi[0].value.length()-1)).toString()); 29 | return null; 30 | } 31 | }); 32 | DRegister.registerNativeMethods(map); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DScript 2 | A new script language based on Java 3 | 4 | ## Features 5 | ### Assign a variable or const 6 | ``` javascript 7 | var a=12; //var 8 | con b=23; //const 9 | ``` 10 | The translation engine will recognize the type of the value automatically.This is just like JavaScript,which can help you simplify your assignment. 11 | ### Conditional branching with 'unless' 12 | ``` javascript 13 | var a=12; 14 | var b=23; 15 | if(ab?1:0); // 1 34 | System.output(a>c?1:0); // 0 35 | System.output(a>b?1); // 1 36 | System.output(a>c?1); // 25 37 | ``` 38 | You can even remove ':'.In this case,if true,it returns the value behind '?'.If false,it returns the left value of the condition. 39 | 40 | ### XOR 41 | ``` javascript 42 | System.output(12>5##3==6); //true 43 | System.output(12>5##3!=6); //false 44 | System.output(12<5##3==6); //false 45 | ``` 46 | Added '##' as XOR that compares the two boolean values beside it,returns true if they are differnt and returns false if not. 47 | 48 | ### Easy asynchronizing 49 | ``` javascript 50 | async("thread1"){ 51 | for(var i=0~100){ 52 | System.output(i); 53 | }; 54 | }; 55 | ``` 56 | Added 'async' to create a thread named what the parameter is. 57 | ### More features are coming soon! 58 | -------------------------------------------------------------------------------- /Main.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | 3 | 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.util.Arrays; 7 | import java.util.Scanner; 8 | 9 | import static com.dexer.dscript.DClass.*; 10 | import static com.dexer.dscript.DFunction.*; 11 | 12 | public class Main { 13 | public static void main(String[] args) { 14 | //DClassExpression.solveClass("class{pub static asfa(a d,a f){dh df}}"); 15 | new DComplier(new File("D:\\java project\\DScript\\out\\artifacts\\dscript\\script.ds")).compile(0,PUBLIC); 16 | Scanner scan_mod = new Scanner(System.in); 17 | String[] params = scan_mod.nextLine().split(" "); 18 | if (params[0].equals("dsc")) { 19 | switch (params[1]){ 20 | case "-v": 21 | System.out.println(DComplier.INFO); 22 | break; 23 | case "-run": 24 | System.out.println("Running..."); 25 | DComplier dc_ = new DComplier(new File(params[2])); 26 | dc_.compile(0, PUBLIC); 27 | System.out.println("Complete"); 28 | break; 29 | case "-help": 30 | System.out.println("//////////////////\n" + 31 | "dsc -v\t\t\t\t\tTo check the version\n" + 32 | "dsc -run \tTo run a script\n" + 33 | "dsc -help\t\t\t\tTo show help\n"+ 34 | "//////////////////"); 35 | break; 36 | default: 37 | System.out.println("Unknown command.Please check commands with \"dsc -help\""); 38 | } 39 | }else 40 | System.out.println("Unknown command.Please check commands with \"dsc -help\""); 41 | main(args); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /DMathExpression.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | import parsii.eval.Expression; 3 | import parsii.eval.Parser; 4 | import parsii.eval.Scope; 5 | import parsii.eval.Variable; 6 | import parsii.tokenizer.ParseException; 7 | 8 | import java.util.regex.Matcher; 9 | import java.util.regex.Pattern; 10 | 11 | public class DMathExpression { 12 | public static DFunction.ParamIns solveMathExpression(String exp,int area_id,int layout_id){ 13 | DFunction.ParamIns pii=null; 14 | { 15 | Pattern p = Pattern.compile("\\w+\\.\\w+\\(.*\\)"); 16 | Matcher matcher = p.matcher(exp); 17 | while (matcher.find()) { 18 | String target = matcher.group(); 19 | exp = exp.replace(target, DClass.runFunction(target, area_id, layout_id).value); 20 | } 21 | } 22 | { 23 | Pattern p = Pattern.compile("[a-zA-Z_]+\\.[a-zA-Z_]+"); 24 | Matcher matcher = p.matcher(exp); 25 | while (matcher.find()) { 26 | String target = matcher.group(); 27 | exp = exp.replace(target, DClass.getAttribute(target,area_id,layout_id).value); 28 | } 29 | } 30 | { 31 | Pattern p = Pattern.compile("[a-zA-Z_]+"); 32 | Matcher matcher = p.matcher(exp); 33 | while (matcher.find()) { 34 | String target = matcher.group(); 35 | exp = exp.replace(target, DReference.getVariableByName(target,area_id,layout_id).value); 36 | } 37 | } 38 | try { 39 | Scope scope=new Scope(); 40 | Expression exp_= Parser.parse(exp); 41 | double res=exp_.evaluate(); 42 | pii=new DFunction.ParamIns("num",res+""); 43 | 44 | } catch (ParseException e) { 45 | e.printStackTrace(); 46 | } 47 | return pii; 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /dni/DArray.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript.dni; 2 | 3 | import com.dexer.dscript.DClass; 4 | import com.dexer.dscript.DFunction; 5 | import com.dexer.dscript.DObject; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import static com.dexer.dscript.DClass.getObjectById; 11 | import static com.dexer.dscript.DFunction.PRIVATE; 12 | 13 | public class DArray { 14 | public static void load(){ 15 | Map map=new HashMap(); 16 | map.put("Array$init",new DFunction.NativeCode(){ 17 | @Override 18 | public DFunction.ParamIns run(DFunction.ParamIns[] pi, String id) { 19 | double length=Double.parseDouble(getObjectById(id).getAttribute("length",PRIVATE).value); 20 | StringBuilder sb=new StringBuilder(); 21 | for(int i=0;i a=new ArrayList<>(); 23 | String[] ss=s.split(""); 24 | String p=""; 25 | for(int i=0;i ress=new ArrayList<>(); 64 | String res=""; 65 | int mode=0; 66 | for(int i=0;i constructor=new ArrayList<>(); 13 | private DAttribute[] attrs; 14 | private String id; 15 | DObject(String type){ 16 | this.type=type; 17 | ArrayList c=getClassByName(type).getConstructor(); 18 | if(c!=null) { 19 | for(DFunction i : c){ 20 | constructor.add(new DFunction(i.getName(), i.getParams(), i.getState(), i.getVisibility(), i.getCode(), i.isNative())); 21 | } 22 | 23 | } 24 | List list=new ArrayList<>(); 25 | for(DFunction f:getClassByName(type).getAllFunctions()){ 26 | list.add(new DFunction(f.getName(),f.getParams(),f.getState(),f.getVisibility(),f.getCode(),f.isNative())); 27 | } 28 | funcs=list.toArray(new DFunction[0]); 29 | 30 | List list_=new ArrayList<>(); 31 | for(DAttribute a:getClassByName(type).getAllAttribute()){ 32 | list_.add(new DAttribute(a.getName(),a.getVal(),a.getState(),a.getVisibility())); 33 | } 34 | attrs=list_.toArray(new DAttribute[0]); 35 | id="[$"+count+"$]"; 36 | count++; 37 | } 38 | 39 | public String getType() { 40 | return type; 41 | } 42 | public String getId(){ 43 | return id; 44 | } 45 | public void reassignAttribute(String name,String value,int area_id,int layout_id){ 46 | for (int i = 0; i < attrs.length; i++) { 47 | String type=attrs[i].getVal().type; 48 | if(type.charAt(type.length()-1)!='$') 49 | if(attrs[i].getName().equals(name)){ 50 | attrs[i].setVal(requireReturn(value,area_id,layout_id)); 51 | } 52 | } 53 | } 54 | public void reassignAttributeForce(String name,String value,String type,int area_id,int layout_id){ 55 | for (int i = 0; i < attrs.length; i++) { 56 | if(attrs[i].getName().equals(name)) 57 | attrs[i]=new DAttribute(name,new ParamIns(type,value),attrs[i].getState(),attrs[i].getVisibility()); 58 | } 59 | } 60 | public ParamIns getAttribute(String name,int layout_id){ 61 | for(DAttribute attr : attrs){ 62 | if(attr.getName().equals(name)&&(attr.getVisibility()==layout_id||layout_id==PRIVATE)) 63 | return attr.getVal(); 64 | } 65 | return null; 66 | } 67 | public ParamIns runFunction(String name,ParamIns[] params,String id,int vis){ 68 | for(DFunction func : funcs){ 69 | if(func.getName().equals(name)&&func.getParams().length==params.length&&(func.getVisibility()==vis||vis==PRIVATE)){ 70 | if(params.length!=0) 71 | for (int i = 0; i < params.length; i++) { 72 | if(params[i].type.equals(func.getParams()[i].type)||func.getParams()[i].type.equals("Object")) { 73 | return func.run(params, id, vis); 74 | } 75 | } 76 | else return func.run(params, id, vis); 77 | } 78 | } 79 | return null; 80 | } 81 | public void runConstructor(ParamIns[] params,String id,int vis){ 82 | if(constructor!=null) { 83 | for(DFunction c : constructor){ 84 | if(c.getParams().length==params.length&&(vis==PRIVATE||c.getVisibility()==vis)) 85 | for(int i=0;i pl = new ArrayList<>(); 62 | String str = words[words.length - 1]; 63 | String[] param_strs = split(getContentInBracket(str, BRACKET_NORMAL), ","); 64 | 65 | String name_ = str.substring(0, indexOf(str, '(')); 66 | Param[] params; 67 | if (!getContentInBracket(str, BRACKET_NORMAL).equals("")) { 68 | for (String s : param_strs) { 69 | String[] temp = s.trim().split("\\s+"); 70 | pl.add(new Param(temp[0].equals("var")?"Object":temp[0], temp[1])); 71 | } 72 | params = pl.toArray(new Param[0]); 73 | } else params = new Param[0]; 74 | if (name_.equals(name)) { 75 | if(!isN) 76 | getClassByName(name).addFunction(new DFunction("constructor", params, state, vis, code.trim(), false)); 77 | else 78 | getClassByName(name).addFunction(new DFunction("constructor", params, state, vis, DRegister.gain(name,"$"), true)); 79 | } else { 80 | if(!isN) 81 | getClassByName(name).addFunction(new DFunction(name_, params, state, vis, code.trim(), false)); 82 | else 83 | getClassByName(name).addFunction(new DFunction(name_, params, state, vis,DRegister.gain(name,name_), true)); 84 | } 85 | } 86 | } 87 | return null; 88 | } 89 | static int indexOfVis(String str){ 90 | switch (str.trim()){ 91 | case "pub": 92 | return PUBLIC; 93 | case "pri": 94 | return PRIVATE; 95 | case "pro": 96 | return PROTECTED; 97 | } 98 | return -1; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /DComplier.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | 3 | import java.io.*; 4 | import java.util.ArrayList; 5 | import static com.dexer.dscript.DClass.*; 6 | import static com.dexer.dscript.DFunction.*; 7 | import static com.dexer.dscript.DReference.*; 8 | import static com.dexer.dscript.DVariable.*; 9 | import static com.dexer.dscript.DRuntime.*; 10 | public class DComplier{ 11 | public static final String VERSION="0.0.1 dev"; 12 | public static final String INFO = 13 | "//////////////////\n" + 14 | " DScript "+VERSION+"\n" + 15 | " Copyright c Dexer Matters\n" + 16 | " Feedback: https://github.com/DexerMatters/DScript/issues\n" + 17 | " Github: https://github.com/DexerMatters/DScript\n" + 18 | " Contact: 2353708378@qq.com or DexerMatters@gmail.com"+ 19 | "\n//////////////////"; 20 | private boolean enabled=true; 21 | private File file; 22 | private static int ins_num=0; 23 | public static DCode code; 24 | public static DComplier complier=null; 25 | public DComplier(DCode code){ 26 | ins_num++; 27 | DRuntime.comp_now=this; 28 | if(ins_num==1) { 29 | DRuntime.comp = this; 30 | complier = this; 31 | } 32 | this.code=code; 33 | } 34 | public DComplier(File file){ 35 | ins_num++; 36 | DRuntime.comp_now=this; 37 | if(ins_num==1) { 38 | DRuntime.comp = this; 39 | complier = this; 40 | } 41 | this.file=file; 42 | StringBuffer sb=new StringBuffer(); 43 | try { 44 | BufferedReader fis=new BufferedReader(new FileReader(file)); 45 | String line; 46 | while((line=fis.readLine())!=null) 47 | sb.append(line); 48 | } catch (IOException e) { 49 | e.printStackTrace(); 50 | } 51 | code=new DCode(sb.toString()); 52 | } 53 | public static void debug(ArrayList array){ 54 | for(T a:array) { 55 | if (a instanceof Variable) { 56 | Variable v= (Variable) a; 57 | System.out.println( 58 | "var : name:"+v.name+ ";\n"+ 59 | "var : type:"+v.type+";\n"+ 60 | "var : value:"+v.value); 61 | } 62 | if(a instanceof ParamIns){ 63 | ParamIns pi=(ParamIns) a; 64 | System.out.println( 65 | "param : type:"+pi.type+";\n"+ 66 | "param : value:"+pi.value); 67 | } 68 | } 69 | } 70 | public void preload(){ 71 | } 72 | public void close(){ 73 | enabled=false; 74 | } 75 | 76 | public void compile(int area_id,int layout_id){ 77 | compile(area_id, layout_id,"$Math"); 78 | } 79 | public void compile(int area_id,int layout_id,String clazz){ 80 | String code_str=code.getCode(); 81 | String line=""; 82 | DPreload.load(); 83 | preload(); 84 | //getClassByName("System").runFunction("output",new ParamIns[]{new ParamIns("String","hello")}); 85 | for (int i = 0; i < code_str.length(); i++) { 86 | 87 | if(code_str.charAt(i)==';'&&enabled){ 88 | if(!(hasCovered(code_str,i,BRACLET_STRING)||hasCovered(code_str,i,BRACLET_CURLY)||hasCovered(code_str,i,BRACKET_NORMAL))) { 89 | line = line.trim(); 90 | DClassExpression.solveClass(line); 91 | importVariable(line, area_id, layout_id); 92 | assignVariable(line, area_id, layout_id); 93 | assignVariableAs(line, area_id, layout_id); 94 | solveKeyword(code_str, line, i, area_id, layout_id); 95 | runFunction(line, area_id, layout_id); 96 | line = ""; 97 | }else line+=code_str.charAt(i); 98 | }else 99 | line+=code_str.charAt(i); 100 | 101 | } 102 | } 103 | 104 | public String getFileAbsolutePath(){ 105 | return file.getAbsolutePath(); 106 | } 107 | public void onError(String message){ 108 | System.out.println(message); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /DReference.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | import java.util.Arrays; 3 | 4 | import static com.dexer.dscript.DClass.requireReturn; 5 | import static com.dexer.dscript.DVariable.*; 6 | import static com.dexer.dscript.DRes.*; 7 | public class DReference{ 8 | public static char[] 9 | BRACKET_SQUARE={'[','}'}, 10 | BRACKET_NORMAL={'(',')'}, 11 | BRACLET_STRING={'\"','\"'}, 12 | BRACLET_CURLY={'{','}'}; 13 | public static DComplier comp; 14 | 15 | public static void reassignToVar(Variable leftV, Variable rightV){ 16 | if(leftV.type.charAt(leftV.type.length()-1)!='$') 17 | vars.get(indexOf(leftV)).value=rightV.value; 18 | } 19 | public static void reassignToVal(Variable leftV,String type,String value,int area_id,int layout_id){ 20 | if(leftV.type.charAt(leftV.type.length()-1)!='$') 21 | vars.get(indexOf(leftV)).value=requireReturn(value,area_id,layout_id).value; 22 | } 23 | public static boolean isVaild(Variable v,int area_id,int layout_id,String name){ 24 | return (v.area_id==area_id||v.layout_id<=layout_id)&&v.name.equals(name); 25 | } 26 | public static String getTypeByName(String name,int area_id,int layout_id){ 27 | String r=null; 28 | for(Variable v : vars){ 29 | if(isVaild(v,area_id,layout_id,name)){ 30 | r=v.type; 31 | } 32 | } 33 | return r; 34 | } 35 | public static String getValueByName(String name,int area_id,int layout_id){ 36 | String r=null; 37 | for(Variable v : vars){ 38 | if(isVaild(v,area_id,layout_id,name)){ 39 | r=v.type; 40 | } 41 | } 42 | return r; 43 | } 44 | public static Variable getVariableByName(String name,int area_id,int layout_id){ 45 | Variable r=null; 46 | for(Variable v : vars){ 47 | if(isVaild(v,area_id,layout_id,name)){ 48 | r=v; 49 | } 50 | } 51 | return r; 52 | } 53 | public static boolean hasCovered(String str,int pos,char[] bracket){ 54 | 55 | //System.out.println(code); 56 | int left = 0, right = 0; 57 | for (int i = pos; i < str.length(); i++) { 58 | if (!Arrays.equals(bracket, BRACLET_STRING)) { 59 | if (str.charAt(i) == bracket[1]) 60 | right++; 61 | if (str.charAt(i) == bracket[0]) 62 | right--; 63 | } else if (str.charAt(i) == bracket[0]) 64 | right++; 65 | } 66 | for (int i = pos; i >= 0; i--) { 67 | if (!Arrays.equals(bracket, BRACLET_STRING)) { 68 | if (str.charAt(i) == bracket[0]) 69 | left++; 70 | if (str.charAt(i) == bracket[1]) 71 | left--; 72 | } else if (str.charAt(i) == bracket[0]) 73 | left++; 74 | } 75 | if (!Arrays.equals(bracket, BRACLET_STRING)) { 76 | return right == left && right + left != 0; 77 | } else return left % 2 != 0 || right % 2 != 0; 78 | } 79 | public static int getIndexCovered(String str,int pos,char[] bracket){ 80 | 81 | //System.out.println(code); 82 | int left = 0, right = 0; 83 | for (int i = pos + 1; i < str.length(); i++) { 84 | if (str.charAt(i) == bracket[1]) 85 | right++; 86 | if (str.charAt(i) == bracket[0]) 87 | right--; 88 | } 89 | for (int i = pos - 1; i >= 0; i--) { 90 | if (str.charAt(i) == bracket[0]) 91 | left++; 92 | if (str.charAt(i) == bracket[1]) 93 | left--; 94 | } 95 | return Math.abs(left*right); 96 | } 97 | public static int indexOf(Variable var){ 98 | int ptr=-1; 99 | for(Variable v : vars){ 100 | ptr++; 101 | if(isVaild(v,var.area_id,var.layout_id,var.name)) 102 | return ptr; 103 | } 104 | return ptr; 105 | } 106 | public static boolean isTrue(DFunction.ParamIns bool){ 107 | return bool.value.equals("true"); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /DFunction.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | 3 | import java.lang.ref.Reference; 4 | import java.lang.reflect.Method; 5 | import java.util.ArrayList; 6 | import java.util.Queue; 7 | 8 | import static com.dexer.dscript.DRes.vars; 9 | import static com.dexer.dscript.DVariable.*; 10 | import static com.dexer.dscript.DReference.*; 11 | import static com.dexer.dscript.DClass.*; 12 | public class DFunction { 13 | public static class Param{ 14 | public String type; 15 | public String name; 16 | public Param(String type,String name){ 17 | this.name=name; 18 | this.type=type; 19 | } 20 | } 21 | public static class ParamIns{ 22 | public String type; 23 | public String value; 24 | public ParamIns(String type,String value){ 25 | this.value=value; 26 | this.type=type; 27 | } 28 | 29 | @Override 30 | public boolean equals(Object obj) { 31 | return this.value.equals(((ParamIns) obj).value); 32 | } 33 | } 34 | public static class NativeCode{ 35 | public ParamIns run(ParamIns[] pi,String id){ 36 | return null; 37 | }; 38 | 39 | } 40 | private Param[] params; 41 | private int state; 42 | private NativeCode code_code; 43 | private String code_str; 44 | private Object code_obj; 45 | private String name; 46 | private int vis; 47 | private boolean isNative; 48 | public static final int STATIC=12; 49 | public static final int DYMASTIC=24; 50 | public static final int PUBLIC=1; 51 | public static final int PROTECTED=2; 52 | public static final int PRIVATE=3; 53 | //NATIVE STATIC 14 54 | //NATIVE DYNASTIC 30 55 | DFunction(String name,Param[] params, int state,int vis, Object code,boolean isNative){ 56 | this.params=params; 57 | this.state=state; 58 | this.name=name; 59 | this.vis=vis; 60 | this.isNative=isNative; 61 | this.code_obj=code; 62 | if(isNative) 63 | this.code_code=(NativeCode) code_obj; 64 | else{ 65 | code_str = (String) code_obj; 66 | this.code_code=new NativeCode(){ 67 | @Override 68 | public ParamIns run(ParamIns[] pi, String id) { 69 | DObject obj=getObjectById(id); 70 | int index=0; 71 | ArrayList list=new ArrayList<>(); 72 | if(obj!=null) { 73 | Variable v=createVariable(obj.getType() + "$", "self", obj.getId(), 0, PRIVATE); 74 | vars.add(v); 75 | list.add(v); 76 | } 77 | if(params.length!=0) 78 | for(ParamIns i : pi) { 79 | Variable v = createVariable(i.type, params[index].name, i.value, 1, 0); 80 | vars.add(v); 81 | list.add(v); 82 | index++; 83 | } 84 | new DComplier(new DCode(code_str)).compile(1,PRIVATE); 85 | Variable returns = getVariableByName("__return",1,0); 86 | for(Variable a : list) removeVariable(a); 87 | removeVariableByAreaId(1); 88 | if(returns!=null) 89 | return new ParamIns(returns.type,returns.value); 90 | return new ParamIns("Null","null"); 91 | } 92 | }; 93 | } 94 | 95 | } 96 | public ParamIns run(ParamIns[] ins,String id,int vis){ 97 | if (ins.length == params.length) 98 | for (int i = 0; i < ins.length; i++) { 99 | if(ins[i]!=null) 100 | if (!(ins[i].type.equals(params[i].type) || params[i].type.equals("Object"))) { 101 | return null; 102 | } 103 | } 104 | if (code_code != null) 105 | return code_code.run(ins,id); 106 | return null; 107 | } 108 | 109 | public int getVisibility() { 110 | return vis; 111 | } 112 | 113 | public Object getCode() { 114 | return code_obj; 115 | } 116 | 117 | public String getCodeString() { 118 | return code_str; 119 | } 120 | 121 | public String getName() { 122 | return name; 123 | } 124 | 125 | public Param[] getParams() { 126 | return params; 127 | } 128 | 129 | public int getState() { 130 | return state; 131 | } 132 | public boolean isNative(){ 133 | return isNative; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /DRuntime.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | import java.io.File; 3 | import java.sql.Array; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.HashMap; 7 | 8 | import static com.dexer.dscript.DClass.*; 9 | import static com.dexer.dscript.DFunction.*; 10 | import static com.dexer.dscript.DReference.*; 11 | import static com.dexer.dscript.DTools.*; 12 | import static com.dexer.dscript.DVariable.*; 13 | public class DRuntime { 14 | public static DComplier comp; 15 | public static DComplier comp_now; 16 | public static HashMap thrs=new HashMap<>(); 17 | public static void solveKeyword(String code,String line,int index,int area_id,int layout_id){ 18 | File file_=new File(comp.getFileAbsolutePath()); 19 | if(line.matches("^(if|unless)\\s*\\(.+\\)\\s*\\{.*}")) { 20 | ParamIns condition = requireReturn(line.substring(indexOf(line, '(') + 1, indexOf(line, ')')),area_id,layout_id); 21 | String flag=line.substring(0,indexOf(line, '(')); 22 | String[] code_strs=getContentInBracket_(line,BRACLET_CURLY); 23 | DCode runs = new DCode(code_strs[0]); 24 | if (flag.equals("if")&&isTrue(condition)) 25 | new DComplier(runs).compile(area_id, layout_id); 26 | if (flag.equals("unless")&&!isTrue(condition)) 27 | new DComplier(runs).compile(area_id, layout_id); 28 | if(code_strs.length==2){ 29 | DCode elses=new DCode(code_strs[1]); 30 | if (flag.equals("if")&&!isTrue(condition)) 31 | new DComplier(elses).compile(area_id, layout_id); 32 | if (flag.equals("unless")&&isTrue(condition)) 33 | new DComplier(elses).compile(area_id, layout_id); 34 | 35 | } 36 | }//for(Integer i=0 > 15) 37 | if(line.matches("^for\\s*\\(.+\\)\\s*\\{.*}$")){ 38 | String condition =line.substring(indexOf(line, '(') + 1, indexOf(line, ')')); 39 | String code_strs=getContentInBracket(line,BRACLET_CURLY); 40 | String[] conds=split(condition,"~"); 41 | if(conds.length==2) { 42 | Variable v = importVariable(conds[0], area_id, layout_id); 43 | 44 | double from = Double.parseDouble(v.value); 45 | double to = Double.parseDouble(requireReturn(conds[1],area_id,layout_id).value); 46 | if(from= to; i--) { 54 | reassignToVal(v, v.type, Double.toString(i), area_id, layout_id); 55 | DCode runs = new DCode(code_strs); 56 | new DComplier(runs).compile(area_id, layout_id); 57 | } 58 | } 59 | removeVariable(v); 60 | }else{ 61 | conds=split(condition,";"); 62 | Variable v = importVariable(conds[0], area_id, layout_id); 63 | ParamIns cond=requireReturn(conds[1],area_id,layout_id); 64 | 65 | while(DReference.isTrue(cond)){ 66 | 67 | DCode runs = new DCode(code_strs); 68 | new DComplier(runs).compile(area_id,layout_id); 69 | DCode runs_ = new DCode(conds[2]+";"); 70 | new DComplier(runs_).compile(area_id,layout_id); 71 | cond=requireReturn(conds[1],area_id,layout_id); 72 | } 73 | removeVariable(v); 74 | } 75 | } 76 | if(line.matches("^async\\s*\\(.+\\)\\s*\\{.*}$")){ 77 | String name =line.substring(indexOf(line, '(') + 1, indexOf(line, ')')); 78 | String code_strs=getContentInBracket(line,BRACLET_CURLY); 79 | importVariable("var "+name+"="+"new Thread(\""+name+"\",\""+code_strs+"\")",area_id,layout_id); 80 | } 81 | if(line.matches("^rm\\s+[a-zA-Z_]+$")){ 82 | String name =line.split("\\s+")[1]; 83 | removeVariable(getVariableByName(name,area_id,layout_id)); 84 | } 85 | if(line.matches("^ret\\s+.+$")){ 86 | String val =addBehind(line.split("\\s+")," ")[1]; 87 | importVariable("var __return="+val,1,layout_id); 88 | comp_now.close(); 89 | } 90 | if(line.matches("^imp\\s+.+$")){ 91 | String val =line.split("\\s+")[1]; 92 | 93 | //System.out.println(comp.getFileAbsolutePath()); 94 | File file=new File(file_.getParentFile().getAbsoluteFile()+File.separator+val); 95 | new DComplier(file).compile(0,0); 96 | } 97 | if(line.matches("^imps\\s+.+$")){ 98 | String val =line.split("\\s+")[1]; 99 | File file=new File(file_.getParentFile().getAbsoluteFile()+File.separator+val); 100 | File[] files=file.listFiles(); 101 | for(File f : files){ 102 | new DComplier(f).compile(0,0); 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /DVariable.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | 6 | import static com.dexer.dscript.DFunction.PUBLIC; 7 | import static com.dexer.dscript.DRes.*; 8 | import static com.dexer.dscript.DReference.*; 9 | import static com.dexer.dscript.DClass.*; 10 | import static com.dexer.dscript.DExpression.*; 11 | public class DVariable{ 12 | static class Variable{ 13 | String type; 14 | String value; 15 | String name; 16 | int area_id; 17 | int layout_id; 18 | } 19 | 20 | 21 | static Variable importVariable(String var_str, int area_id,int layout_id){ 22 | Variable var=new Variable(); 23 | var.area_id=area_id; 24 | var.layout_id=layout_id; 25 | if(var_str.matches("^(var|con)\\s+[\\W\\w_\\d]+(\\s*=\\s*.+)?$")) { 26 | if(var_str.contains("=")) { 27 | 28 | String[] strs = addBehind(var_str.split("="), "="); 29 | if (strs.length == 2) { 30 | DFunction.ParamIns pi = requireReturn(strs[1], area_id, layout_id); 31 | var.value = pi.value; 32 | String[] s = strs[0].split("\\s+"); 33 | if (s.length == 2 && s[0].equals("var")) { 34 | var.type = DClass.getTypeOf(pi.value); 35 | var.name = s[1]; 36 | vars.add(var); 37 | } 38 | if (s.length == 2 && s[0].equals("con")) { 39 | var.type = DClass.getTypeOf(requireReturn(strs[1], area_id, layout_id).value) + "$"; 40 | var.name = s[1]; 41 | vars.add(var); 42 | } 43 | } 44 | }else{ 45 | String[] s = var_str.split("\\s+"); 46 | if(s[0].equals("var")){ 47 | var.type="Null"; 48 | var.name=s[1]; 49 | vars.add(var); 50 | } 51 | } 52 | } 53 | return var; 54 | } 55 | static void assignVariable(String str, int area_id,int layout_id) { 56 | if (str.matches("^[\\W\\w_\\d.\\[\\]]+\\s*=\\s*.+$")) { 57 | String[] strs = addBehind(str.split("="), "="); 58 | if(strs[0].contains("var")||strs[0].contains("con")) return; 59 | Variable tar=getVariableByName(strs[0], area_id, layout_id); 60 | DFunction.ParamIns vic=requireReturn(strs[1],area_id,layout_id); 61 | if(strs[0].indexOf('[')!=-1){ 62 | String[] v=anaylzeArrayGetter(strs[0],area_id,layout_id); 63 | getObjectById(v[0]).runFunction("set",new DFunction.ParamIns[]{new DFunction.ParamIns("num",v[1]),new DFunction.ParamIns(vic.type,vic.value)},v[0],PUBLIC); 64 | } else if (strs[0].indexOf('.') == -1) { 65 | if(tar.type.equals("Null")) tar.type=vic.type; 66 | reassignToVal(tar, vic.type, vic.value, area_id, layout_id); 67 | }else { 68 | String[] temp = strs[0].split("\\."); 69 | Variable v = getVariableByName(temp[0], 0, 0); 70 | if (v == null) { 71 | getClassByName(temp[0]).reassignAttribute(temp[1], requireReturn(strs[1], area_id, layout_id).value); 72 | } else 73 | getObjectById(requireReturn(temp[0], area_id, layout_id).value).reassignAttribute(temp[1], requireReturn(strs[1], area_id, layout_id).value, area_id, layout_id); 74 | } 75 | } 76 | } 77 | static String assignVariableAs(String str,int area_id,int layout_id){ 78 | if(str.matches("^.+\\s*[+\\-][+\\-]$")){ 79 | String temp=cleanBracket(str.substring(0,str.length()-2).trim()); 80 | String sym=str.substring(str.length()-2).trim(); 81 | Variable v=getVariableByName(temp,area_id,layout_id); 82 | if(v.type.equals("num")) { 83 | int del= sym.equals("++")?1:-1; 84 | reassignToVal(v, "num", String.valueOf(Integer.parseInt(v.value) + del), area_id, layout_id); 85 | return getVariableByName(temp,area_id,layout_id).value; 86 | } 87 | else new DError(comp,"type"); 88 | } 89 | if(str.matches("^[+\\-][+\\-]\\s*.+$")){ 90 | String temp=str.substring(2).trim(); 91 | String sym=str.substring(0,2).trim(); 92 | Variable v=getVariableByName(temp,area_id,layout_id); 93 | if(v.type.equals("num")) { 94 | int del= sym.equals("++")?1:-1; 95 | String v_=v.value; 96 | reassignToVal(v, "num", String.valueOf(Integer.parseInt(v.value) + del), area_id, layout_id); 97 | return v_; 98 | } 99 | else new DError(comp,"type"); 100 | } 101 | return null; 102 | } 103 | static void removeVariable(Variable v){ 104 | vars.remove(v); 105 | } 106 | static void removeVariableByAreaId(int id){ 107 | ArrayList arr=(ArrayList) vars.clone(); 108 | for(Variable v:arr){ 109 | if(v.area_id==id) 110 | vars.remove(v); 111 | } 112 | } 113 | static Variable createVariable(String type,String name,String value,int area_id,int layout_id){ 114 | Variable v=new Variable(); 115 | v.name=name; 116 | v.type=type; 117 | v.value=value; 118 | v.area_id=area_id; 119 | v.layout_id=layout_id; 120 | return v; 121 | } 122 | static int indexOf(Variable var){ 123 | int ptr=-1; 124 | for(Variable v : vars){ 125 | ptr++; 126 | if(v.layout_id<=var.layout_id&&v.area_id==var.area_id&& v.name.equals(var.name)) 127 | return ptr; 128 | } 129 | return ptr; 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /DClass.java: -------------------------------------------------------------------------------- 1 | package com.dexer.dscript; 2 | 3 | import java.lang.reflect.Array; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | import static com.dexer.dscript.DReference.*; 9 | import static com.dexer.dscript.DVariable.*; 10 | import static com.dexer.dscript.DFunction.*; 11 | import static com.dexer.dscript.DExpression.*; 12 | import static com.dexer.dscript.DTools.*; 13 | import static com.dexer.dscript.DRes.*; 14 | public class DClass{ 15 | 16 | public static class Class { 17 | private String name; 18 | private ArrayList static_func=new ArrayList<>(), 19 | dymastic_func=new ArrayList<>(); 20 | private ArrayList static_attr=new ArrayList<>(), 21 | dymastic_attr=new ArrayList<>(); 22 | private ArrayList constructor=new ArrayList<>(); 23 | private Class(String name){ 24 | this.name=name; 25 | } 26 | public String newInstance(ParamIns[] pi,int vis){ 27 | DObject o=new DObject(name); 28 | objs.add(o); 29 | o.runConstructor(pi,o.getId(),vis); 30 | return o.getId(); 31 | } 32 | 33 | 34 | public void addFunction(DFunction function){ 35 | if(!function.getName().equals("constructor")) 36 | if(function.getState()==DFunction.DYMASTIC) { 37 | dymastic_func.add(function); 38 | }else 39 | static_func.add(function); 40 | else constructor.add(function); 41 | } 42 | public void addAttribute(DAttribute attribute){ 43 | if(attribute.getState()==DAttribute.DYMASTIC||attribute.getState()==(DAttribute.DYMASTIC|DAttribute.NATIVE)) 44 | dymastic_attr.add(attribute); 45 | else 46 | static_attr.add(attribute); 47 | } 48 | public ParamIns runStaticFunction(String name, DFunction.ParamIns[] params,String id,int vis){ 49 | for(DFunction func :static_func){ 50 | if(func.getName().equals(name)&&func.getParams().length==params.length&&(func.getVisibility()==vis||vis==PRIVATE)){ 51 | if(func.getParams().length!=0) 52 | for (int i = 0; i < params.length; i++) { 53 | if(params[i].type.equals(func.getParams()[i].type)||func.getParams()[i].type.equals("Object")) { 54 | return func.run(params, id, vis); 55 | } 56 | } 57 | else return func.run(params, id, vis); 58 | } 59 | } 60 | return null; 61 | } 62 | public DFunction[] getAllFunctions(){ 63 | return dymastic_func.toArray(new DFunction[0]); 64 | } 65 | public DAttribute[] getAllAttribute(){ 66 | return dymastic_attr.toArray(new DAttribute[0]); 67 | } 68 | public ArrayList getConstructor(){ 69 | return constructor; 70 | } 71 | public ParamIns reassignAttribute(String name,String value){ 72 | for (int i = 0; i < static_attr.size(); i++) { 73 | String type=static_attr.get(i).getVal().type; 74 | if(type.charAt(type.length()-1)!='$') 75 | if(static_attr.get(i).getName().equals(name)) 76 | static_attr.get(i).setVal(requireReturn(value,0,0)); 77 | } 78 | return null; 79 | } 80 | public ParamIns getAttribute(String name, int layout_id){ 81 | for(DAttribute attr : static_attr) { 82 | if (attr.getName().equals(name)) { 83 | if(layout_id==attr.getVisibility()||layout_id==PRIVATE) 84 | return attr.getVal(); 85 | } 86 | } 87 | return null; 88 | } 89 | 90 | } 91 | 92 | static ParamIns instanceClass(String str, int area_id, int layout_id){ 93 | str=str.trim(); 94 | String type=str.substring(indexOf(str,'w')+2,indexOf(str,'(')).trim(); 95 | String temp=getContentInBracket(str,BRACKET_NORMAL); 96 | ArrayList pis=new ArrayList<>(); 97 | if(!temp.equals("")) { 98 | for (String s : split(temp, ",")) 99 | pis.add(requireReturn(s.trim(), area_id, layout_id)); 100 | return new ParamIns(type, getClassByName(type).newInstance(pis.toArray(new ParamIns[0]), layout_id)); 101 | } 102 | else { 103 | return new ParamIns(type, getClassByName(type).newInstance(new ParamIns[0], layout_id)); 104 | } 105 | } 106 | static ParamIns runFunction(String str,int area_id,int layout_id){ 107 | 108 | if(str.matches("^.+\\.\\w+\\(.*\\)$")){ 109 | String[] strs=split(str,"."); 110 | strs=addFront(strs,"."); 111 | if(!strs[0].matches("^[\\W\\w_]+$")) return null; 112 | String params; 113 | ArrayList pis=new ArrayList<>(); 114 | params=getContentInBracket_(str,BRACKET_NORMAL)[getContentInBracket_(str,BRACKET_NORMAL).length-1]; 115 | ParamIns[] array; 116 | if(params.equals("")) array=new ParamIns[0]; 117 | else { 118 | for (String s : split(params, ",")) 119 | pis.add(requireReturn(s.trim(), area_id, layout_id)); 120 | array = pis.toArray(new ParamIns[0]); 121 | } 122 | DClass.Class v=getClassByName(strs[0]); 123 | if(v!=null) 124 | return getClassByName(strs[0]).runStaticFunction(strs[1].substring(0,indexOf(strs[1],'(')),array,"null",layout_id); 125 | else{ 126 | DObject obj=getObjectById(requireReturn(strs[0],area_id,layout_id).value); 127 | return obj.runFunction(strs[1].substring(0,indexOf(strs[1],'(')),array,obj.getId(),layout_id); 128 | } 129 | //System.out.println(strs[1]+"|"+name+"|"+params); 130 | } 131 | return null; 132 | } 133 | public static ParamIns getAttribute(String str,int area_id,int layout_id){ 134 | String[] temp=split(str,"."); 135 | temp=addFront(temp,"."); 136 | Class v=getClassByName(temp[0]); 137 | if(v!=null) 138 | return getClassByName(temp[0]).getAttribute(temp[1],layout_id); 139 | else { 140 | 141 | return getObjectById(requireReturn(temp[0], area_id, layout_id).value).getAttribute(temp[1],layout_id); 142 | } 143 | } 144 | static int index=0; 145 | public static String getTypeOf(String str){ 146 | index=0; 147 | if(str.matches("^\".*\"s$")) 148 | return "String"; 149 | if(str.matches("^\".*\"$")) 150 | return "string"; 151 | if(str.matches("^-?[0-9]+\\.*[0-9]+$")) 152 | return "num"; 153 | if(str.matches("^(true|false)$")) 154 | return "bool"; 155 | if(str.matches("^.+\\.[a-zA-Z_]+$")) 156 | return "attribute"; 157 | if(str.matches("^\\{.+}$")) 158 | return "Array"; 159 | if(str.matches("^\\[\\$.+\\$]$")) 160 | return "Object"; 161 | if(str.matches("^new\\s+[a-zA-Z_]+\\s*\\(.*\\)$")) 162 | return "objectInstance"; 163 | if(str.matches("^\\w+\\.\\w+\\(.*\\)$")) 164 | return "function"; 165 | if(isBoolExpressionResult(str)!=null) 166 | return "bool_expression"; 167 | if((index=isEquality(str))!=-1) 168 | return "equality"; 169 | if((index=isInequality(str))!=-1) 170 | return "inequality"; 171 | 172 | if(str.matches("^[a-zA-Z_]+$")) 173 | return "variable"; 174 | return "expression"; 175 | } 176 | public static String getObjTypeOf(String str){ 177 | return getObjectById(str).getType(); 178 | } 179 | public static ParamIns requireReturn(String str, int area_id, int layout_id){ 180 | str=cleanBracket(str); 181 | 182 | switch (getTypeOf(str)){ 183 | case "string": 184 | return new ParamIns(getTypeOf(str),str); 185 | case "String": 186 | String id=getClassByName("String").newInstance(new ParamIns[]{new ParamIns("string",str.substring(0,str.length()-1))},layout_id); 187 | return requireReturn(id,area_id,layout_id); 188 | case "Array": 189 | return getArrayExpressionResult(str,area_id,layout_id); 190 | case "Object": 191 | return new ParamIns(getObjectById(str).getType(),str); 192 | case "objectInstance": 193 | return instanceClass(str,area_id,layout_id); 194 | case "variable": 195 | Variable var= getVariableByName(str, area_id, layout_id); 196 | return new ParamIns(var.type,var.value); 197 | case "function": 198 | return runFunction(str,area_id,layout_id); 199 | case "bool_expression": 200 | return getBoolExpressionResult(str,area_id,layout_id); 201 | case "equality": 202 | return getEqualityResult(str,area_id,layout_id); 203 | case "inequality": 204 | return getInequalityResult(str,area_id,layout_id); 205 | case "attribute": 206 | return getAttribute(str,area_id,layout_id); 207 | case "expression": 208 | return getExpressionResult(str, area_id, layout_id); 209 | } 210 | 211 | return new ParamIns(getTypeOf(str),str); 212 | } 213 | public static String[] addBehind(String[] str,String insert){ 214 | String s=""; 215 | for(int i=1;i'|| 42 | str.charAt(i-1)=='!' 43 | )) 44 | r=i-1; 45 | if( !hasCovered(str,i,BRACKET_NORMAL)&& 46 | !hasCovered(str,i,BRACLET_STRING)&& 47 | (str.charAt(i)=='<'|| 48 | str.charAt(i)=='>')) 49 | r=i; 50 | if( !hasCovered(str,i,BRACLET_STRING)&& 51 | !hasCovered(str,i,BRACKET_NORMAL)&& 52 | str.charAt(i)=='?') 53 | r=-1; 54 | } 55 | return r; 56 | } 57 | public static ParamIns getEqualityResult(String str,int area_id,int layout_id){ 58 | int index=isEquality(str); 59 | String[] strs={ 60 | str.substring(0,index).trim(), 61 | str.substring(index+2).trim() 62 | }; 63 | if(requireReturn(strs[0], layout_id, area_id).equals(requireReturn(strs[1], layout_id, area_id))) 64 | return new ParamIns("bool","true"); 65 | else 66 | return new ParamIns("bool","false"); 67 | } 68 | public static ParamIns getInequalityResult(String str,int area_id,int layout_id){ 69 | int index=isInequality(str); 70 | String sym=str.charAt(index)+""+str.charAt(index+1); 71 | String[] strs; 72 | if(sym.charAt(1)=='=') 73 | strs= new String[]{ 74 | str.substring(0, index).trim(), 75 | str.substring(index + 2).trim() 76 | }; 77 | else 78 | strs= new String[]{ 79 | str.substring(0, index).trim(), 80 | str.substring(index + 1).trim() 81 | }; 82 | int A=Integer.parseInt(requireReturn(strs[0], layout_id, area_id).value); 83 | int B=Integer.parseInt(requireReturn(strs[1], layout_id, area_id).value); 84 | 85 | if(sym.equals("<=")) 86 | return new ParamIns("bool",Boolean.toString(A<=B)); 87 | else if(sym.equals(">=")) 88 | return new ParamIns("bool",Boolean.toString(A>=B)); 89 | else if(sym.equals("!=")) 90 | return new ParamIns("bool",Boolean.toString(A!=B)); 91 | else if(sym.charAt(0)=='<') 92 | return new ParamIns("bool",Boolean.toString(A') 94 | return new ParamIns("bool",Boolean.toString(A>B)); 95 | return null; 96 | } 97 | public static ParamIns getExpressionResult(String str,int area_id,int layout_id){ 98 | String value; 99 | if(str.matches("^!.+$")){ 100 | String temp=cleanBracket(str.substring(1)); 101 | 102 | ParamIns pi=requireReturn(temp,area_id,layout_id); 103 | if(pi.type.equals("bool")) { 104 | return new ParamIns("bool",Boolean.toString(!Boolean.parseBoolean(pi.value))); 105 | }else 106 | return null; 107 | } 108 | else if((value=assignVariableAs(str,area_id,layout_id)) != null){ 109 | return new ParamIns("num",value); 110 | } 111 | // if(str.matches("^\\(\\w+\\)\\s*.+$")){ 112 | // String type_casted=str.substring(1,str.indexOf(")")); 113 | // String temp=cleanBracket(str.substring(str.indexOf(")")+1).trim()); 114 | // String val=requireReturn(temp,area_id,layout_id).value; 115 | // String type=requireReturn(temp,area_id,layout_id).type; 116 | // if(type.equals("String")) 117 | // return new ParamIns(type_casted,val.substring(1,val.length()-1)); 118 | // else 119 | // return new ParamIns(type_casted,"\""+val+"\""); 120 | // } 121 | else if(str.matches("^.+\\?.+(:.+)?$")){ 122 | int mode=0; 123 | String condition="", 124 | iftrue="", 125 | iffalse=""; 126 | for(int i=0;i ar=new ArrayList<>(); 167 | for(int i=1;i=2) { 188 | int index = 0; 189 | for (int i : ar) { 190 | index++; 191 | String sym = str.charAt(i - 1) + "" + str.charAt(i); 192 | syms[index-1] = sym; 193 | strs[index] = str.substring(ar[index - 1] + 1, ar[index] - 1); 194 | if (index == ar.length - 1) break; 195 | } 196 | } 197 | int last=ar[ar.length-1]; 198 | syms[syms.length-1]=str.charAt(last-1) + "" + str.charAt(last); 199 | strs[0]=str.substring(0,ar[0]-1); 200 | strs[strs.length-1]=str.substring(last+1); 201 | //Second 202 | ParamIns[] pis=new ParamIns[strs.length]; 203 | for (int i = 0; i < pis.length; i++) 204 | pis[i]=requireReturn(strs[i],area_id,layout_id); 205 | int ptr=0; 206 | while(ptr2) { 244 | if ((str.charAt(0) + "" + str.charAt(str.length() - 1)).equals("()")) 245 | return str.substring(1, str.length() - 1); 246 | else 247 | return str; 248 | }else 249 | return str; 250 | } 251 | private static ParamIns bool_and(ParamIns A,ParamIns B){ 252 | return new ParamIns("bool",Boolean.toString(Boolean.parseBoolean(A.value)&&Boolean.parseBoolean(B.value))); 253 | } 254 | private static ParamIns bool_or(ParamIns A,ParamIns B){ 255 | return new ParamIns("bool",Boolean.toString(Boolean.parseBoolean(A.value)||Boolean.parseBoolean(B.value))); 256 | } 257 | private static ParamIns bool_xor(ParamIns A,ParamIns B){ 258 | return new ParamIns("bool",Boolean.toString(Boolean.logicalXor(Boolean.parseBoolean(A.value),Boolean.parseBoolean(B.value)))); 259 | } 260 | } 261 | --------------------------------------------------------------------------------