Home > front end >  What are the steps to generate a C target in ANTLR3, brew does not support ANTLR3, and I cannot find
What are the steps to generate a C target in ANTLR3, brew does not support ANTLR3, and I cannot find

Time:11-16

I am currently working on rewriting a parser project of mine from java to C. I'd love to stick with ANTLR as I find it easy to use, but unfortunately ANTLR4 no longer supports C targets. Luckily, ANTLR3 does, and I've whipped up a quick grammar to test things, but I'm unclear on how to generate the code. I'm on macOS Monterey, and I've tried the CLI tool (using antlr <file>). The code does not generate however, and I get an error saying ANTLR cannot generate C code as of version 4.11.1. This is to be excepted, but there is not a command line tool for ANTLR3 (as far as I can find).

Brew supports installing antlr@2, but not 3, and I cannot find any extensions in VSCode to generate the C target. My grammar is below, if that matters:

grammar Q;

options 
{
    language = C;
}

program
    : PRINT
    ;

// Tokens.
PRINT
    : 'printf' '<' ID '>'
    ;


WS  :   (' '|'\t'|'\n') 
    ;

fragment
ID  :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
    ;        

CodePudding user response:

The approach hasn't changed between ANTLR3 and ANTLR4. You can still start the generation process by invoking Java with the ANTLR jar, like:

java -Xmx1024m -jar antlr-3.4-complete.jar -make MySQL.g

  • Related