Gramatica is run from the command-line. The available command line options are printed when running without any options, as can be seen in the figure below.
# java -jar grammatica-1.0.jar Syntax: Grammatica <grammarfile> <action> [<options>] Actions: --tokenize <file> Debugs the grammar by using it to tokenize the specified file. No code has to be generated for this. --parse <file> Debugs the grammar by using it to parse the specified file. No code has to be generated for this. --csoutput <dir> Creates a C# parser for the grammar (in source code). The specified directory with be used as when generating source code files. --javaoutput <dir> Creates a Java parser for the grammar (in source code). The specified directory with be used as base directory when generating source code files. C# Output Options: --csnamespace <package> Sets the C# namespace to use in generated source code files. --csclassname <name> Sets the C# class name prefix to use in generated source code files. --cspublic Sets public access for all C# types generated. Java Output Options: --javapackage <package> Sets the Java package to use in generated source code files. --javaclassname <name> Sets the Java class name prefix to use in generated source code files. --javapublic Sets public access for all Java types. Error: Wrong number of arguments
Figure 1. The command-line help output from Grammatica.
The ordering of the command-line parameters is important. The first argument should always be the grammar file. The second argument should always be one of the four available actions, with the additional file or directory parameter. The specific output options for C# and Java are all optional, choosing default values if not specified.
Grammatica can be used for parsing and tokenizing files, even though no parser has been generated. This feature can be very useful for testing and debugging grammars, as illustrated in the figure below.
# java -jar grammatica-1.0.jar test.grammar --parse test.data
Figure 2. Command-line for using Grammatica to parse a test data file.