[antlr-interest] PLSQLGrammar.g

Michiel Vermandel MVerma at ferranti.be
Tue Mar 22 00:17:59 PST 2005


Hi Ed,

About the list of warnings in your mail: I've got these too...
I ignored them for the moment and passed on to the next stage where I compiled the java files. After removing the missing class the compilation went ok.
That's were I got... Now I'm a bit short of time (this week) and knowledge to proceed. I do not quit now how to proceed and parse a PlSql package file, but I'll find out, I guess.

My purpose: I'm working in a company with about 60 people working on the same project. We are generating lots of PlSql packages and so we are facing some problems such as checking code quality and coding standards but even more important: we need to keep the technical designs of these packages in sync so other programmers can use this documentation.

Therefore we want to 
1) create a tool which creates a basic documentation out of PlSql packages (We call it PlSqlDoc, similar to JavaDoc) 
2) be able to add structured comments to our code. Then we can use these comments to generate a flow of the packages.
What I mean is: you can find some software to generate a flowchart out of PLSQL code but that's mainly not useful since they just parse the syntax and generate hugh flows without much added value. Sometimes you just get your code duplicated in boxes and arrows. We want to be able to identify important blocks and for these add special comment.
For example: if you have some code with two loops and one of them is very important for the understanding of the functionality then we want to be able to add some comment tag:

FOR x IN (SELECT * FROM Employees)
LOOP /*@DOC: Determining raise for every employee*/

END LOOP;

The other, less important loop does not get such /*@DOC */ tag and thus won't appear in the generated flow...

For the example above we want to use AntLr to identify the structure (the LOOP) and find the comment assigned to this statement. Then we want to generate a flow with this comment added to the loop symbol.

Well, that's the idea...

In this way the programmer can distinguish important logical steps from less important ones and control the comment that will appear along side in the documentation.

Any ideas are off course welcome.

Regards,

Michiel

-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Ed Delaney
Sent: maandag 21 maart 2005 20:44
To: antlr-interest at antlr.org
Subject: [antlr-interest] PLSQLGrammar.g


Hey Michiel, 
Can you tell me how you generated it? I have not figured out Eclipse and the Antlr plug-in, so I'm just trying from dos. 
java antlr.Tool plsqlgrammar.g 

It generates PLSqlLexer.java and PLSqlParser.java, but in the process generates a huge amount of output that looks like the stuff below. 

So you have any idea what it's problem is? 

Can you tell me a little about what you are interested in doing? 

My interest is first just learning about antlr and parsers and lexers. Specifically, I want to be able to create a tool that does this: 

1) recognizes pl/sql, sqlplus, and sql code inside a file. All our source is stored as sqlplus build scripts that may contain all of these in one file, including sqlplus substitution variables. I'd like my tool to be aware of the substitution variables so it doesn't choke on them or force me to always extract the code from the database first. 

2) for plsql, a) a code formatter, b) a syntax checker c) a style checker (with our custom style rules) 

3) finally, once I can get a complete parse tree, I want to create a language that can edit and query the parse tree in a syntax sensitive way and generate new plsql code. That is, I want to be able to answer questions such as "list all the procedure names in the package that contain a call to function X with  the first paramter = 'ABC'" 
or 
Select every procedure or function definition that does not contain a call to function 'B'. 
or 
Read the package and for every procedure called 'A', insert text at a specific point in the code. 

thanks, 
ed 

-------------------------------------------------------------- 
... 
PLSQLGrammar.g:1196:25:     k==1:OPEN_PAREN 
PLSQLGrammar.g:1196:25:     k==2:NUMBER 
PLSQLGrammar.g:1196:25:     k==3:CLOSE_PAREN 
PLSQLGrammar.g:1196:25:     k==4:NULL_TREE_LOOKAHEAD,"or","replace","is","as",SE 
MI,"not",ASSIGNMENT_EQ,"default",OPEN_PAREN,COMMA,CLOSE_PAREN,"then","in",PLUS,M 
INUS,"and","like","between",DOUBLEDOT,ASTERISK,DIVIDE,QUOTED_STRING,"abs","ceil" 
,"floor","power","round","sign","sqrt","trunc","chr","initcap","lower","lpad","l 
trim","rpad","rtrim","soundex","substr","translate","upper","ascii","instr","len 
gth","concat","count","chartorowid","convert","hextoraw","rawtohex","rowidtochar 
","to_char","to_date","to_number","decode","dump","greatest","least","nvl","user 
env","vsize","user","sysdate",EQ,LT,GT,NOT_EQ,LE,GE,"intersect",IDENTIFIER 
PLSQLGrammar.g:1684:11: warning:nondeterminism between alts 1 and 2 of block upo 
n 
PLSQLGrammar.g:1684:11:     k==1:"replace",QUOTED_STRING,"abs","ceil","floor","p 
ower","round","sign","sqrt","trunc","chr","initcap","lower","lpad","ltrim","rpad 
","rtrim","soundex","substr","translate","upper","ascii","instr","length","conca 
t","count","chartorowid","convert","hextoraw","rawtohex","rowidtochar","to_char" 
,"to_date","to_number","decode","dump","greatest","least","nvl","userenv","vsize 
","user","sysdate","intersect",IDENTIFIER 
PLSQLGrammar.g:1684:11:     k==2:DOT 
PLSQLGrammar.g:1684:11:     k==3:"replace",QUOTED_STRING,"abs","ceil","floor","p 
ower","round","sign","sqrt","trunc","chr","initcap","lower","lpad","ltrim","rpad 
","rtrim","soundex","substr","translate","upper","ascii","instr","length","conca 
t","count","chartorowid","convert","hextoraw","rawtohex","rowidtochar","to_char" 
,"to_date","to_number","decode","dump","greatest","least","nvl","userenv","vsize 
","user","sysdate","intersect",IDENTIFIER 
PLSQLGrammar.g:1684:11:     k==4:DOT 
PLSQLGrammar.g:1634: warning:nondeterminism between alts 1 and 2 of block upon 
... 

---------------------------------------------------
Ed Delaney
SunGard SCT
Advisory Software Engineer
Phone Number (Office): 765-939-0533
Time Zone: US Indiana
edelaney at sungardsct.com
www.sungardsct.com

Leadership - Choices - Excellence


More information about the antlr-interest mailing list