COMP1820 - CODE EXERCISE (Part of Section C of your Logbook) General information: This code exercise will form part of your logbook and should be submitted on Moodle by the logbook deadline. It is to...

1 answer below »
Create Flex and Bison files to generate a post-fix notation calculator for Boolean algebra. The calculator should be able to handle Boolean expressions with the input values TRUE and FALSE, together with the operators AND (&), OR (|) and NOT (!). The program should accept keyboard input and exit on the end-of-file character (CTRL+d).


COMP1820 - CODE EXERCISE (Part of Section C of your Logbook) General information: This code exercise will form part of your logbook and should be submitted on Moodle by the logbook deadline. It is to be submitted under the “Code submission” link in the “Assessment” block. Note: It is important that your submission adheres to the specification, as it is automatically marked. Task: Create Flex and Bison files to generate a post-fix notation calculator for Boolean algebra. The calculator should be able to handle Boolean expressions with the input values TRUE and FALSE, together with the operators AND (&), OR (|) and NOT (!). The program should accept keyboard input and exit on the end-of-file character (CTRL+d). Technical Specification: • Calculations happen whenever a newline character is read (i.e. when enter is pressed) • The input accepted should: o cover both capital and lower-case letters for TRUE and FALSE, o also accept 0 for FALSE and 1 for TRUE. o accept only the symbols &, | and ! to denote AND, OR and NOT respectively. The following are examples of valid input values: TrUe fALSE True false truE fAlSe TRUE FALSE true 0 1 The following are all valid operators: & | ! • The compiler should display a generic error message if it is unable to parse the input. • Output should simply be the answer to the expression: TRUE or FALSE (Note: The answers should only be one of these exact strings, in capital letters) Here are some examples: We wish to calculate TRUE AND FALSE INPUT: TRUE FALSE & OUTPUT: FALSE We wish to calculate TRUE OR FALSE INPUT: true 0 | OUTPUT: TRUE We wish to calculate NOT TRUE INPUT: 1! OUTPUT: FALSE We wish to calculate NOT(TRUE AND FALSE) OR FALSE INPUT: tRuE FaLsE & ! fAlSe | OUTPUT: TRUE Upload Specification: • You need to upload two files with the following names: boolcalc.l boolcalc.y • Files should be uploaded as they are -- not zipped, tar-ed or placed in a directory. • Make sure the files you are uploading compile and run correctly and provide the correct output. Notes about C you might find useful: • There are no Boolean primitives in C, but you can use integers to represent these. • Expressions evaluating to 0 is FALSE and non-zero is TRUE. • The Boolean operators in C are denoted as: AND: && OR: || NOT: ! An if-statement has the format if (test expression) { statements to be executed if expression is true } else { statements to be executed if expression is false } More information on C syntax at https://www.cprogramming.com/tutorial/c/lesson2.html
Answered 3 days AfterApr 15, 2021

Answer To: COMP1820 - CODE EXERCISE (Part of Section C of your Logbook) General information: This code exercise...

Kamal answered on Apr 18 2021
155 Votes
#include
#include
#include
#include
// structure for s
tack
struct Stack
{
int top;
int* arr;
unsigned size;
};
typedef struct Stack stack;
// functions
char makeInput (char*);
int boolCalc (char*);
stack* create (unsigned);
int isEmpty (stack*);
char peek (stack*);
void push (stack*, char);
char pop (stack*);
int main()
{
    char inputArr[50], *token, input[10];
    int output, i = 0;
    
    // read input into a string
    gets(inputArr);
    
    // split the input string
    token = strtok(inputArr, " ");
    
    while (token != NULL)
    {
        // make the input
        input[i++] = makeInput(token);
        token = strtok(NULL, "...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here