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
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');
inc (arrayCounter);
writeln;
menu;
end;
's': {display all identifiers}
begin
for i := 0 to arrayCounter -1 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
arrayCounter := 0; {array counter initialisation}
menu;
end.