Building new PHP target based on ANTL4

281 views
Skip to first unread message

mrpabl...@gmail.com

unread,
Jun 3, 2013, 9:13:43 PM6/3/13
to antlr-di...@googlegroups.com
Hi

I am relatively new in field of Compilers and ANTLR.

I would like to try build PHP target with ANTLR4. I have cloned repo with:
```
git clone https://github.com/antlr/antlr4.git
```

Then I installed maven and run:
```
mvn -N install
```

After that I run:
```
mvn -Duser.name="Your Name" -DskipTests=true install
```

as described here: http://www.antlr.org/wiki/display/ANTLR4/Building+ANTLR+4+with+Maven

I get the antlr4-runtime-4.0.1-SNAPSHOT.jar file, but when I try to run the following command:
``
java -cp .;antlr4-runtime-4.0.1-SNAPSHOT.jar org.antlr.v4.Tool
```
from the antlr4\runtime\Java\target> directory I get the following error:
```
Error: Could not find or load main class org.antlr.v4.Tool
```

I have no idea what is wrong? Can you give me some advice so I be able to fix it?

Thanks ;)

Kevin J. Cummings

unread,
Jun 3, 2013, 9:58:25 PM6/3/13
to antlr-di...@googlegroups.com
On 06/03/2013 09:13 PM, mrpabl...@gmail.com wrote:
> java -cp .;antlr4-runtime-4.0.1-SNAPSHOT.jar org.antlr.v4.Tool
^

Um, shouldn't that semi-colon above be a colon? Its a classpath separator.


--
Kevin J. Cummings
kjc...@verizon.net
cumm...@kjchome.homeip.net
cumm...@kjc386.framingham.ma.us
Registered Linux User #1232 (http://www.linuxcounter.net/)

mrpabl...@gmail.com

unread,
Jun 3, 2013, 10:25:43 PM6/3/13
to antlr-di...@googlegroups.com
On Tuesday, June 4, 2013 4:58:25 AM UTC+3, Kevin Cummings wrote:
> On 06/03/2013 09:13 PM, mrpabl...@gmail.com wrote:
>
> > java -cp .;antlr4-runtime-4.0.1-SNAPSHOT.jar org.antlr.v4.Tool
>
> ^
>
>
>
> Um, shouldn't that semi-colon above be a colon? Its a classpath separator.
>

Thanks Kevin for suggestion, I have tried both cases - ; and : and they don't work for some reason...

May be I don't have the org.antlr.v4.Tool class in the generated .jar and I need to compile the antlr4-4.x-complete.jar file somehow... Because the following command is working:
```
java org.antlr.v4.runtime.misc.TestRig
```

Could you describe a sequence of commands to compile the antlr4-4.x-complete.jar file?

Terence Parr

unread,
Jun 3, 2013, 10:29:30 PM6/3/13
to antlr-di...@googlegroups.com
i think you can just say "ant" and it will build you a nice little jar :)
Ter

Sam Harwell

unread,
Jun 3, 2013, 10:32:27 PM6/3/13
to antlr-di...@googlegroups.com
The steps to build the complete Jar are located here (section 4):

http://www.antlr.org/wiki/display/ANTLR4/Building+ANTLR+4+with+Maven

Keep in mind that there are substantially more requirements for the complete build, including configuring GraphViz, GPG, and the bootstrap classpath.

--
Sam Harwell
Owner, Lead Developer
http://tunnelvisionlabs.com
--
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.


mrpabl...@gmail.com

unread,
Jun 3, 2013, 11:28:46 PM6/3/13
to antlr-di...@googlegroups.com
Okay, I have installed ant and with one simple command I have got the antlr-4.0.1-dev-complete.jar file that just works. Thanks!

mrpabl...@gmail.com

unread,
Jun 3, 2013, 11:35:21 PM6/3/13
to antlr-di...@googlegroups.com
Thanks Sam, I have got the antlr-4.0.1-dev-complete.jar file, so I think it would be good to add this information to wiki to help others. I am also interesting why there are two different approaches to compile .jar - maven and ant?

Terence Parr

unread,
Jun 4, 2013, 12:00:09 AM6/4/13
to antlr-di...@googlegroups.com, antlr-di...@googlegroups.com
Haha. Take that, mvn.

Sent from my iPhone

Terence Parr

unread,
Jun 4, 2013, 12:03:05 AM6/4/13
to antlr-di...@googlegroups.com, antlr-di...@googlegroups.com
People prefer different approaches. maven is the most complicated build system I've ever seen so I prefer ant. I am literally not smart enough to use maven. Honestly though I simply use Javac *.java in my IDE.

Sent from my iPhone

mrpabl...@gmail.com

unread,
Jun 10, 2013, 5:17:43 AM6/10/13
to antlr-di...@googlegroups.com
I have added the following block of code in the PHP.stg:
```
// ...
ParserFile(file, parser, namedActions) ::= <<
<fileHeader(file.grammarFileName, file.ANTLRVersion)>
>>

Parser(parser, funcs, atn, sempredFuncs, superClass) ::= <<
<Parser_(ctor="parser_ctor", ...)>
>>

Parser_(parser, funcs, atn, sempredFuncs, ctor, superClass) ::= <<
@TODO: Parser
>>

DefaultParserSuperClass(s) ::= "BaseParser"

LexerFile(lexerFile, lexer, namedActions) ::= <<
<fileHeader(file.grammarFileName, file.ANTLRVersion)>
>>

DefaultLexerSuperClass(s) ::= "BaseLexer"

Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= <<
@TODO: Lexer
>>

fileHeader(grammarFileName, ANTLRVersion) ::= <<
\<?php
/**
* Automatically generated with ANTLR <ANTLRVersion>.
*/
namespace My\Ns;
>>
// ...
```
After running of antlr I get Parser.java with the '@TODO Parser' string, but Lexer.java contains Java code for some reason, however I expect that it will contain the '@TODO: Lexer' string.

It seems like the Lexer related lines are ignored in the string template file.

Could describe what is wrong or what should be done to fix this problem and generate Lexer with @TODO string?

Reply all
Reply to author
Forward
0 new messages