Atitti.java Exp AST Java expression Syntax ast constructor

Source: Internet
Author: User
Tags addall object object tojson

Atitti.java Exp AST Java expression syntax ast Constructor

/atiplat_cms/src/com/attilax/lang/astparser.java

Principle

Split Tokens_slice_li

Analysis splitor, mostly dot and end

Author :: ★ (Attilax) >>>   nickname : Span style= "font-family: the song Body;" > old wow Paw   (   attilax akbar  al rapanui  Attilax   Baroque   Alpha   Rapa Nui   )   Kanji name: Ayron, Email:[email protected]

reprint Please indicate source: http://www.cnblogs.com/attilax/

Package Com.attilax.lang;

Import java.io.UnsupportedEncodingException;

Import Java.net.URLEncoder;

Import java.util.ArrayList;

Import java.util.Collections;

Import java.util.List;

Import COM.ATTILAX.FSM.JAVAEXPFSM;

Import Com.attilax.json.AtiJson;

Import Com.attilax.net.UrlEncode_del;

Import com.google.common.collect.Lists;

public class Astparser {

public Object obj;

Public Object Rzt;

public static void Main (string[] args) throws Unsupportedencodingexception {

System.out

. println (Urlencoder

. Encode ("New (Com.attilax.util.connReduceDync). Set_resfile (Userphone4jobusimp/uc_js.txt). JoinNoutV2 ()",

"UTF8"));

String s= "New (com.attilax.orm.AtiOrmV2). Queryasrzt (\" Select SUM ($) sumx from recharge where accountId in (select ID as UID from account where promoter=888) \ ")";

S= "New (Com.attilax.agent.AgentRechargeService). Getsubmemtotalsrecyclebyagentid (\" promoter: $pid $,fld2:v2\ ")";

S= "New (Com.attilax.user.AgentService). Login (Admin,admin)";

System.out.println (New Astparser (). Getexprsliast (s));

// "Select SUM ($) sumx from recharge where accountId in (select ID as UID from account where promoter=888)"

System.out.println ("..");

System.setproperty ("Prj", "Jobus");

String

Code= "New (Com.attilax.util.connReduceDync). Set_resfile (Userphone4jobusimp/uc_js.txt). JoinNoutV2 ()". Trim ();

AST Astparser = new AST ();

List ast=astparser.getexprsliast (code);

System.out.println (Atijson.tojson (Astparser.parse (AST));

// s= "Login (admin,admin)";

}

Public Object parse;

Public Object Parse (List ast) {

for (Object object:ast) {

String exp= (String) object;

Parsesingle (object);

}

return this.rzt;

}

private void Parsesingle (Object exp) {

Exprs e = (EXPRS) (exp);

E.obj = This.obj;

This.rzt = E.calc ();

This.obj = E.obj;

}

@SuppressWarnings ("All")

Public List Getexprsliast (String code) {

List li = new ArrayList ();

List tokens = new JAVAEXPFSM (code). Gettokens ();

System.out.println (Atijson.tojson (tokens));

list<string> Tokens_slice_li = Lists.newlinkedlist ();

for (int i = 0; i < tokens.size (); i++) {

Last

Dot is Expres splitor. If cur pos of tokens is dot

if (Tokens.get (i). toString (). Trim (). Equals (".")

) {

Exprs e = Getexprsfrmtokenslice (Tokens_slice_li);

Li.add (e);

Tokens_slice_li = Lists.newlinkedlist ();

Continue

}

if (i = = Tokens.size ()-1)

{

Tokens_slice_li.add (String) tokens.get (i));

Exprs e = Getexprsfrmtokenslice (Tokens_slice_li);

Li.add (e);

Break

}

Tokens_slice_li.add (String) tokens.get (i));

}

Collections.addall (Li, a);

return Li;

}

Private Exprs Getexprsfrmtokenslice (list<string> tokens_slice_li) {

Exprs e = new Exprs ();

// if (tokens_slice_li.size () = = 5) {

//

// }

// if (tokens_slice_li.size () = = 4) {

// E.method = (String) tokens_slice_li.get (0);

// String params = tokens_slice_li.get (2);

// //  e.params = params; E.parseparams (Params.tostring ());

// e.params = Lists.newlinkedlist ();

// E.params.add (params);

// //q716 must as a params .

// //' New (Com.attilax.agent.AgentRechargeService). Getsubmemtotalsrecyclebyagentid ("promoter: $pid $,fld2:v2") ';

//

// }

Last log () mode, empty param mode

if (tokens_slice_li.size () = = 3) {

E.method = (String) tokens_slice_li.get (0);

E.params = Lists.newlinkedlist ();

}else

{

E.method = (String) tokens_slice_li.get (0);  

E.params = Parseparams (Tokens_slice_li);

}

return e;

}

@Deprecated

Public List parseparams (String pa_str) {

String[] A=pa_str.split (",");

List li= new ArrayList ();

Collections.addall (Li, a);

return Li;

}

/**

Attilax Year 9 month 2 12:12:01 pm

* @param tokens_slice_li

* @return

*/

Public List parseparams (list<string> tokens_slice_li) {

List li= new ArrayList ();

for (int i=2;i<tokens_slice_li.size () -1;i++)

{

Li.add (Tokens_slice_li.get (i));

}

return Li;

}

}

Atitti.java Exp AST Java expression Syntax ast constructor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.