[antlr-interest] [] in commentary

kdaling71 kdaling at uos.de
Thu Aug 5 02:34:03 PDT 2004


Hi all,

I am using the following lines to get comments in my grammar:

SL_COMMENT :
    "//"
    (~'\n')* '\n'
    { _ttype = Token.SKIP; newline(); }
    ;

When I now put a comment with squared brackets in my file like

// This is [a] comment

I get an error message:

expecting '\n' found [

Comments with other symbols like () oder {} are allowed.
Does anybody has an idea what the problem is?

Thanks


Klaus Dalinghaus

---------------------------------------------------------------
Institute of Cognitive Science, University of Osnabrück
Kolpingstraße 7, 49069 Osnabrück
Tel.: +49-(0)-541-969-4797   Fax.: +49-(0)-541-969-6229
http://www.cogsci.uni-osnabrueck.de/~kdaling







Here is my complete grammar

class FPParseParser extends Parser;

// options for the parser
options {
    buildAST = true;    // uses CommonAST by default
    defaultErrorHandler = false;
}


fuzzyProgram
    :    ( prefixStatement ) ? ( operatorDefinition ) * ( clauseBlock ) +
    ;

prefixStatement
    :    PREFIX^ IDENTIFIER SEMI!
    ;

operatorDefinition
    :    OPERATOR^ IDENTIFIER EQUALS! IDENTIFIER LEFTBRACKET! (
operatorArgumentList ) ? RIGHTBRACKET! SEMI!
    ;

operatorArgumentList
    :    IDENTIFIER ( COMMA^ IDENTIFIER ) *
    ;

clauseBlock
    :    clause SEMI^
    ;

clause
    :    conclusion LEFTARROW^ premiseOp
    ;

premiseOp
    :    simplePremise
    |    multiPremise
    |   
    ;

simplePremise
    :    premiseList PIPE^ operator
    ;

multiPremise
    :     LEFTCURLY^ premise RIGHTCURLY! PIPE! operator
    ;

premiseList
    :    premise ( COMMA^ premise )*
    ;

conclusion
    :    IDENTIFIER
    ;

premise
    :    IDENTIFIER
    ;

operator
    :    IDENTIFIER
    ;

class FPParseLexer extends Lexer;


options{
    defaultErrorHandler = false;
}

tokens{
    PREFIX = "prefix";
    OPERATOR = "operator";
}

WS    :    (' '
    |    '\t'
    |    '\n'
    |    '\r')
        { _ttype = Token.SKIP; }
    ;

SL_COMMENT :
    "//"
    (~'\n')* '\n'
    { _ttype = Token.SKIP; newline(); }
    ;


EQUALS:            '=';

LEFTARROW:        "<-";

LEFTCURLY:        '{';

RIGHTCURLY:        '}';

LEFTBRACKET:    '(';

RIGHTBRACKET:    ')';

SEMI:            ';';

COMMA:            ',';

PIPE:            "|";

IDENTIFIER
options {
    testLiterals = true;
    paraphrase = "an identifier";
}
    :    ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'.'|'-')+
    ;







 
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