PLC Laboratory 8

From Marek Běhálek Wiki
Revision as of 09:51, 27 January 2022 by Beh01 (talk | contribs)
Jump to navigation Jump to search

Interpreter of Arithmetic Expressions Using ANTLR II

Extend the interpreter of arithmetic expressions from previous Laboratory 7 with the usage of variables.

The basic description is still valid. Expressions contain +, -, *, / operators (with common priorities and left associativity) and parentheses. To simplify the task, consider we have only binary operators. There are no unary operators in our language.

But now, we have variables. Their identifiers compose from letters and they have two types: float and int. Before variables are used, they need to be defined. The language is extended with = operator (lowest priority and right associativity).

Moreover, our expression now has a type. If it contains only integer numbers and variables it is int. In all other cases it is float.

Input specification

In the input, there are expressions, they are writtent with free formatting. Each expression ends with semicolon. Numbers can be written similarly to C language constants. it can be either: decimal , octal (starting with zero) or hexadecimal (starting with characters 0x) number.

Output specification

For each expression write one line containing the result – the computed value of the expression. If there is any error in the input, you can stop the computation.

Example

  • Input
012-10; 2 * (0xff+5);
0x23e5-0x201;
  • Output
0
520
8676