regex - ANTLR3 String Literals and Disallowing Nested Comments -


i've been tasked writing antlr3 grammar fictional language. else seems fine, i've couple of minor issues with:

1) comments between '/*' , '*/', , may not nested. know how implement comments ('/*' .* '*/'), how go disallowing nesting?

2) string literals defined sequence of characters (except double quotes , new lines) in between pair of double quotes. can used in output statement. attempted define thus:

output : output (stringlit | ident) ; stringlit : '"' ~('\r' | '\n' | '"')* '"' ; 

for reason, however, parser accepts

output "hello, world!" 

and tokenises "hello, \nworld. exclamation mark or closing " went have no idea. whitespace maybe?

whitespace : ( '\t' | ' ' | '\n' | '\r' | '\f' )+ { $channel = hidden; } ; 

any advice appreciated - time! :)

  1. the form wrote disallows nested comments. token stop @ first instance of */, if multiple /* sequences appeared in comment. allow nested comments have write lexer rule treat nesting.

  2. the problem here stringlit not allow string split across multiple lines. without seeing rest of lexer rules, cannot tell how tokenized, it's clear stringlit rule gave sample input not valid string.

note: input given in original question not clear, reformatted in attempt show exact input using. can verify edit represents input?


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -