Skip to content

Latest commit

 

History

History
46 lines (29 loc) · 958 Bytes

using_terminals_in_expressions.md

File metadata and controls

46 lines (29 loc) · 958 Bytes

Using Terminals In Expressions

The <expression> part of a grammar rule can contain terminals. For example:

S: A;

terminals

A: 'a';

This grammar accepts exactly the string a.

Alternatively, this grammar can also be written as the grammar below, where we replace A with 'a' in the grammar rule:

S: 'a';

terminals

A: 'a';

In general, we can replace a terminal name with its content in any grammar rules. The new grammar is equivalent to the old one. It would have better readabilities especially for long grammar files.

Multiple terminals can be concatenated in a grammar rule such as the grammar below:

S: A B C;

terminals

A: 'a';
B: 'b';
C: 'c';

This grammar accepts exactly the string abc with optional white spaces allowed in between.

➡️ Next: Using Grammar Symbols In Expressions

📘 Back: Table of contents