[antlr-interest] Request:External action definitions

Matthew Ford Matthew.Ford at forward.com.au
Tue Nov 26 14:21:04 PST 2002


Hi Monty,
Were you thinking of my posting on CodeSections.
It does not quite do what is being discussed here.

Using CodeSections
> RULE:
> 'a' .. 'z' { %id; }
> ;
>
would be coded as

<<*>>=
RULE:
'a' .. 'z' {
<<id1>>=
 // code for rule here
<<id2>>=
// code for different action here
<<*>>=
 }
;


All the actions are in the one file and CodeSections just outputs the
sections you want.
Having used this for a little while now the two problems I have found are
i) line numbers don't match the error messages
ii) large action blocks make the code hard to read when there are
alteratives

The solution to  ii) is to use methods instead of large lumps of code

I don't have a solution for i) yet.  Need some way of carrying the original
line numbers to the output file and then
having Antlr resync it error message line counter.

For example if CodeSections was modified to produce output like

//#lineNumber:1
RULE:
'a' .. 'z' {
//#lineNumber:4
// code for rule here
//#lineNumber:8
 }
;

and Antlr recognised //#lineNumber: as a directive to resync it err line
counter then all is well

matthew
----- Original Message -----
From: <mzukowski at yci.com>
To: <antlr-interest at yahoogroups.com>
Sent: Wednesday, November 27, 2002 3:10 AM
Subject: RE: [antlr-interest] Request:External action definitions


> Someone has recently done just this, but I forget who.  I'm sure they will
> pipe up.  Look at the files section on the yahoo list site, I think it is
> there.
>
> Also noweb can be used for this type of thing too.  Searching for noweb in
> the list archives may uncover the one I was thinking of.
>
> Monty
>
> -----Original Message-----
> From: Anakreon Mejdi [mailto:amejdi at ertonline.gr]
> Sent: Tuesday, November 26, 2002 3:41 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Request:External action definitions
>
>
> I have an idea which might make antlr better.
> Instead of defining the actions in the same file with the grammar
> they could be defined in other file(s).
>
> A way this could be achived(not necessarily the best) would be:
>
> RULE:
> 'a' .. 'z' { %id; }
> ;
>
>
> rule
> :
> RULE { %some_id; }
> ;
>
>
> tree_rule
> :
> #(r:RULE { %tree_id; System.out.println("RULE matched");  }
> ;
>
>
> In this case antlr.Tool will be fed with the grammar file and the
> file(s)  where actions are defined.
>
> The actions identified with a label (like %id) will be searched among
> the  action  files and the label should be replaced by the content of
> the action.
>
> Example:
> id = {
> System.out.println("Externaly defined action");
> }
>
> tree_id = {
> System.out.println(r.getText());
> }
>
> This could be achieved with regular expressions but would be a primitive
> implementation.
>
> I'd like to know what you think about it.
> Anakreon
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>


 

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



More information about the antlr-interest mailing list