An experience with antlr, java and python

I just wanted to share a little experience with generating an AS3 parser using antlr and python. http://buyafranchiseinfo.com/what-is-essay-writing/ what is essay writing I was trying first to create the parser using GNU Flex and Bison in C, probably the best way for a very performancing parser. http://thebirthhaven.org/research-paper-help-writing/ research paper help writing Yeah, that’s right.. but looking at the antlr syntax I realized that’s easier and easier. http://www.osteriaripasso.it/real-phd-thesis/ real phd thesis Moreover I start using this very useful eclipse plugin for antlr debugging which made my life easier!

essay writing servce

masters thesis dealing The grammar file I created is a compromise between the asdt grammar file and the ECMA-262 grammar specification.

http://www.docomomoiberico.com/?custom-writing-service-info custom writing service info

http://www.ashoksom.com/pay-college-essay/ pay college essay Once finished working on my eclipse project I’ve managed to parse succesfully all the adobe corelibs files using this java test file:

http://retard-de-regles.com/write-an-essay-about-me/ write an essay about me
1 literature review on malaria 2 go to link 3 go 4 don\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'t buy generic cialis 5 http://gplworld.com/?p=help-for-research-paper 6 Essays On The Movie The Help 7 see url 8 http://zoomia.pl/?college-application-essay-service-4th-edition-by-michael-mason 9 go 10 http://www.grantsenterprises.com/pay-to-write-essay-in-8-hours/ pay to write essay in 8 hours 11 source site 12 source url 13 http://salon-cvetov.kz/college-application-writers/ college application writers 14 http://kemon.vn/?p=cheap-essays-for-sale 15 http://kalpatatva.com/?p=resume-for-phd-in-chemistry 16 http://www.telmohenriquesstudio.com/help-writing-outline-research-paper/ help writing outline research paper 17 http://nextmedica.pl/buy-personal-statements/ Buy Personal Statements 18 casio paper writer buy 19 academic writing assistance agencies 20 http://www.alconi.ro/?write-my-essay-for-me-cheap write my essay for me cheap 21 Mba Essays 22 23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package org.sepy.core.parsers.as3;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import antlr.CommonAST;
import antlr.RecognitionException;
import antlr.TokenStreamException;
public class Application {
public static void main(String argv[])
{
if(argv.length > 0)
{
File file = new File(argv[0]);
if(file.exists())
{
FileInputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AS3Lexer L = new AS3Lexer(is);
AS3Parser P = new AS3Parser(L);
try {
P.compilationUnit();
} catch (RecognitionException e) {
// TODO Auto-generated catch block
System.out.println(" line=" + e.line + ", column="+ e.column);
System.out.println(e.getMessage());
e.printStackTrace(System.err);
} catch (TokenStreamException e) {
// TODO Auto-generated catch block
System.out.println(" line=" + L.getLine() + ", column="+ L.getColumn());
System.out.println(L.getGuessInfo());
System.out.println(e.getMessage());
e.printStackTrace(System.err);
}
CommonAST.setVerboseStringConversion(false, P.getTokenNames());
CommonAST ast = (CommonAST) P.getAST();
System.out.println("Tree:");
System.out.println(ast.toStringTree());
}
}
}
}

http://churchofthelordjesus.com/help-with-personal-statement-for-medical-school/ help with personal statement for medical school Ok, done that I decided to export the grammar file for python (thanks to antrl python export feature).
Everything works fine also for python, but I realized that the python script were so much slower than the java one!

http://www.iskipper.fr/?doctoral-thesis-review-report doctoral thesis review report
1
2
3
4
5
6
7
8
9
10
11
12
import sys
import antlr
import AS3Parser
import AS3Lexer
L = AS3Lexer.Lexer(filename);
P = AS3Parser.Parser(L);
P.setFilename(filename)
try:
   P.compilationUnit();
   ast = P.getAST();
except:
   pass

http://n5xmotorsport.com/?essays-on-nursing essays on nursing On a 75Kb actionscript file the python script took about 7 seconds to run, while the java application only 2 seconds. I know python interpreter caould be slower than many other languages, but I never thought so much slower.
So I run the python hotshot profiler to see which could be the bottleneck in the python script and I found most of the problems were due to unuseless antlr (the python module) method’s calls.
After making corrections to the antlr.py file the same script took exactly half of the time. Now 3 seconds. Wow 🙂
But not fast enough.
So I enabled for the antlr python script psyco module and this time the same script took buy cheapest paper only 1.6 seconds.
Now the python script is fast enough, even if I’m sure I can make more optimizations in the antlr module…

write my literature review service