Open-source image
open-source
Hime logo

Table of content

Grammar options

The Hime language let you specify various options for the grammar. They must appear in the options section of your grammars. The supported options are:

grammar MathExp
{
options
{
Axiom = "file";
Separator = "WHITESPACE";
OutputPath = "path/to/compilation/output";
CompilationMode = "Source";
ParserType = "LR";
Runtime = "Net";
Namespace = "Com.SeriousBusiness.MyApp";
AccessModifier = "Internal";
}
terminals { }
rules { }
}

Axiom

The Axiom option let you specify the top variable of your grammar. The value of this option should simply be the name of the variable.

Separator

The Separator option let you specify the name of a single terminal that will act as a separator token. The corresponding terminal must be defined in the terminals section of your grammar. The effect of this option is that the separator terminal will be matched by the lexer and dropped immediately. You will never find a token of the separator type in the syntax tree produced by a parser. The separator terminal is usually the aggregation of whitespaces, line endings and comments. A typical way to defined the separator terminal is as follow:

grammar MathExp
{
options
{
Axiom = "exp";
Separator = "SEPARATOR";
}
terminals
{
NEW_LINE -> U+000D /* CR */
| U+000A /* LF */
| U+000D U+000A /* CR LF */
| U+2028 /* LS */
| U+2029 /* PS */ ;
WHITE_SPACE -> U+0020 | U+0009 | U+000B | U+000C ;
COMMENT_LINE -> '//' (.* - (.* NEW_LINE .*)) ;
COMMENT_BLOCK -> '/*' (.* - (.* '*/' .*)) '*/' ;
SEPARATOR -> (NEW_LINE | WHITE_SPACE | COMMENT_LINE | COMMENT_BLOCK)+;
}
rules {}
}

OutputPath

The OutputPath option (requires himecc v3.1.0 or later) let you specify the default path for the compilation artifacts produced by the compilation of this grammar. This option may be overriden by the himecc compiler with the -p option. The default path is the empty path. Relative path are resolved agains the current directory of the himecc compiler.

CompilationMode

The CompilationMode option (requires himecc v3.1.0 or later) let you specify the type of artifacts to be produced by the himecc compiler. The default value is Source. This option may be overriden by the himecc compiler with the -o:xxxx options. The supported values for this options are:

  • Source (default): Generates the sources of the corresponding parser for this grammar.
  • Assembly: Generates a compiled and assembled package (dll for .Net and jar for Java).
  • SourceAndAssembly: Generates for the sources and the compiled, assembled package.
  • Debug: Generates the debug artifacts for this grammar, i.e. the sources and additional data used for debugging purposes.

ParserType

The ParserType option (requires himecc v3.1.0 or later) let you specify which kind of parsing method shall be used for the generated parser. The default value is LR. This option may be overriden by the himecc compiler with the -m:rnglr option. The supported values for this options are:

  • LR (default): LR parsing method with a LALR(1) automaton.
  • RNGLR: RNGLR parsing method with a RNGLALR(1) automaton.

Runtime

The Runtime option (requires himecc v3.1.0 or later) let you specify which runtime shall be targetted for generated parsers. The default value is Net. This option may be overriden by the himecc compiler with the -t:xxx options. The supported values for this options are:

  • Net (default): Target the .Net runtime ; sources are generated in C# and assemblies will be .dll files.
  • Java: Target the Java runtime ; sources are generated in Java and assemblies will be .jar files.
  • Rust: Target the Rust runtime ; sources are generated in Rust and assemblies will be .so files on Linux and .dll files on Windows.

Namespace

The Namespace option (requires himecc v3.1.0 or later) let you specify the namespace for the generated code. The default value is the grammar's name. This option may be overriden by the himecc compiler with the -n option.

AccessModifier

The AccessModifier option (requires himecc v3.1.0 or later) let you specify the access modifier for the generated code. The default value is Internal. This option may be overriden by the himecc compiler with the -a:xxxx options. The supported values for this options are:

  • Internal (default): The generated code is assembly-internal for the .Net target and package-internal for the Java target.
  • Public: The generated code is public.