How To Use

The LGen is a command-line tool and all steps involved with its use are made by editing files and running commands. First step is to create a grammar in EBNF notation. This step is done in any text editor. The saved file is used as input for the translator. With the EBNF grammar file the next step is to run the translator to generate a Lua specification file for the initial EBNF grammar. The last step is running the generation engine to build the set of test data. In following sections each step of the process is explained in detail.

Build EBNF Grammar

The input grammars that are used by LGen should be described in EBNF notation. This notation used in input grammar is described below:

Operator Syntax Description
Sequence Term1, Term2 A term Term1 is generated and then Term2 will be generated.
Alternative Term1 | Term2 A term Term1 or Term2 can be generated.
Optional [Term1] A term Term1 may or not be generated.
One or More Term1+ A term Term1 can be generated one or more times.
One or More With Separator Term1+Str A term Term1 can be generated one or more times and when it is generated more then one time Str is used to separate the terms.
Zero or More {Term1} A term Term1 can be generated zero or more times.

The terminals are defined by strings and non-terminals by identifiers. The derivation rules are defined by an identifier and an expression. The empty symbol is defined by empty pattern in expression. One example of input grammar is shown below:

OMA = "a" | "a", OMA;
OMB = "b" | "b", OMB;

Running the Translator

Once defined an input grammar, it is necessary to use the Translator to translate the EBNF notation to Lua specification. This process is done by the translator component at command-line. In the command line interface, go to folder where Translator is installed. Now run Translator using the bash script The first parameter of the translator is the input grammar in EBNF notation and the second is the start symbol of grammar. An example of command-line call is shown below :

./ Examples/Est.BNFOnly_WCycle_01.ebnf ST

With this command, a new file is generated with the name Est.BNFOnly_WCycle_01.lua. Note that this new file has extension "lua", because it is a Lua program. The content of this file is shown below:

G.startSymbol = "ST"

G.ST = alt(V.OMA,V.OMB)
G.OMA = alt(terminal("a"),seq(terminal("a"),V.OMA))
G.OMB = alt(terminal("b"),seq(terminal("b"),V.OMB))

Now with this file, Lua specification, we can run the generation engine component.

Running the Generation Engine

The generation engine is a command line tool. To use it you need the following steps:

  1. Open your console terminal;
  2. Go to LGen folder in your environment. This folder is referenced by "<LGenFolder>".
  3. Run this command:
./ Examples/Est.BNFOnly_WCycle_01.lua 1 4 term

The above command follows the pattern shown below :

./ <LuaGrammarSpec> <maxCycles> <maxDerivLen> <coverCrit>

Each item of the pattern is explained as follow:

  • LuaGrammarSpec: Inform the path to the Lua grammar specification.
  • maxCycles: Positive integer value that controls the maximum number of recursion cycles of a non-terminal used in the process of sentence generation.
  • maxDerivLen: Positive integer value that controls the height of the derivation tree associated with the generated sentences.
  • coverCrit: configures a coverage criterion to direct the generation process. Currently, the options are the term, for terminal coverage criterion, and prod, for production coverage criterion. LGen has been designed with these, but can easily adapted with the inclusion of new criteria.

Once the parameters passed in the execution, the LGen is executed and it results in two files. The first file has an extension out that contains the sentences. For the example above the name of file is Est.BNFOnly_WCycle_01.terminalCoverage.1.4.out and your contents are listed below:


The second file, with extension prf, contains information about the generation process. In addition, information such as coverage criteria, coverage rate of the selected criteria, number of generated sentences, memory used and elapsed run time of the generation engine are presented on the screen. This file name is Est.BNFOnly_WCycle_01.terminalCoverage.1.4.prf and your contents are listed below:

Derivation{[1]="ST", [2]="OMA"}
Derivation{[1]="ST", [2]="OMB"}
--Num. Sentences: 2
NonTerm{'OMB', 'OMA', 'ST'}

The name of these files follows the pattern "<LuaGrammarSpec>.<coverCrit>.<maxCycles>.<maxDerivLen>" and they are saved in same folder of the LuaGrammarSpec file.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License