ANTLR works 2 experience

57 views
Skip to first unread message

Илья Марголин

unread,
Jun 25, 2015, 5:20:25 PM6/25/15
to antlr-di...@googlegroups.com
I have to share it with you guys, because I did not find anything like a feedback forum for the antlr works 2, and I guess I have a lot of strong emotions my non geeky friends are not going to be interested in.

I've been keeping track of the antlr project for years now and I have to say it is still unusable by simple folks like me.

ok, here is my story. raw emotions. just don't read it if you are not ready.

I opened the antlr works 2 on windows. Copied a simple grammar from the book to the editor. Doesn't work! "Grammar has no rules". I've been programming since 2nd grade. It's been freaking 22 years! I didn't figure out what was wrong. I moved back and forth for 10 minutes and I didn't understand. Know what it was? Apparently the "IDE" doesn't feel it is necessary to save the file I'm editing first, prior to giving it to the tools!

OK. I need a very, VERY simple parser. I want to parse a chess FEN string. The parser is rather trivial to write by hand. Apparently I need lexer modes for that. Apparently that's an advanced feature, cause now the IDE says that I have to have a separate file for the lexer.

Do you think that steep learning curve they've been talking about when they mention ANTLR is about fancy LL(k) concepts? Actually I watched one video and got it. Steep learning curve is to figure out how the freak you make ANTLR understand that there are two related files: lexer and parser and that they should go together!

Apparently it's not simple. The so called IDE doesn't clean the error messages from the output, so whatever you do, you always have it red :( It took me 15 minutes, to figure out that lexer has to be precompiled first and only then does parser see it! That's the curve, not the "lexing" and "parsing" concepts.

Actually they teach you about "lexing" and "parsing" in any decent university. It's tools that make entering this universe so annoying.

Now came the moment when I just gave up. Finally I have lexer and parser, and there's no warnings nor errors, and I saved them, and I generated the java code from them (because by now there's no hope that the IDE does it itself when I press Run or give meaningful error), and I press "Run in  TestRig...", and I have no hope that it will work. I'm internally ready that there will be an error, and it will not be descriptive, and I will go and google again.

Guess what?
> Compiling grammar files...
> Arguments: [-o, C:\Users\Ilya\AppData\Local\Temp\TestRigTask-1435265231249, -lib, C:\Users\Ilya\Documents\Antlr, -no-listener, -no-visitor, C:\Users\Ilya\Documents\Antlr\FenLexer.g4]

That's it. That is all the "IDE" gave me. It does not work. There is no error. There is no "Done" message box. There is no "You are freaking idiot" message box. Nothing. How do I ask google why there is nothing going on?

I give up. I guess I will return a few years later again.

If someone read all the crap I just wrote and has a minute, I would love to read an explanation of why it is logical for the IDE to not follow up on the command I gave it.

Just in case it is needed here is the code:

lexer grammar FenLexer;
Piece : [pnbrqkPNBRQK];
Gap : [12345678];
Sep : '/';
TooManySpaces : '  ';
Ws : ' ' -> skip, pushMode(TURN);
mode TURN;
Black : 'b';
White : 'w';
TurnEnd : ' ' -> skip, popMode, pushMode(CASTLINGS);
mode CASTLINGS;
NoCastling : '-';
CastlingOption : [KQkq];
CastlingsEnd : ' ' -> skip, popMode, pushMode(ENPASSANT);
mode ENPASSANT;
NoEnPassant : '-';
File : [abcdefgh];
EnBlack : '3';
EnWhite : '6';
EnPassantEnd : ' ' -> skip, popMode, pushMode(TAIL);
mode TAIL;
Int : [0-9]+;
TailWs : ' ' -> skip;

parser grammar FenParser;
//import FenLexer;
options {
    tokenVocab=FenLexer;
}
fen : core Int Int;
core : placement turn castlings enPassant;
placement
    : rank Sep rank Sep rank Sep rank Sep
      rank Sep rank Sep rank Sep rank;
rank :  (Piece | Gap)+;
turn : Black | White;
castlings
    : NoCastling
    | CastlingOption (CastlingOption (CastlingOption CastlingOption?)?)?
    ;
enPassant
    : NoEnPassant
    | (EnBlack | EnWhite) File;

Terence Parr

unread,
Jun 25, 2015, 5:28:05 PM6/25/15
to antlr-di...@googlegroups.com
I suggest command line or Intellij :)  have you tried either of those?
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/d/optout.

Илья Марголин

unread,
Jun 29, 2015, 8:58:01 AM6/29/15
to antlr-di...@googlegroups.com
The problem is I'm so very far from Java. I'm .net. I downloaded the IDEA but got stuck. It really is not simple to get started with a complicated environment without guidance. And with command line tools I guess I'm not ready to go that low level :)

I guess I will wait till
a) I can install the ANTLR v >4 as an extension to the last version of the visual studio. Hopefully without polluting my machine with JRE
b) It works fine with the tools like Resharper/NCrunch (i.e. not the correct MSBuild integration model, but something like T4)
c) It does not require much to plug it into the CI (again T4-like integration model would be perfect)

I really hope MS or some big player does it because the community of the ANTLR enthusiasts is apparently too small to move this project forward with any decent speed

Eric Vergnaud

unread,
Jun 29, 2015, 10:28:05 AM6/29/15
to antlr-di...@googlegroups.com
Why don't you use the version from tunnelvisionlabs that is tightly integrated with VS?
It seems designed for you. It's available through NuGet.

Jim Idle

unread,
Jun 29, 2015, 10:33:35 AM6/29/15
to antlr-di...@googlegroups.com
You know, the world did a lot of work with vi and ed. Perhaps you should learn a few more fundamentals before jumping in to parsers? Command line tools are hardly low level. You seem to be trained/experienced with Microsoft IDEs only. That's cool, they are good, but you really need more arrows in your quiver than that. 
--

Sam Harwell

unread,
Jun 29, 2015, 12:21:24 PM6/29/15
to antlr-di...@googlegroups.com

Earlier this month I merged a pull request (#2) that adds new editor features for ANTLR 4 within Visual Studio. It should be released to the Visual Studio gallery soon.

 

For your three requests:

 

a.       There is no need to install a Visual Studio extension in order to use ANTLR. An optional extension for Visual Studio is available if you want additional editor features; this extension already does not use the JRE. The removal of the JRE requirement from the ANTLR 4 build integration is a work in progress: https://github.com/tunnelvisionlabs/antlr4cs/pull/94

b.      ReSharper is not Visual Studio. It replaces the IntelliSense functionality in Visual Studio with its own, and it does not behave the same way. The integration of ANTLR 4 with proper Visual Studio is completely seamless and works exactly the way a developer would expect. I recommend filing a feature request with JetBrains (or voting for the one I filed years ago), uninstalling ReSharper, or building a new integration which works specifically with ReSharper.

c.       This should already work, unless the JRE requirement is causing a problem. In that case, refer to the first item above. :)

--

Reply all
Reply to author
Forward
0 new messages