1

I have the following ANTLR grammar.

grammar DDGrammar;

ddstmt: dd2 EOF;

dd2: splddstart inlinerec;
splddstart: '//' NAME DDWORD '*' NL;
inlinerec: NON_JCL_CARD* END_OF_FILE ;

DDWORD:'DD';
//DUMMYWORD: 'DUMMY';

NAME: [A-Z@#$]+;

NON_JCL_CARD  : ~'/'  {getCharPositionInLine() == 1}? .*? ( NL | EOF ) ;
END_OF_FILE   : '/'  {getCharPositionInLine() == 1}? '*' ;

NL  : '\r' '\n' ;
WS  : [ \t]+ -> skip ;

For the input :

//SYSIN    DD  *     
SORT FIELDS=COPY
INCLUDE COND
any other program input @ $ ! & %
/*

I get the following error.

DDGrammar::ddstmt:1:2: mismatched input 'SYSIN DD * \r\n' expecting NAME Looks like SYSIN is not recognised as a NAME token. Actually a similar grammar did work sometime back. See mismatched input error. But now the same doesnt seem to work for me.

ssdimmanuel
  • 448
  • 10
  • 29

2 Answers2

1

My guess is that you didn't regenerate the parser/lexer classes since the following code works just fine:

String source = "//SYSIN    DD  *     \r\n" +
        "SORT FIELDS=COPY\r\n" +
        "INCLUDE COND\r\n" +
        "any other program input @ $ ! & %\r\n" +
        "/*";

DDGrammarLexer lexer = new DDGrammarLexer(CharStreams.fromString(source));
DDGrammarParser parser = new DDGrammarParser(new CommonTokenStream(lexer));

parser.ddstmt();
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
  • I have not reached to the part where I use it in my Java application . I am using the ANTLR 4 IDE eclipse plugin to composing my grammar. The tool shows this error. May be bug with the plugin ? am I missing something ?AntlrWorks too doesnt work with Java 8. So I am left with limited options – ssdimmanuel Jun 09 '18 at 14:29
  • 1
    Perhaps the IDE does not handle the predicate properly? Anyway, again, the grammar parses the input just fine. HTH. – Bart Kiers Jun 09 '18 at 14:31
  • Thanks Bart. I will see if I can open a bug request. Do you know of any other plugin which work ? – ssdimmanuel Jun 09 '18 at 14:42
  • No problem. No, not that I know. Many ANTLR plugins/editors have problems properly handling predicates. – Bart Kiers Jun 09 '18 at 15:00
0

JCL is painful to parse because of it's context sensitivity and the significance of whitspace.

Handling instream data is particularly thorny - there are a few optionals in there that can throw things out if you are not aware of them.

For example, there are some optional keywords that may appear after DD * (or DD DATA); these may or may not appear on the same physical line as the DD statement itself. Another is that the delimiter can be other than "/*" if the optional "DLM=" operator is used in the instream DD statement. I needed a pretty nasty Java function to handle the variability, which is never recommended.

v0rl0n
  • 145
  • 7