Skip to content

Statement Constructor

Prasant Acharya 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.

1) S                 Transform this S into (S) | (S) 
2) (S) | (S)         Transform the first S into (S) & (S)
3) ((S) & (S)) | (S) Transform the S's into their respective variables
4) ((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.

Clone this wiki locally