Implementing logic from text

I have a program that receives inputs as text, for example:

IF (A.4.1-1/1 OR A.4.1-1/2) AND A.4.4-1/9 AND (A.4.4-1/12 OR A.4.4-1/13 OR A.4.4-1/14 OR A.4.4-1/15) THEN R ELSE N/A

where A.4.1-1/1etc. - variables with a value TRUE or FALSE. so far I have parsed the text into logical parts for the above example. I have a list that looks like this:

['IF', '(', 'A.4.1-1/1', 'OR', 'A.4.1-1/2', ')', 'AND', 'A.4.4-1/9', 'AND', '(', 'A.4.4-1/12', 'OR', 'A.4.4-1/13', 'OR', 'A.4.4-1/14', 'OR', 'A.4.4-1/15', ')', 'THEN', 'R', 'ELSE', 'N/A']

I'm just wondering if it is possible to actually execute the logic on this list, how to combine all this into rquired python statements and provide the result. I'm not sure that I should have started reading on some sites, that I should use the analyzer from top to bottom

+5
source share
2 answers

This sounds like a task for pyparsing :

pyparsing , lex/yacc . Python.

( ) . -, Pyparsing 300 .

+6

Python, Java, JavaCC. , grammar ( EBNF, ), โ€‹โ€‹, JavaCC, , , .

, ( , if-then-else, , ).

Python .

+1
source

All Articles