-
Notifications
You must be signed in to change notification settings - Fork 0
Statement Constructor
NYYuHao edited this page Feb 10, 2020
·
11 revisions
The string constructor for building a statement (which holds logical statements as a tree) is recursive, and requires that the given input is passed in a very specfic format.
A statement takes in a string S, and S can be constructed using the following CFG to build any desired statement.
S -> (S) | (S) or (S) & (S)
- etc. For other arguments S -> A or B or C or Hello
- etc. For other variables
As an example, consider A and B or C.
- S * Transform this S into (S) | (S)
- (S) | (S) * Transform the first S into (S) & (S)
- ((S) & (S)) | (S) * Transform the S's into their respective variables
- ((A) & (B)) | (C)`
Given the above string, the statement constructor will parse this into a tree with the root containing '|', its left holding a node with '&', etc.