//converted from C++ to Java applet. DFW //modified for boolean expressions DFW // & | ~ operators, variables, 0 1 //Stroustrup's real-number calculator. C++ Programming Language chapter 6. //Ex. to evaluate with p true and q false: // p=1; q=0; (p&(~(~p|q)))|(p&q) //or as: // 1&(~(~1|0))|(1&0) //as command line argument or interactively. //Interactively: either on one line, or each semicoloned statement on own line: //p=1 //q=0; //(p&(~(~p|q)))|(p&q) //semicolon is optional. //White space optional: (p & (~( ~p|q))) |(p & q) //Parens optional. & higher precedence than | //p&(~(~p|q))|p&q import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class ParserLogic extends JApplet { public final char NAME='\000', NUMBER='\001', END='\002', OR='|', NEGATE='~', AND='&', PRINT=';', ASSIGN='=', LP='(', RP=')'; char curr_tok = PRINT; String input; int index; boolean bool_value; String string_value; int no_of_errors; Map table; JTextField inputField; JLabel resultLabel; JButton clearButton; JLabel errorLabel; public void init() { table = new HashMap(); Container container = getContentPane(); int panelRowsSize = 4; container.setLayout( new GridLayout( panelRowsSize, 1 ) ); JPanel [] panelRows = new JPanel[panelRowsSize]; for (int i=0; i