[antlr-interest] Free Text mixed with rules

Loring Craymer lgcraymer at yahoo.com
Tue Jun 17 17:49:52 PDT 2008


If you want to recover text in its original format, you might as well use the start and stop markers on the first and last tokens of the "text" sequence from the input stream (ANTLR 3 keeps the text input stream in memory).  At the same time, you are probably best off in going ahead and including an expression grammar in your parser to handle what you are calling "free text"--otherwise, you will have to deal with nested conditionals in your lexer, and that gets very messy.  You can repackage the "text" segments in the output AST as a replacement for the nodes matched by the expression grammar.

--Loring


----- Original Message ----
From: victor panizza <victor.panizza at gmail.com>
To: antlr-interest at antlr.org
Sent: Tuesday, June 17, 2008 5:17:29 PM
Subject: [antlr-interest] Free Text mixed with rules


Hello All, 
 
I have the follow issue:
 
I'm trying to develop a Parse Grammar and a Tree Parse for read PL/SQL scripts and translate it to DB2 SQL PL. Now, there're many diferences beetwen thems and this diferences are defined by the rules and some literals, but there're many things in common like the IF LOGICAL_OPERATION THEN END IF;
 
My Idea is create a Node in the tree (using a token like FREE_TEXT) where I can put each segment of free text like the above and later walk the tree and get this free text in the same order on they were recongnized. For example: 
 
IF (LAST_DAY(PDATE)!=PDATE) THEN
  PDATEAUX := ADD_MONTHS(PDATE, PMONTHS);
  RETURN ADD_MONTHS(PDATE, PMONTHS);
END IF;
 
In text tree representation:
 
(ROOT
          (FREE_TEXT "IF (LAST_DAY(PDATE)!=PDATE) THEN")
          (ASSING "PDATEAUX := PDATE;")
          (FREE_TEXT "RETURN ADD_MONTHS(PDATE, PMONTHS);")
          (FREE_TEXT "END IF;);")
)
 
 
Any idea, thanks in advance!!!!
 
-- 
Saludos,
Victor Panizza 


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080617/3293a387/attachment.html 


More information about the antlr-interest mailing list