Send
Close Add comments:
(status displays here)
Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Logical expression definitions
1. Logical expression definitions
2. Inductive definition
Here is an inductive (bottom-up) definition of a logical expression using 0 for false and 1 for true.
3. Inductive base cases
Base cases:
Literal 0 is a logical expression.
Literal 1 is a logical expression.
Variable x is a logical expression if x contains a logical value.
4. Inductive step cases
Step cases: If
x and
y are logical expressions, then so are the following.
x & y (conjunction)
x | y (disjunction)
x ^ y (exclusive or, non-equality)
x = y (equality)
! x (negation)
( x ) (grouping)
5. Deductive grammar definition
Here is a deductive grammar (top-down) definition of a logical expression using
0 for
false and
1 for
true.
Expr = Term { ExprOp Term } .
Term = Factor { TermOp Factor } .
Factor = Literal | Variable | "(" Expr ")" | "!" Expr .
ExprOp = "&" | "=" .
TermOp = "|" | "^^" .
Literal = "0" | "1" .
Variable = "name" .
Note: The terminal symbols, such as "name", are defined as tokens that can be any valid name.
The notation used is
EBNF (
Extended Backus Naur Form) , This notation will be covered in more detail later.
6. Grammar
Here is the first part of the grammar.
Expr = Term { ExprOp Term } .
Term = Factor { TermOp Factor } .
Factor = Literal | Variable | "(" Expr ")" | "!" Expr .
Note:
ExprOp,
TermOp,
Literal, and
Variable are defined below.
7. Syntax diagrams
Here are the syntax diagrams for the first part of the grammar.

8. Grammar
Here is the second part of the grammar.
ExprOp = "&" | "=" .
TermOp = "|" | "^^" .
Literal = "0" | "1" .
Variable = "name" .
9. Syntax diagrams
Here are the syntax diagrams for the second part of the grammar.

10. End of page
11. Acronyms and/or initialisms for this page
1 acronyms omitted (login required)