# The SmPL Grammar (version 1.1.1 ) ### Research group on Coccinelle ### January 30, 2025

This document presents the grammar of the SmPL language used by the Coccinelle tool. For the most part, the grammar is written using standard notation. In some rules, however, the left-hand side is in all uppercase letters. These are macros, which take one or more grammar rule right-hand-sides as arguments. The grammar also uses some unspecified nonterminals, such as id, const, etc. These refer to the sets suggested by the name, i.e., id refers to the set of possible C-language identifiers, while const refers to the set of possible C-language constants.

A square bracket that is surrounded by spaces in the description of a term should appear explicitly in the term, as in an array reference. On the other hand, square brackets that surround some other term indicate that the presence of that term is optional.

A PDF version of this documentation is available at https://coccinelle.gitlabpages.inria.fr/website/docs/main_grammar.pdf.

- Program
- Metavariables for Transformations
- Metavariables for Scripts
- Control Flow
  - Basic dots
  - Dot variants
  - An example
- Transformation
  - Basic transformations
  - Advanced transformations
- Types
- Function Declarations
- Declarations
- Statements
- Expressions
- Constants, Identifiers and Types for Transformations
- Comments and Preprocessor Directives
- Command-Line Semantic Match
- Iteration
- .cocciconfig Support
- Examples
  - Function renaming
  - Removing a function argument
  - Introduction of a macro
  - Look for NULL dereference
  - Reference counter: the of_xxx API
  - Filtering identifiers, declarers or iterators with regular expressions
- Tips and Tricks
  - How to remove useless parentheses?

> This document was translated from LATEX by H E V E A.