program ExpressionEval; {$APPTYPE CONSOLE} uses SysUtils; type Identifier = record Name : String; Value : String; end; const CAPACITY = 19; var menuchoice : char; i : integer; identValue : String; identName : String; identArray : array[0..CAPACITY] of Identifier; arrayCounter : integer; procedure menu; begin arrayCounter := 0; {array counter initialisation} writeln ('(d)isplay menu'); writeln ('(l)ex keyboard input to tokens'); writeln ('(p)arse the tokens into a parse tree'); writeln ('(e)valuate the parse tree'); writeln ('(b)ind an identifier to a value'); writeln ('(s)how the values of all the identifiers'); writeln ('(q)uit'); writeln; write ('Selection => '); readln (menuchoice); case menuchoice of 'd': menu {re-displays the menu}; 'l': {lex into tokens}; 'p': {parse tokens into tree}; 'e': {evaluate tree}; 'b': {Get user-entered values for identifiers} begin write ('Enter the name of the identifier : '); readln (identName); identArray[arrayCounter].Name := identName; write ('Enter the value to assign to this identifier : '); readln (identValue); identArray[arrayCounter].Value := identValue; writeln ('Identifier added'); arrayCounter := arrayCounter + 1; writeln; menu; end; 's': {display all identifiers} begin for i := 0 to arrayCounter do begin writeln ((identArray[i].Name), ' : ', (identArray[i].Value)); end; writeln ('End of list'); writeln; menu; end; 'q': {nothing - quits program}; else writeln ('Invalid selection, please choose again'); menu; end; end; begin menu; end.