Numeric Expression Grammar in Backus–Naur form (BNF)

This information is interesting but not required for the project

Definitions

1.syntax: the spelling and grammatical structure of a computer language

2. semantics: the meanings of the words and phrases

3. Lexical analysis, or tokenization is the process of converting a sequence of characters into a sequence of tokens (strings).

4. BNF: Backus–Naur form

In the 1950s, Noam Chomsky realized that rules for building syntactically correct sentences can be written as an equational definition. Chomsky called the definition a grammar. John Backus and Peter Naur independently discovered the same concept, and for this reason, a grammar is sometimes called BNF (Backus-Naur form) notation.

A grammar is a set of equations (rules), where each equation defines a set of phrases (strings of words).

Numeric Expression in BNF

EXPRESSION ::= TERM
             | EXPRESSION '+' TERM
             | EXPRESSION '-' TERM

TERM       ::= FACTOR
             | POWER
             | TERM '*' FACTOR
             | TERM '/' FACTOR
             | TERM '%' INTEGER

POWER      ::= FACTOR '**' FACTOR

FACTOR     ::= NUMBER
             | '(' EXPRESSION ')'

NUMBER     ::= INTEGER
             | FLOAT
             | REAL

INTEGER    ::= ['-' | '+'] DIGIT {DIGIT}

FLOAT      ::= INTEGER '.' {DIGIT}

REAL       ::= (INTEGER | FLOAT) ('e' | 'E') INTEGER

DIGIT      ::= '0' | '1' | ... | '8' | '9'

           []  enclose optional items
           ()  enclose optional items, one of which is required
           {}  zero or more optional item; not required.
            |  separate alternatives

Links

Syntax Of the Gentee Language In BNF Form

The syntax of C in Backus-Naur Form