[antlr-interest] Re: Translators Should Use Tree Grammars

Anakreon anakreonmejdi at yahoo.gr
Tue Nov 23 01:51:01 PST 2004


> Anakreon,
> 
> I spent a couple of hours trying to figure out how your stuff works.
The codebase is large. I have extensive docs on how the translator is
implemented but is in Greek. 
> It looks to me like you've got tree_js.g (251 lines) for your
> Jscript treewalker grammar. You've got tree_js_php.act
> containing two things: supporting classes (the first 1481 lines),
> plus the actual code that would normally be embedded
> in the grammar (the remaining 827 lines). And somehow you
> automatically stuff that code into the .g file before
I use annotation, a tool which is available from antlr site.
Inside the grammar a placeholder for the action code looks like this:
<code_here> and in an other file the actual code is inserted like this:
@code_here : //Java code 
The two files are merged before antlr is called.
> using ANTLR on it? And then you've got 9200 lines of
> xml (tests/js_*.xml)
Those are just test cases. The AST generated by the Parser and the TreeParser
are saved in a file when I'm certain that the result is OK.
When I change the grammar, I compare the EAST generated from those 2 phases
with the stored EAST in the files. This process is automated with JUnit and
a custom TestCase class. 
> that appears to specify how to translate specific AST structures.
> (they appear to contain transformation logic, yet their in
> the 'test' directory...are they part of the program, or some
> sort of test case?)
The xml which contain transformation logic are in the objects
directory.
> Also, could you give a small example of some more complex 
> transformation? I didn't see anything in the code you posted
> other than very simple syntactic changes (for example, nothing
> that would have to look at other places in the AST).
The post was about transformation of syntactic structures.
The class definition of JScript was transformed into an equivalent
syntactic structure of PHP.
If by complex transformation you mean method calls 
(because the transformation I posted is really complex) I'll demonstrate
a transformation of an ActiveX call:
Code from tests/sources/response.asp
 <%
Response.Buffer = true
Response.CacheControl = "Public"
cache = Response.CacheControl
Response.ContentType = "text/plain"
cType = Response.ContentType
a = Response.isClientConnected
Response.status = "Some Status"
Response.pics = "pics"
Response.Expires = "123"
Response.ExpiresAbsolute = "12/2/2004"
Response.addHeader "MyHeader", "HeaderValue"
Response.AppendToLog "This is my message"
Response.Clear()
Response.Clear
Response.end
Response.End()
Response.Flush
Response.Flush()
Response.redirect "Some url"
Response.write(html)
Response.write html & "<br>"
Response.Cookies("A") = "Value"
Response.Cookies("A")("B") = "Other value"
%>
Code generated by command:./run.sh tests/sources/response.asp . -s
<?php
ob_start();
session_cache_limiter("Public");
$cache = session_cache_limiter();
header("Content-type: " . "text/plain");
$cType = $_SERVER["CONTENT_TYPE"];
$a = connection_status() == 0;
header("Status: " . "Some Status");
header("pics-label: " . "pics");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + "123") . "GMT");
header("Expires: " . "12/2/2004");
header("MyHeader" . ": " . "HeaderValue");
error_log("This is my message");
ob_clean();
ob_clean();
ob_flush_end();
exit();
ob_flush_end();
exit();
ob_flush();
ob_flush();
header("Location: " . "Some url");
print($html);
print($html . "<br>");
set_cookie("A", "Value");
set_cookie("A" . "[" . "B" . "]", "Other value");
?>

An other complex transformation could be the test case tests/sources/string.asp
which tests the translation of the String built-in object of Jscript.

If you need more info send a mail.
In case the antlr list is not interested on this issue, send email to my address
only.

Anakreon


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list