Atitti. java exp ast java expression syntax ast constructor, atitti. javaast

Source: Internet
Author: User
Tags addall tojson

Atitti. java exp ast java expression syntax ast constructor, atitti. javaast

Atitti. java exp ast java expression syntax ast Constructor

 

/Atiplat_cms/src/com/attilax/lang/AstParser. java

 

Principle

Tokens_slice_li

Analyze splitor, mainly dot and end

 

 

 

 

Author ::★(Attilax)> nickname: old wow's paw (full name: Attilax Akbar Al Rapanui Attila Akba Arla Panui) Chinese name: AI long, EMAIL: 1466519819@qq.com

Reprinted 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. conn1_cedync). set_resfile (userPhone4jobusImp/uc_js.txt). joinNoutV2 ()",

"Utf8 "));

String s = "new (com. attilax. orm. atiOrmV2 ). queryAsRzt (\ "select sum (RMB) 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 (RMB) 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. conn1_cedync). 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. newlists List ();

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. newcategory list ();

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, );

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. newqueue list ();

// 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. newqueue list ();

} 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, );

Return li;

}

/**

Attilax September 2, 2016 12:12:01

* @ 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;

}

 

}

 

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.