Question: Below are the syntax and semantics for a single Boolean expression followed by a period. Write a program which prompts the user to input a
Below are the syntax and semantics for a single Boolean expression followed by a period. Write a program which prompts the user to input a file name which contains the Boolean expression or simply to input the string to be checked (indicate which input method you will use in your comments). You may assume that no input will be longer than 100 characters in length. Expressions may contain white spaces and white spaces should be considered as delimiters (i.e. a white space between the ? and > of the implication symbol would be a syntax error). The program should check if the expression in the file is of valid syntax and (if valid) compute the value of the expression. The output should either be an error message or a message that gives the value of the expression.
Syntax: (note: for ? use the lowercase letter v and for ? use the caret symbol)
Selection Sets
?B? ::= ?IT? . {~,T,F,(}
?IT? ::= ?IT? ?IT_Tail? {~,T,F,(}
?IT_Tail? ::= ?> ?OT? ?IT_Tail? {? >}
::= ? {.,)}
?OT? ::= ?AT? ?OT_Tail? {?,T,F,(}
?OT_Tail? ::= ? ?AT? ?OT_Tail? {?}
::= ? {? >,.,)}
?AT ? ::= ?L? ?AT_Tail? {?,T,F,(}
?AT_Tail? ::= ? ?L? ?AT_Tail? {?}
::= ? {?,? >,.,)}
?L? ::= ?A? {T,F,(}
::= ~ ?L? {~}
?A? ::= T {T}
::= F {F}
::= ( ?IT? ) {(}
Syntactic Domains:
?B? : Bool_stmt
?IT? : Imply_term
?OT? : Or _ term
?AT? : And_ term
?IT Tail? : Imply_tail
?OT Tail? : Or_tail
?AT Tail? : And_tail
?L? : Literal
?A? : Atom
Semantic Domain:
b = {T.F} (Boolean values True and False)
Semantic Function Domains:
?: Bool_stmt ? b
?: Imply_term ? b
?:Or_term? b
?: And_term? b
?: b Imply_tail? b
?: b Or_tail? b
?: b And_tail? b
? : Literal ? b
?: Atom? b
Semantic Equations:
?(? ?IT?. ?) = ?(? ?IT? ?)
?(? ?OT??IT Tail? ?) = ?(?(? ?OT? ?),? ?IT Tail? ?)
?(? ?AT??OT Tail? ?) = ?(?(? ?AT? ?),? ?OT Tail? ?)
?(??L??AT Tail??)= ?(?(??L??),??AT Tail??)
?(b,?) = b (where b ? {T,F})
?(F,? ? > ?OT??IT Tail? ?) = ?(T,? ?IT Tail? ?)
?(T,? ? > ?OT??IT Tail? ?) = ?(?(? ?OT? ?),? ?IT Tail? ?)
?(b,?) = b (where b ? {T,F})
?(T,? ??AT??OT Tail? ?) = T
?(F,? ??AT??OT Tail? ?) = ?(?(? ?AT? ?),? ?OT Tail? ?)
?(b,?) = b (where b ? {T,F})
?(F,???L??AT Tail??)=F
?(T,? ??L??AT Tail? ?) = ?(?(? ?L? ?),? ?AT Tail? ?)
?(???L??)= if ?(??L??)=T then F else if ?(??L??)=F then T
?(? ?A? ?) = ?(? ?A? ?)
?(?T ?)=T
?(?F ?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
