Production Rules

Learn the production rules useful in parsing a template string.

Introduction

Production rules represent the formal way to describe grammar. It can be considered as a rewriting rule composed of two parts. Terminals are symbols that cannot be subdivided further, whereas, nonterminals are symbols that may be subdivided further. A non-terminal symbol on the left, followed by an arrow and a string of non-terminal and terminal symbols.
Below is an example of formal grammar described by two production rules:

S -> <V>
V -> ([$\w.])+

{ S, V } : No terminal symbols
S : Starting symbol
([$\w.])+ : RegEx

This grammar generates a language that produces open tags. For example sentences like <div>, <span>, <custom> are supported by the above grammar.

Get hands-on with 1200+ tech skills courses.