Skip to main content



      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 13:28
Eclipse UserFriend
Hello,

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{


...

@Override
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'/>
		</Variable>
		<Value>
		   <ClassInstanceCreation start='192' length='8'>
			<ClassName start='196' length='2'>
				<Identifier start='196' length='2' name='AA'/>
			</ClassName>
			<ConstructorParameters>
			</ConstructorParameters>
		   </ClassInstanceCreation>
		</Value>
	</Assignment>
</ExpressionStatement>



<?php


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();
	$aa->m1("hello");
	$aa->f1=5;
}

printName();


?>



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: Wed Jul 09 23:02:23 EDT 2025

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

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

Back to the top