[antlr-interest] questions basic or difficult ?

Tom Liu TomL at avokia.com
Tue Jun 27 15:46:10 PDT 2006


Hi, All

I am testing to use Antlr 2.7.6  to parser sybase stored procedures,
Does anyone have the .g file for stored procedure or sql statement?

Considering the following script as a typical input, 
Test.sql
--------------------------------------
Drop table test 
Go
Drop procedure testsp
Create procedure testsp
as 
   drop table test
   create table test(id int not null, str varchar(20))
go
Create procedure testsp1
as 
begin
   insert into test values(1,'test')
   update test set str='another' 
     where id=(select count(*) from test) and str = 'test'
   select * from test 
end
--------------------------------------
You may notice that there is no last "go" at the end of the file,
And there is nothing that can be used as the flag for the end of a
statement
(actually all the script can be written in one line)

How do I define the rules if I want to generate a xml like following?
Test.sql.xml
--------------------------------------
<root>
<GOBLOCK><STATEMENT>Drop table test</STATEMENT></GOBLOCK>
<GOBLOCK>
   <STATEMENT>Drop procedure testsp</STATEMENT> 
   <STATEMENT>Create procedure testsp as 
   	<STATEMENT>drop table test</STATEMENT>
   	<STATEMENT>create table test(id int not null, str varchar[20])

   	</STATEMENT>   
   </STATEMENT>
</GOBLOCK>
<GOBLOCK>
   <STATEMENT>Create procedure testsp1 as begin
       <STATEMENT>insert into test values(1,'test')</STATEMENT>
       <STATEMENT>update test set str='another' 
              where id=(select count(*) from test) and str = 'test'
       </STATEMENT>
       <STATEMENT>select * from test</STATEMENT>
       end
    </STATEMENT>
</GOBLOCK>
</root>
--------------------------------------

Is this some difficult?

Could anyone give me suggestions or example about this,

Thanks a lot,

Tom



More information about the antlr-interest mailing list