PHP Target

135 views
Skip to first unread message

Marcos Passos

unread,
May 2, 2017, 9:40:17 AM5/2/17
to antlr-discussion

I would like to propose introducing a PHP target and runtime.


Is anyone interested in joining me to implement a PHP target?

morrisfre...@gmail.com

unread,
Dec 21, 2018, 10:53:31 AM12/21/18
to antlr-di...@googlegroups.com
Hello Marcos Passos,

I did it for PHP 7.2.

I have used the ANTLR4-runtime C++ target to phpize the library.

<!DOCTYPE html><?xml-stylesheet href="antlr.css" ?><?php
$text
= <<<ANTLR
grammar Calculator;

NUMBER: [0-9]+;
WS
: [ \\t\\r\\n]+ -> skip ; // notice the antislash in hereDoc

expr
   
: sum=(a=expr '+' b=expr)
   
| sub=(a=expr '-' b=expr)
   
| mul=(a=expr '*' b=expr)
   
| div=(a=expr '/' b=expr)
   
| fac=('(' a=expr ')')
   
| num=(a=NUMBER)
   
;
ANTLR
;

$doc = new ANTLRDocument(); // By default the ANTLRDocument use the antlr4 grammar. Use ANTLRImplementation to select parser
$doc->load($text);
$xml
= $doc->saveHTML();// $doc->saveJAVA(); ... $doc->saveCPP();

// output expected :


antlr4-php7.png

Reply all
Reply to author
Forward
0 new messages