2 years ago

#50213

test-img

yaccoff

Antrl4 parsing - tackling difficult syntax

I am parsing a language which has some difficult syntax that I need some help or suggestions to tackle it.

Heres an a typical line =>

IF CLCI((ZNTEM+CHRCNT),1,1H())) EQ 0

The difficult bit is nH(....any character within the character set.....) where n is 1 in this example and the single char in question is a ')' . My lexer has:

fragment Lp: '(';
fragment Rp: ')';

LP: Lp;
RP: Rp; etc....

My current non-working solution is to switch modes in the lexer because then I can then define all the special chars to consume

// Default mode rules
STRING_SUB: INT 'H' LP -> pushMode(ISLAND) ; // switch to ISLAND mode

and then to switch back

// Special mode of INT H ( ID )
// ID is the string substitute which can includes, spaces, backslash, etc, special chars

mode ISLAND;

ISLAND_CLOSE : RP -> popMode ; // back to nomal mode

ID : SpecialChars+; // match/send ID in tag to parser

fragment SpecialChars: '\u0020'..'\u0027' | '\u002A'..'\u0060' | '\u0061'..'\u007E' | '¦';

But obviously the pop mode trigger is the ')' which fails in the particular example case, because the payload is a RP. Any suggestions?

parsing

antlr

antlr4

0 Answers

Your Answer

Accepted video resources