Troubles for building a correct chess pgn grammar.

113 views
Skip to first unread message

laurent bernabe

unread,
Dec 28, 2013, 4:43:21 PM12/28/13
to antlr-di...@googlegroups.com
Hello everyone,

I am trying to build my own chess PGN grammar : compilation is fine, but when parsing a PGN file, the flow is broken since the first caracter !!!

This is the error I get :

______________________________________________________________
line 1:0 mismatched input '[Event "?"]' expecting {'[', MOVE_NUMBER}
______________________________________________________________

What's wrong with my grammar ? (I would like, for each game, to have the collected tags in a group called tag, and in the notation group, to collect each single/pair of halfmoves individually. And that can explain some of the grammar choices).

I've joined the pgn file I've used for the test.

Regards
Scandinave.pgn

Terence Parr

unread,
Dec 28, 2013, 5:01:10 PM12/28/13
to antlr-di...@googlegroups.com
sounds like a UTF-8 or other encoding issue.  
Ter
--
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/groups/opt_out.
<Scandinave.pgn>

laurent bernabe

unread,
Dec 28, 2013, 5:22:47 PM12/28/13
to antlr-di...@googlegroups.com
Hello,

thank you for your answer,

I did not though about this problem.
Meanwhile, I notice that I forgot to give an updated version of the grammar I am working on (now it's done).

Furthermore, as I added modifications, I noticed that errors and result tree was quite differents. That make me think I am still on the learning way of the grammars building :).

This time I get these errors :

____________________________
line 1:7 token recognition error at: '"?'
line 1:9 token recognition error at: '"]'
line 2:6 token recognition error at: '"?'
line 2:8 token recognition error at: '"]'
line 3:6 token recognition error at: '"?'
line 3:8 token recognition error at: '?'
line 3:9 token recognition error at: '?'
line 3:10 token recognition error at: '?'
line 3:12 token recognition error at: '?'
line 3:13 token recognition error at: '?'
line 3:15 token recognition error at: '?'
line 3:16 token recognition error at: '?'
line 3:17 token recognition error at: '"]'
line 4:7 token recognition error at: '"?'
line 4:9 token recognition error at: '"]'
line 5:7 token recognition error at: '"o'
line 5:27 token recognition error at: '"]'
line 6:7 token recognition error at: '"o'
line 6:27 token recognition error at: '"]'
line 7:8 token recognition error at: '"*'
line 7:10 token recognition error at: '"]'
line 8:5 token recognition error at: '"C'
line 8:9 token recognition error at: '"]'

line 2:0 mismatched input '[' expecting TAG_VALUE
line 3:0 mismatched input '[' expecting TAG_VALUE
line 3:11 mismatched input '.' expecting TAG_VALUE
line 5:0 mismatched input '[' expecting TAG_VALUE
line 5:9 mismatched input 'peningTrainerWhite' expecting TAG_VALUE
line 6:9 mismatched input 'peningTrainerBlack' expecting TAG_VALUE
line 8:0 mismatched input '[' expecting TAG_VALUE
line 8:7 mismatched input '01' expecting TAG_VALUE
________________________________________________

Regards
Scandinave.pgn
Pgn.g4

Terence Parr

unread,
Dec 28, 2013, 5:55:25 PM12/28/13
to antlr-di...@googlegroups.com
i'm afraid you'll have to read the manual/book and see examples rather than just pasting in rexpr stuff like this: ;)

TAG_VALUE:  '"'[:print:]*'"';

Ter
--
Dictation in use. Please excuse homophones, malapropisms, and nonsense. 

laurent bernabe

unread,
Dec 28, 2013, 6:17:14 PM12/28/13
to
Thank you very much :)

I used this kind of notation([:print:]) in Regex, but it can't apply here.

My pgn grammar is nearly complete : I've just problems with the NEWLINE lexer : I can't figure why it can't resolve '\n' into the lexer NEWLINE.

Errors are :

_____________________________

line 1:11 mismatched input '\n' expecting NEWLINE
line 2:10 mismatched input '\n' expecting NEWLINE
line 3:19 mismatched input '\n' expecting NEWLINE
line 4:11 mismatched input '\n' expecting NEWLINE
line 5:29 mismatched input '\n' expecting NEWLINE
line 6:29 mismatched input '\n' expecting NEWLINE
line 7:12 mismatched input '\n' expecting NEWLINE
line 8:11 mismatched input '\n\n1.' expecting NEWLINE
_________________________________

Regards


Le samedi 28 décembre 2013 23:55:25 UTC+1, the_antlr_guy a écrit :
i'm afraid you'll have to read the manual/book and see examples rather than just pasting in rexpr stuff like this: ;)

TAG_VALUE:  '"'[:print:]*'"';

Ter
Pgn.g4

laurent bernabe

unread,
Dec 29, 2013, 10:52:32 AM12/29/13
to
I've gone one step further :
The tags are well parsed, but I still have problem for discarding newlines.

Problematic token is in red :
________________________________________________________________
[@0,0:0='[',<5>,1:0]
[@1,1:5='Event',<10>,1:1]
[@2,7:9='"?"',<11>,1:7]
[@3,10:10=']',<6>,1:10]
[@4,12:12='[',<5>,2:0]
[@5,13:16='Site',<10>,2:1]
[@6,18:20='"?"',<11>,2:6]
[@7,21:21=']',<6>,2:9]
[@8,23:23='[',<5>,3:0]
[@9,24:27='Date',<10>,3:1]
[@10,29:40='"????.??.??"',<11>,3:6]
[@11,41:41=']',<6>,3:18]
[@12,43:43='[',<5>,4:0]
[@13,44:48='Round',<10>,4:1]
[@14,50:52='"?"',<11>,4:7]
[@15,53:53=']',<6>,4:10]
[@16,55:55='[',<5>,5:0]
[@17,56:60='White',<10>,5:1]
[@18,62:82='"openingTrainerWhite"',<11>,5:7]
[@19,83:83=']',<6>,5:28]
[@20,85:85='[',<5>,6:0]
[@21,86:90='Black',<10>,6:1]
[@22,92:112='"openingTrainerBlack"',<11>,6:7]
[@23,113:113=']',<6>,6:28]
[@24,115:115='[',<5>,7:0]
[@25,116:121='Result',<10>,7:1]
[@26,123:125='"*"',<11>,7:8]
[@27,126:126=']',<6>,7:11]
[@28,128:128='[',<5>,8:0]
[@29,129:131='ECO',<10>,8:1]
[@30,133:137='"C01"',<11>,8:5]
[@31,138:138=']',<6>,8:10]
[@32,139:142='\n\n1.',<13>,8:11]
[@33,144:145='e4',<13>,10:3]
[@34,147:148='d5',<13>,10:6]
[@35,150:151='2.',<13>,10:9]
[@36,153:154='d4',<13>,10:12]
[@37,156:156='(',<3>,10:15]
[@38,158:159='2.',<13>,10:17]
[@39,161:164='exd5',<13>,10:20]
[@40,166:169='Qxd5',<13>,10:25]
[@41,171:171='(',<3>,10:30]
[@42,173:176='2...',<13>,10:32]
[@43,178:180='Nf6',<13>,10:37]
[@44,182:182=')',<4>,10:41]
[@45,184:185='3.',<13>,10:43]
[@46,187:189='Nc3',<13>,10:46]
[@47,191:193='Qa5',<13>,10:50]
[@48,195:195=')',<4>,10:54]
[@49,197:197='(',<3>,10:56]
[@50,199:200='2.',<13>,10:58]
[@51,202:203='f3',<13>,10:61]
[@52,205:208='dxe4',<13>,10:64]
[@53,210:211='3.',<13>,10:69]
[@54,213:216='fxe4',<13>,10:72]
[@55,218:218=')',<4>,10:77]
[@56,220:223='2...',<13>,10:79]
[@57,225:226='e6',<13>,10:84]
[@58,228:229='3.',<13>,10:87]
[@59,231:234='exd5',<13>,10:90]
[@60,236:239='exd5',<13>,10:95]
[@61,242:242='*',<1>,10:101]
[@62,243:242='<EOF>',<-1>,10:102]
line 8:11 extraneous input '\n\n1.' expecting {'[', MOVE_NUMBER}
(file (game (tag [ Event "?" ]) (tag [ Site "?" ]) (tag [ Date "????.??.??" ]) (tag [ Round "?" ]) (tag [ White "openingTrainerWhite" ]) (tag [ Black "openingTrainerBlack" ]) (tag [ Result "*" ]) (tag [ ECO "C01" ]) \n\n1. e4 d5 2. d4 ( 2. exd5 Qxd5 ( 2... Nf6 ) 3. Nc3 Qa5 ) ( 2. f3 dxe4 3. fxe4 ) 2... e6 3. exd5 exd5 * notation))
_________________________________________________________________________________________________________________________________________

The new grammar and the Scandinave.pgn test file are joined.

Regards
Scandinave.pgn
Pgn.g4

Terence Parr

unread,
Dec 29, 2013, 12:31:12 PM12/29/13
to antlr-di...@googlegroups.com
On Dec 29, 2013, at 7:49 AM, laurent bernabe wrote:

I've gone one step further :
The tags are well parsed, but I still have problem for discarding newlines.

doesn't look that way to me
T
Regards

--
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/groups/opt_out.
<Scandinave.pgn><Pgn.g4>

laurent bernabe

unread,
Dec 29, 2013, 4:47:23 PM12/29/13
to antlr-di...@googlegroups.com
It is strange, because as when debugging in AntlrWorks2,
it has some troubles with some newlines.

Maybe should I use the antlr4 command line tools, and not rely on AntlrWork2.

Terence Parr

unread,
Dec 29, 2013, 4:51:29 PM12/29/13
to antlr-di...@googlegroups.com
AW2 and the command-line might be using diff versions of antlr lib?
T

laurent bernabe

unread,
Dec 29, 2013, 4:57:51 PM12/29/13
to antlr-di...@googlegroups.com
No, I've said nonsense.
It can't be AW2 version nor the Antlr bin I've setup in my PATH, as they are the latest.

But I've always a problem for ignoring all '\n' inputs, as I got a token whose value is '\n\n1.',
instead of just having the token '1' and the token '.' .

Regards

John B. Brodie

unread,
Dec 29, 2013, 5:42:46 PM12/29/13
to antlr-di...@googlegroups.com
Greetings!

Should the NO_SPECIAL_GRAPH negation also include the \t \r and \n chars?

Hope this helps....
   -jbb

laurent bernabe

unread,
Dec 29, 2013, 6:09:56 PM12/29/13
to antlr-di...@googlegroups.com
Hello,

Thank you for your suggestion.

Now all the newlines are removed :).

Now I've got to improve the tokens for the notation rule.

Regards

laurent bernabe

unread,
Dec 29, 2013, 6:41:12 PM12/29/13
to antlr-di...@googlegroups.com
Far better now : all tokens are well grouped.
I am skipping the points in move numbers.

There's just a little problem with some parenthesis which seem to have been excluded from the parser stream.

Regards.
Pgn.g4

laurent bernabe

unread,
Dec 29, 2013, 6:52:20 PM12/29/13
to
Finally got it !!!

Thank you for all your answers :)

My final grammar is joined to this message.
Pgn.g4
Reply all
Reply to author
Forward
0 new messages