[antlr-interest] About removing the "; " In the last sentence of a block

roberto rag700504 at hotmail.com
Wed Dec 7 10:19:37 PST 2011


Hello Everyone

Itried to create asimplelanguagewhere I want todeletethe last';'which 
appearsin a block.Besides having compound blocks,that do not need';'at 
the end ofthe sentence.

This exampleis what I have

*{

a=34;;;;

for(34)

a=59;

}

a=34;

I would liketoremove the';'which goesbehind the59.Iwondered 
ifthereanyway ofsaywhen you findaTOKEN, do not consume thisbutcontinue

expression_statement

: ';'

| expression (';' | *'}'*)

;

For exampleI would like thatwhen you find the'}'generatessentence but 
notbecause it willconsume thetokenusedby the commandblock.

grammar lteA;

program

:statement_list EOF

;

statement_list

: statement+

;

statement

: compound_statement

| expression_statement

| block

;

compound_statement

: sen_for

;

expression_statement

: ';'

| expression (';' |'}')

;

expression

: ID '=' (INT | STRING | FLOAT)

;

sen_for

: 'for' '(' INT ')'

;

block

: '*' '{' statement_list '}'

;

ID:('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*

;

INT :'0'..'9'+

;

FLOAT

:('0'..'9')+ '.' ('0'..'9')* EXPONENT?

|'.' ('0'..'9')+ EXPONENT?

|('0'..'9')+ EXPONENT

;

COMMENT

:'//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}

|'/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}

;

WS:( ' '

| '\t'

| '\r'

| '\n'

) {$channel=HIDDEN;}

;

STRING

:'"' ( ESC_SEQ | ~('\\'|'"') )* '"'

;

CHAR:'\'' ( ESC_SEQ | ~('\''|'\\') ) '\''

;

fragment

EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;

fragment

HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;

fragment

ESC_SEQ

:'\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')

|UNICODE_ESC

|OCTAL_ESC

;

fragment

OCTAL_ESC

:'\\' ('0'..'3') ('0'..'7') ('0'..'7')

|'\\' ('0'..'7') ('0'..'7')

|'\\' ('0'..'7')

;

fragment

UNICODE_ESC

:'\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT

;

  best
regard Roberto



More information about the antlr-interest mailing list