The grammar of expressions

The Backus-Naur Form (BNF) notation is used to specify the grammar for programming languages. The semantics of BNF can be learned from books, and plenty of material is available. The grammar of the expression evaluator we use is as follows:

    <Expr> ::= <Term> | Term { + | - } <Expr> 
    <Term> ::= <Factor> | <Factor> {*|/} <Term> 
    <Factor>::= <number> | ( <expr> ) | {+|-} <factor> |  
                SIN(<expr>) | COS(<expr>) | $t 

This BNF can be converted to source code very easily.

Get .NET Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.