The grammar instrumenter works in two phases. In the first phase, the probe specification file is processed by the specification processor. In the second phase, the grammar processor is used to process the language grammar specification. It parses the grammar specification file and generates the instrumented grammar.
Figure 5.5 shows a flowchart depicting the work flow in the grammar instrumenter. Below, its working is described in detail.
The specification processor accepts the probe specification file as input and parses it. All the sections of the probe specification file are processed separately and are checked for syntactic correctness. The code from variable declaration section is extracted and stored in a temporary file. The production rules from the production rule section are processed next and a production table is created that stores all these rules. Now, the probe definition section is parsed and a probe definition table is generated that contains all the TCA symbols along with their corresponding code. Lastly, the code in the code section is processed and stored in a temporary file.
In the next phase, the grammar instrumenter takes the grammar specification file as input. The grammar parser parses the grammar specification, identifies each section and provides this information to the instrumenter. Instrumenter uses this information along with the tables and files generated by the specification processor to instrument the grammar.
The variable and token declaration section of the yacc specification is processed first. The variable declaration code stored in the temporary file is merged with this code and is written into the instrumented grammar file. The rule section of the grammar is processed next. The production rules are read one by one and passed to the rule comparator. It searches the production table for a rule that match with the given rule. If a matching rule is found, the production is instrumented by inserting probe actions in place of the TCA symbols in the rule. The instrumented rule is added in the instrumented grammar. If no matching rule is found in the production table, the rule is added as it is. This process continues until all the rules in the grammar file are processed. Lastly, the code section of the grammar specification is processed. It is merged with the code section of the probe specification file, stored in the temporary file and copied in the instrumented grammar.
Now, the instrumented grammar file and its corresponding lexical specification file is processed by Yacc and Lex respectively. The output is compiled to generate the Test Coverage Analyzer.