Implement an interpreter for the language described below. The standard input receives a program in the given language. Output the decimal value of the last expression in the program.
Language grammar:
<character> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J"
| "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V"
| "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h"
| "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t"
| "u" | "v" | "w" | "x" | "y" | "z" | "_"
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<number> ::= <digit> | <digit> <number>
<identifier> ::= <character> | <identifier> <character>
<operation> ::= "+" | "-" | "*" | "/" | "%" | ">" | "<" | "="
<constant-expression> ::= "-" <number> | <number>
<binary-expression> ::= "(" <expression> <operation> <expression> ")"
<argument-list> ::= <expression> | <expression> "," <argument-list>
<call-expression> ::= <identifier> "(" <argument-list> ")"
<if-expression> ::= "[" <expression> "]?{" <expression> "}:{"<expression>"}"
<expression> ::= <identifier>
| <constant-expression>
| <binary-expression>
| <if-expression>
| <call-expression>
<parameter-list> ::= <identifier> | <identifier> "," <parameter-list>
<function-definition> ::= <identifier>"(" <parameter_list> ")" "={" <expression> "}"
<function-definition-list> : ""
| <function-definition> <EOL>
| <function-definition> <EOL> <function-definition-list>
<program> ::= <function-definition-list> <expression>
<EOL>
- newline symbol - \n
, the program doesn't contain other whitepsace characters.
Language semantics:
- All variables are 32-bit integers
- Overflows do not occur
- All arithmetic operations are equivalent to corresponding ones in Java
- Comparison operations return 1 if true, 0 otherwise
<if-expression>
evaluates the second expression, if the first is not 0, otherwise it evaluates the third<call-expression>
calls function with given name- Expressions are evaluated left to right