0% found this document useful (0 votes)
8 views2 pages

Lab6 Assignment

Uploaded by

hgj jh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Lab6 Assignment

Uploaded by

hgj jh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Sl.

Problem Statement
No

Assignment 6 ( 28 Feb 2024)

Write Lex and Yacc program for the following : ( Question 1 - 5 marks, Question 2 - 5 marks )

John is a newbie programmer. He has a string which is an arithmetic expression, he is struggling to find the
1 result of this string by creating a YACC program. He also wants to know whether arithmetic expression is valid
or not. John needs your help to write the YACC program.

Input format

The first line contains string S.

Output format

The first line contains, string S is valid or Invalid.

The second line indicates the result.

Sample Input Sample Input

(( 7 * 2 - 12 * 1 + 2) / 7) % 3 (2 * 4) + (4 / 5) + 5 - 2 - 1 * 7 %

Sample output Sample output

Valid Invalid

Sample Input Sample Input

(5 ^ 12 * 4 / 2486 + ( 578 - 124) / 4)) 4 * 3.142 * r * r

Sample output Sample output

? ?
2 Zayan is throwing a birthday party. Seeing the extravagant parties thrown by her friends like Varaa and Arik in
the past, Zayan too decided to do something unique. Being a Computer Engineer himself, he knew just how to

do it. He sent a password-protected e-invites(string) to his friends. Now their task is to convert the given string

which is an infix expression to a postfix expression and to find the result of that string. Underscore separated

postfix expression and result which would be the password for that invite. Help Zayan friends in finding the

password so that they can enjoy the birthday party!

Input format

The first line contains string S.

Output format

The first line contains a postfix expression

The second line indicates the result.

The third line indicates the password.

Constraints

1 <= | string length | <= 1000

Sample Input Sample Input Sample Input

8 - 15 / (5 * 3) + 10 (( (7 % 2) - 12 / 12 * 8) + 3) % 20 (55 ^ 12 )* (4 / 2486) + ( 578 - 124) % 351

Sample output Sample output Sample output

8 15 5 3 * / - 10 + 7 2 % 12 12 / 8 * - 3 + 20 % ?

17 ? ?

81553*/-10+_17 ? ?

You might also like