Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » how to get the actual expression from AST
how to get the actual expression from AST [message #1061742] Mon, 03 June 2013 17:28
Laleh m is currently offline Laleh mFriend
Messages: 9
Registered: May 2013
Junior Member

I am using org.eclipse.php.internal.core to parse PHP files. I need to get the expression statements as they are in the source code, but the node.getExpression() returns
an Expression and with a toString() it return an xml-like string. please see the code:

public class MyVisitor implement Visitor{


public boolean visit(ExpressionStatement node) {
	// TODO Auto-generated method stub
	System.out.println("ExpressionStatement: "+node.getExpression().toString);
	return true;


So for the following php file, the output for line "$aa= new AA();" here:

ExpressionStatement: <ExpressionStatement start='187' length='14'>
	<Assignment start='187' length='13' operator='='>
		<Variable start='187' length='3' isDollared='true'>
			<Identifier start='188' length='2' name='aa'/>
		   <ClassInstanceCreation start='192' length='8'>
			<ClassName start='196' length='2'>
				<Identifier start='196' length='2' name='AA'/>


include 'varInclude.php';

print ("name: ".$name."\t\t\t");

function printName(){
	include_once  'varInclude.php';
	include 'varInclude2.php';
	print ("name: ".$name."\t\t\t");
	$aa= new AA();



So do i need to write another parser to parse this xml like output to get to the actual statement "$aa= new AA();" ? If yes, then how a bout the parenthesis and quotations???
Is there other way to get this statement as is ,from AST?
Previous Topic:Folding IF Statements
Next Topic:How to "run" a PHP file
Goto Forum:

Current Time: Thu Feb 02 16:02:23 GMT 2023

Powered by FUDForum. Page generated in 0.37079 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top