Mismatched input error

48 views
Skip to first unread message

Immanuel Stephen

unread,
Jan 13, 2017, 9:00:52 AM1/13/17
to antlr-di...@googlegroups.com

I have a grammar which looks like this consisting of comment and control statements of a particular language:

Grammar:

grammar DD;



ddlist
: (ddstmt| jclcomment)+;

ddstmt
: dd1 | dd2 | dd3 | dd4 ;

dd1
: JCLBEGIN ddname DDWORD 'DUMMY';
dd2
: JCLBEGIN ddname DDWORD 'DYNAM';
dd3
: JCLBEGIN ddname DDWORD NAME'=' (''|NAME);
dd4
: JCLBEGIN ddname DDWORD '' inlinerec INLINESTMTEND?;

inlinerec
: (INLINEDATA )+ ;
fragment INLINEDATA
: (~[\r\n])*;

ddname
: NAME;

jclcomment
: JCLCOMMENT+;
JCLCOMMENT
: COMMENTBEGIN ~[\r\n]*;

DDWORD
: 'DD';

JCLBEGIN
: '//' ;
COMMENTBEGIN
: '//*' ;
INLINESTMTEND
: '/*' ;

NAME
: [A-Z#] (ALPHA | NUMBER | SPECIALCHARS)*;

NUMBER
: [0-9];
ALPHA
: [A-Z];
SPECIALCHARS
: '#' | '@' | '$';

WS
: [ \r\n] -> channel(HIDDEN);



My input is this:

//SYSIN DD *
SORT FIELDS
=COPY
INCLUDE COND
/*
//SYSPRINT DD SYSOUT=*
//* Comment line
#1
//* Comment line
#2
//SYSOUT DD SYSOUT=*
//CEEDUMP DD SYSOUT=*
//* Comment line
#3
//SYSUDUMP DD SYSOUT=A


When I use AntlrWorks to run this grammar with the input, I get the following error:

line 2:0 mismatched input 'SORT' expecting INLINEDATA
How can this error be resolved ?

Jim Idle

unread,
Jan 13, 2017, 3:52:58 PM1/13/17
to antlr-discussion
Your grammar statements should really be left factored as they all start with the same tokens but that's not  the  issue. 

You're JCLCOMMENT and COMMENTBEGIN tokens are ambiguous, you only need one of these. Most of your lexer definitions should be fragments as they are not stand alone tokens NUMBER, ALPHA, SPECIALCHARS . Your INLINEDATA token can be empty, * should be +.You are hiding ' ' but the surviving it in dd3 and dd4. Your comments actually start with //" but you don't cater for that. SORT and INCLUDE are not catered for... I could go b on. 

Basically this grammar is more incorrect than it is correct. I think you need to start again after reading some tutorials or better yet buy a copy of the book.  Grammar programming is not rocket science but you do need to know what you are doing before trying to type one out. 

You will get there if you read up on it first


_____________________________
From: Immanuel Stephen <ssdim...@gmail.com>
Sent: Friday, January 13, 2017 04:00
Subject: [antlr-discussion] Mismatched input error
To: antlr-discussion <antlr-di...@googlegroups.com>


I have a grammar which looks like this consisting of comment and control statements of a particular language:

Grammar:

grammar DD;



ddlist
: (ddstmt| jclcomment)+;

ddstmt
: dd1 | dd2 | dd3 | dd4 ;

dd1
: JCLBEGIN ddname DDWORD 'DUMMY';
dd2
: JCLBEGIN ddname DDWORD 'DYNAM';
dd3
: JCLBEGIN ddname DDWORD NAME'=' (''|NAME);
dd4
: JCLBEGIN ddname DDWORD '' inlinerec INLINESTMTEND?;

inlinerec
: (INLINEDATA )+ ;
fragment INLINEDATA
: (~[\r\n])*;

ddname
: NAME;

jclcomment
: JCLCOMMENT+;
JCLCOMMENT
: COMMENTBEGIN ~[\r\n]*;

DDWORD
: 'DD';

JCLBEGIN
: '//' ;

COMMENTBEGIN
: '//' ;
INLINESTMTEND
: '/' ;


NAME
: [A-Z#] (ALPHA | NUMBER | SPECIALCHARS)*;

NUMBER
: [0-9];
ALPHA
: [A-Z];
SPECIALCHARS
: '#' | '@' | '$';

WS
: [ \r\n] -> channel(HIDDEN);



My input is this:

//SYSIN DD *
SORT FIELDS
=COPY
INCLUDE COND
/*
//SYSPRINT DD SYSOUT=*
//* Comment line
#1
//* Comment line
#2
//SYSOUT DD SYSOUT=*
//CEEDUMP DD SYSOUT=*
//* Comment line
#3
//SYSUDUMP DD SYSOUT=A


When I use AntlrWorks to run this grammar with the input, I get the following error:

line 2:0 mismatched input 'SORT' expecting INLINEDATA
How can this error be resolved ?

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Immanuel Stephen

unread,
Jan 14, 2017, 9:57:29 AM1/14/17
to antlr-discussion
The grammar I have given is a partial grammar matching a particular construct of a language called JCL (used in IBM mainframe ZOS.
in the JCL language, comments start with //* and thats what I have put in my grammar. Also lines starting with // are the lines having the language statement.
There are many statements in the JCL language and I was having an issue with a statement called DD (Data definition) statement. Thats why I have isolated 
the statement construct into a separate grammar and trying to solve it. Though its a very short introduction to the JCL language, hope this give you an idea on 
what I am trying to achieve

Mike Cargal

unread,
Jan 17, 2017, 6:30:33 PM1/17/17
to ANTLR List
shouldn’t dd4 be:

dd4: JCLBEGIN ddname DDWORD ‘*’ inlinerec INLINESTMTEND;

(inline records need a DD *, you don’t have anything to match the “*")

you’re not doing anything to exclude whitespace after from DD * (on the same line) from inlinerec (and I suspect that the inlinrec rule cardinality should be * (not +)  pretty sure the following would be “valid” , though pretty unusual

//SYSIN DD *
/*

I believe that INLINESTMTEND should be ‘/*’  (right, my JCL’s a bit rusty, been a few years)

just some things that jump out (and are untested)

Immanuel Stephen

unread,
Feb 2, 2017, 12:55:20 PM2/2/17
to antlr-discussion
I did include a '*' after DDWORD but got missed in code formatting while writing the question.
For now I am having the cardinality of inlinerec as +

Immanuel Stephen

unread,
Feb 2, 2017, 1:14:49 PM2/2/17
to antlr-discussion
Reply all
Reply to author
Forward
0 new messages