Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Grammar Generation in C #

Shulou Source: shulou.com Published: 2022-06-02 09:15:41 09月28日 Update

This article will explain in detail how to achieve grammar generation in C#. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

The C # language has a lot to learn. Here we mainly introduce the production of C # grammar, including XX and so on.

Lexical grammar and syntactic grammar are represented by C # grammar production. Each grammar production defines a non-ending symbol and its possible extension (a sequence of non-terminators or Terminators). In grammar production, non-closing symbols are displayed in italics, while closing symbols are displayed in equal-width fonts.

The * line of the C # grammar generator is the name of the non-ending symbol defined by the production, followed by a colon. Each subsequent indentation lists a possible extension in the form of a sequence of non-Terminators or Terminators. For example, production:

◆ while-statement: (while statement:)

◆ while (boolean-expression)

◆ embedded-statement (while) embedded statement)

A while statement is defined, which starts with the tag while, followed by the tag "(", Boolean expression, tag ")" and the embedded statement.

When there is more than one possible non-closing symbol extension, list these possible extensions (each extension on a separate line). For example, production:

◆ statement-list: (statement list:)

◆ statement (statement)

◆ statement-list statement (statement list statement)

Define a list of statements that either contains only one statement or consists of a list of statements followed by a statement. In other words, the definition is recursive and the statement list consists of one or more statements.

If a symbol is suffixed with "optional" below, it indicates that the symbol is optional. Production:

Block: (block:)

{statement-listopt} ({statement list optional})

Is a short form of the following production:

Block: (block:)

{}

{statement-list} ({statement list})

It defines a block that consists of a list of optional statements enclosed in "{" and "}" tags.

Options are usually listed on separate lines, but when there are many options, you can add the phrase "one of the following" before the given extension list on a single line. This is just a short form of listing each option on a separate line.

This is the end of the article on "how to achieve grammar generation in C#". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Statements grammars symbols symbols tags terminators forms articles brevity line followed Boolean sequence more expressions good practical subscript content colons Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple OPPO Reno Docker Huawei