VOOZH about

URL: https://www.geeksforgeeks.org/compiler-design/yacc-program-to-implement-a-calculator-and-recognize-a-valid-arithmetic-expression/

⇱ YACC program to implement a Calculator and recognize a valid Arithmetic expression - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

YACC program to implement a Calculator and recognize a valid Arithmetic expression

Last Updated : 26 Aug, 2020
Problem: YACC program to implement a Calculator and recognize a valid Arithmetic expression. Explanation: Yacc (for “yet another compiler compiler.”) is the standard parser generator for the Unix operating system. An open source program, yacc generates code for the parser in the C programming language. The acronym is usually rendered in lowercase but is occasionally seen as YACC or Yacc. Examples:
Input: 4+5 
Output: Result=9
Entered arithmetic expression is Valid

Input: 10-5
Output: Result=5
Entered arithmetic expression is Valid

Input: 10+5-
Output: 
Entered arithmetic expression is Invalid

Input: 10/5
Output: Result=2
Entered arithmetic expression is Valid

Input: (2+5)*3
Output: Result=21
Entered arithmetic expression is Valid

Input: (2*4)+
Output: 
Entered arithmetic expression is Invalid

Input: 2%5
Output: Result=2
Entered arithmetic expression is Valid 
Lexical Analyzer Source Code: Parser Source Code : Output: 👁 Image
Comment
Article Tags:

Explore