[antlr-interest] Dot Grammar conversion from antlr v2 to v3 - regd.

ASHOK REDDY asoka250 at gmail.com
Tue Jun 10 07:20:56 PDT 2008


Hello,

As this being my first mail to the list, I like to thank Terrence parr and
all the active members for keeping the list active and informative. As part
of my project requirement, I am trying to convert Graphviz dot grammar (
http://www.antlr.org/grammar/1138116546902/dot/index.html), from antlr v2 to
antlr v3. For this purpose, I downloaded the tar ball (
http://www.antlr.org/wiki/display/ANTLR3/Migrating+from+ANTLR+2+to+ANTLR+3?focusedCommentId=10125322#comment-10125322)
and did as instructed in the Readme file. The conversion for DotParser.g
went well, but I stumbled across some errors in the case of DotLexer.g
grammar file. Can anyone help me in resolving the issue. I got the following
ouput at stdout:-

ashok at ashok-laptop:~/parser/v2v3-0.2/v2v3$ java v3me -combined
./../../DotLexer.g
line 52:13 mismatched character 'r' expecting '''
line 52:19 mismatched character ' ' expecting '''
line 53:13 mismatched character 'i' expecting '''
line 53:21 mismatched character ' ' expecting '''
line 54:13 mismatched character 't' expecting '''
line 54:20 mismatched character ' ' expecting '''
line 55:13 mismatched character 'o' expecting '''
line 55:18 mismatched character ' ' expecting '''
line 56:13 mismatched character 'd' expecting '''
line 56:18 mismatched character ' ' expecting '''
line 57:13 mismatched character '-' expecting '''
line 58:13 mismatched character '>' expecting '''
line 70:27 mismatched character 'r' expecting '''
line 70:33 mismatched character '\n' expecting '''
line 71:29 mismatched character 'i' expecting '''
line 71:37 mismatched character '\n' expecting '''
line 72:28 mismatched character 't' expecting '''
line 72:35 mismatched character '\n' expecting '''
line 73:26 mismatched character 'o' expecting '''
line 73:31 mismatched character '\n' expecting '''
line 74:26 mismatched character 'd' expecting '''
line 74:31 mismatched character '\n' expecting '''
line 86:13 mismatched character '>' expecting '''
line 86:22 mismatched character '>' expecting '''
line 87:13 mismatched character '-' expecting '''
line 87:22 mismatched character '-' expecting '''
line 99:13 mismatched character 'e' expecting '''
line 99:22 mismatched character 'e' expecting '''
line 100:13 mismatched character 'w' expecting '''
line 100:22 mismatched character 'w' expecting '''
line 101:13 mismatched character 'o' expecting '''
line 101:18 mismatched character ' ' expecting '''
line 104:13 mismatched character 'e' expecting '''
line 104:22 mismatched character 'e' expecting '''
line 105:13 mismatched character 'w' expecting '''
line 105:22 mismatched character 'w' expecting '''
line 129:14 mismatched character '\' expecting '''
line 129:18 mismatched character ' ' expecting '''
line 129:25 mismatched character '\' expecting '''
line 130:0 mismatched character ' ' expecting '''
line 150:13 mismatched character '*' expecting '''
line 151:13 mismatched character '/' expecting '''
line 158:9 mismatched character '/' expecting '''
line 165:9 mismatched character '*' expecting '''
line 185:9 mismatched character '/' expecting '''
BR.recoverFromMismatchedToken
line 51:0 mismatched input 'LITERALS' expecting EOF
//;-*- mode: antlr -*-
/*
                        DotParser

    Copyright (C) 2006  Jose San Leandro Armendariz
                        chous at acm-sl.org

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
USA

    Thanks to ACM S.L. for distributing this library under the GPL license.
    Contact info: chous at acm-sl.org
    Postal Address: c/Playa de Lagoa, 1
                    Urb. Valdecabanas
                    Boadilla del monte
                    28660 Madrid
                    Spain

 *****************************************************************************
 *
 * Filename: $RCSfile: DotLexer.g,v $
 *
 * Author: Jose San Leandro Armendariz
 *
 * Description: Clean ANTLR-based lexer according to GraphViz's Dot grammar.
 *
 * See http://www.graphviz.org/doc/info/lang.html
 *
 */



/*options
{
    k=1;
    charVocabulary = '\3'..'\377';
    exportVocab=Dot;
}*/

LITERALS
    :  (  (ph> GRAPH_LITERAL {$setType(GRAPH_LITERAL);}
        | (raph> DIGRAPH_LITERAL {$setType(DIGRAPH_LITERAL);}
        | (ict> STRICT_LITERAL {$setType(STRICT_LITERAL);}
        | (e> NODE_LITERAL {$setType(NODE_LITERAL);}
        | (e> EDGE_LITERAL {$setType(EDGE_LITERAL);}
        | () => EDGEOP_LITERAL {$setType(EDGEOP_LITERAL);}
        | () => EDGEOP_LITERAL {$setType(EDGEOP_LITERAL);}
        | ('{') => O_BRACKET {$setType(O_BRACKET);}
        | ('}') => C_BRACKET {$setType(C_BRACKET);}
        | ('[') => O_SQR_BRACKET {$setType(O_SQR_BRACKET);}
        | (']') => C_SQR_BRACKET {$setType(C_SQR_BRACKET);}
        | (';') => SEMI_COLON {$setType(SEMI_COLON);}
        | ('=') => EQUAL {$setType(EQUAL);}
        | (',') => COMMA {$setType(COMMA);}
        | (':') => COLON {$setType(COLON);}
        | ID {$setType(ID);})
    ;

fragment GRAPH_LITERAL : phragment DIGRAPH_LITERAL : raphragment
STRICT_LITERAL : ictragment NODE_LITERAL : eragment EDGE_LITERAL : efragment
O_BRACKET : '{';
fragment C_BRACKET : '}';
fragment O_SQR_BRACKET : '[';
fragment C_SQR_BRACKET : ']';
fragment SEMI_COLON : ';';
fragment EQUAL : '=';
fragment COMMA : ',';
fragment COLON : ':';

fragment EDGEOP_LITERAL
    :  (  () =>
        | () =>
       )
    ;

fragment ID
    :  (  VALIDSTR
        | NUMBER
        | QUOTEDSTR
        | HTMLSTR
       );

fragment COMPASS_PT
    :  (  () =>
        | () =>
        | (e> NODE_LITERAL
        | 'n'
        | 'e'
        | () =>
        | () =>
        | 's'
        | 'w'
       );

fragment ALPHACHAR
    :  (   'a'..'z'
        |  'A'..'Z'
        |  '_'
       );

fragment VALIDSTR
    :  ALPHACHAR
        (  ALPHACHAR
         |  '0'..'9'
        )*
    ;

fragment NUMBER
    :  ('-')? ('0'..'9')+ ('.' ('0'..'9')+)?
    ;

fragment QUOTEDSTR
    :  '"'
       (  (>       | ~('"')
       )*
       '"'
    ;

fragment HTMLSTR
    :  '<' (~'>')* '>'
    ;

WS
    :
       (   ' '
        |  '\t'
        |  '\r' '\n' { newline(); }
        |  '\n'      { newline(); }
       ) {$setType(Token.SKIP);} //ignore this token
    ;

// Single-line comments
COMMENT
    :  (  () => ML_COMMENT
        | () => SL_COMMENT)
       {$setType(Token.SKIP); newline();}
    ;

// Taken from ANTLR's Java grammar.
// Single-line comments
fragment SL_COMMENT
    :
       (~('\n'|'\r'))* ('\n'|'\r'('\n')?)
       {$setType(Token.SKIP); newline();}
    ;

// multiple-line comments
fragment ML_COMMENT
    :
       (   /*
              '\r' '\n' can be matched in one alternative or by matching
              '\r' in one iteration and '\n' in another.  I am trying to
              handle any flavor of newline that comes in, but the language
              that allows both "\r\n" and "\r" and "\n" to all be valid
              newline is ambiguous.  Consequently, the resulting grammar
              must be ambiguous.  I'm shutting this warning off.
            */
            /*options
            {
                generateAmbigWarnings=false;
            }*/

               {LA(2)!='/'}? '*'
             | '\r' '\n' {newline();}
             | '\r' {newline();}
             | '\n' {newline();}
             | ~('*'|'\n'|'\r')
       )*

       {$setType(Token.SKIP);}
    ;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080610/335e4281/attachment-0001.html 


More information about the antlr-interest mailing list