ANTLR3C
3.3.1
|
The antlr tool jar, run against a grammar file that targets the C language, will generate the following files according to whether your grammar file contains a lexer, parser, combined or treeparser specification. Your grammar file name and the subject of the grammar line in your file are expected to match. Here the generic name G is used:
Suffix | Generated files |
---|---|
lexer grammar (G.g3l) | GLexer.c GLexer.h |
parser grammar (G.g3p) | GParser.c GParser.h |
grammar G (G.g3pl) | GParser.c GParser.h GLexer.c GLexer.h |
tree grammar G; (G.g3t) | G.c G.h |
The generated .c files reference the .h files using <G.h>, so you must use -I.
on your compiler command line (or include the current directory in your include paths in Visual Studio). Additionally, the generated .h files reference antlr3.h
, so you must use -I/path/to/antlr/include
(E.g. -I /usr/local/include
) to reference the standard ANTLR include files.
In order to reference the library file at compile time (you can/should only reference one) you need to use the -L/path/to/antlr/lib
(E.g. -L /usr/local/lib
) on Unix, or add the path to your "Additional Library Path" in Visual Studio. You also need to specify the library using -L
on Unix (E.g. -L /usr/local/lib -l antlr3c
) or add antlr3c_dll.lib
to your Additional Library Dependencies in Visual Studio.
In case it isn't obvious, the generated files may be used to produce either a library or an executable (.EXE on Windows) file.
If you use the shared version of the libraries, DLL or .so/.so/.a then you must ship the library with your application must run in an environment whereby the library can be found by the runtime linker/loader. This usually involves specifying the directory in which the library lives to an environment variable. On Windows, X:{yourwininstalldir} will be searched automatically.
In order to run your lexer/parser/tree parser combination, you will need a small function (or main) function that controls the sequence of events, from reading the input file or string, through to invoking the tree parser(s) and retrieving the results. See "Using the ANTLR3C C Target" for more detailed instructions, but if you just want to get going as fast as possible, study the following code example.