[antlr-interest] Exception tests eat performance?
Terence Parr
parrt at cs.usfca.edu
Wed Jan 7 11:00:35 PST 2004
On Wednesday, January 7, 2004, at 10:29 AM, Karl Meissner wrote:
> Instead of every code block being a try{}catch
Howdy,
Only for syn preds, which should be avoided, though.
> you could do most things with break and returning a result stucture.
Makes recursive and nested structures pretty tough. And most of the
time syn preds call other rules, making "break" unusable. :(
> Null result is success.
>
> At the end of every block check result is null to coninue.
>
> struct ResultInfo ; //ErrorInfo is a struct that can hold the
> //info we are putting into the exception
> currently
>
>
> Have match and rules return errorinfo structs on error, null on
> success.
>
> ErrorInfo Match( Symbol t ) {
> if ( LA( 1 ) != t )
> return new ResultInfo( t, linenumber, etc);
>
> consume();
> return null; //success
> }
Pretty slow creating a new result object for each match isn't it? An
interesting idea, though :)
> ResultInfo Rule1() {
>
> ResultInfo result=null; //null until sucess
> //stuff
>
> for(;;){ // inside some block
>
>
> for(;;) {
> if( (result = Rule2()) != null } break;
>
> if( (result = Match( SYM123 ) ) != null } break;
> }
> if( result != null ) break; //put this after every single code
> block
> // will break to the top level
> // a poor man's goto
> // still cheaper then a catch even
> if nested deep
> }
> if( result != null ) break; //etc.
>
> //stuff
>
> if( result != null ) {
> //handle result
>
> }
> return result;
> }
Breaks are gotos and don't necessary lend themselves to more readable
code ;)
Good discussion :)
Terence
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Co-founder, http://www.jguru.com
Co-founder, http://www.knowspam.net enjoy email again!
Co-founder, http://www.peerscope.com link sharing, pure-n-simple
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list