[antlr-interest] parsing quoted string

Siddharth Karandikar siddharth.karandikar at gmail.com
Wed Nov 26 02:58:38 PST 2008


Ooops  what a mistake ...
Thanks Chris. Now working like a charm!  :)


- Siddharth

On Wed, Nov 26, 2008 at 4:15 PM, Chris Rebert <cvrebert at gmail.com> wrote:
> On Wed, Nov 26, 2008 at 2:34 AM, Siddharth Karandikar
> <siddharth.karandikar at gmail.com> wrote:
>> Hi All!
>>
>> I am a newbie here and trying to test out few things with Antlr-v3.
>> Following is what I have written to parse quoted string and print that
>> parsed string on console.
>> For this I referred to StringLiteral definition in Java.g But somehow,
>> grammar written by me is not working. Am I doing something really
>> stupid?
>>
>> Thanks,
>> Siddharth
>>
>> Grammar -
>>
>> grammar Test;
>>
>> literal : q=quoted
>>  {
>>    System.out.println("q=>"+$q.text);
>>  };
>>
>> quoted : '"' ( EscapeSequence | ~('\\'|'"') )* '"' ;
>
> I believe quoted is supposed to be a lexer rule and thus must start
> with a capital letter (i.e. Quoted), although all-caps is preferred
> (i.e. QUOTED).
> Otherwise, ANTLR thinks it's a parser rule, and it's obviously not
> very sensible as a parser rule, hence the error.
>
> Cheers,
> Chris
> --
> Follow the path of the Iguana...
> http://rebertia.com
>
>>
>> fragment
>> EscapeSequence : '\\' ('\"'|'\''|'\\') ;
>>
>> WS  :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
>>    ;
>>
>>
>> Errors that I get -
>>
>> $ java -classpath .:output/:../../antlr-3.1.jar Run
>> "abcd ABCD"
>> line 1:1 no viable alternative at character 'a'
>> line 1:2 no viable alternative at character 'b'
>> line 1:3 no viable alternative at character 'c'
>> line 1:4 no viable alternative at character 'd'
>> line 1:6 no viable alternative at character 'A'
>> line 1:7 no viable alternative at character 'B'
>> line 1:8 no viable alternative at character 'C'
>> line 1:9 no viable alternative at character 'D'
>> q=>" "
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>>
>


More information about the antlr-interest mailing list