[antlr-interest] v4 "Honey Badger" teaser

Terence Parr parrt at cs.usfca.edu
Thu Dec 29 15:24:40 PST 2011


Hi, For those of you secretly playing with v4 using the repository, don't forget that you can use left recursive expression rules now. These are not only faster at runtime, they are easier to specify. ANTLR unravels it to nonrecursive rules they use semantic predicates to compare operator precedence. Here's a sample expression rule for the R language. Believe it or not, that crap works in a top-down parser generator. Oh, and there is no such thing is parser backtracking a more. The new adaptive LL(*) simply makes all the right choices without backtracking in the prediction or in the parser.

v4 code name: Honey Badger, after The Crazy Nastyass Honey Badger:

http://www.youtube.com/watch?v=4r7wHMg5Yjg

It's hilarious if you haven't seen it. "ANTLR v4 doesn't care. It's bad ass." ;)

Ter
------------
expr    :       '{' exprlist '}'
        |       '(' expr ')'
        |       expr '[[' sublist ']' ']'
        |       expr '[' sublist ']'
        |       expr ('::'|':::') expr
        |       expr ('$'|'@') expr
        |       expr '^'<assoc=right> expr
        |       ('-'|'+') expr
        |       expr ':' expr
        |       expr USER_OP expr
        |       expr ('*'|'/') expr
        |       expr ('+'|'-') expr
        |       expr ('>'|'>='|'<'|'<='|'=='|'!=') expr
        |       '!' expr
        |       expr ('&'|'&&') expr
        |       expr ('|'|'||') expr
        |       '~' expr
        |       expr '~' expr
        |       expr ('->'|'->>'|':=') expr
        |       expr ('<-'<assoc=right>|'<<-'<assoc=right>) expr

        |       'function' '(' formlist ')' expr
        |       expr '(' sublist ')'

        |       'if' '(' expr ')' expr
        |       'if' '(' expr ')' expr 'else' expr
        |       'for' '(' ID 'in' expr ')' expr
        |       'while' '(' expr ')' expr
        |       'repeat' expr

        |       '?' expr

        |       'next'
        |       'break'

        |       ID
        |       STRING
        |       HEX
        |       INT
        |       FLOAT
        |       COMPLEX
        |       'NULL'
        |       'NA'
        |       'Inf'
        |       'NaN'
        |       'TRUE'
        |       'FALSE'
        ;



More information about the antlr-interest mailing list