Difference between revisions of "PLC Laboratory 9"
(Created blank page) |
|||
Line 1: | Line 1: | ||
+ | == Compiler of Arithmetic Expressions Using ANTLR == | ||
+ | Extend the interpreter of arithmetic expressions from previous [[PLC_Laboratory_7 | Laboratory 7]]. In this laboratory, for each expression generate a target | ||
+ | |||
+ | The language 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. We will use only integer numbers. | ||
+ | |||
+ | == Input specification == | ||
+ | |||
+ | In the input, there are expressions, they are written in 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 | ||
+ | <syntaxhighlight lang="haskell" > | ||
+ | 012-10; 2 * (0xff+5); | ||
+ | 0x23e5-0x201; | ||
+ | </syntaxhighlight > | ||
+ | |||
+ | * Output | ||
+ | ''Your output may be different. Type error's messages are not precisely defined and there is no defined precision for floating point numbers.'' | ||
+ | <syntaxhighlight lang="haskell" > | ||
+ | |||
+ | </syntaxhighlight > |
Revision as of 10:43, 27 January 2022
Contents
Compiler of Arithmetic Expressions Using ANTLR
Extend the interpreter of arithmetic expressions from previous Laboratory 7. In this laboratory, for each expression generate a target
The language 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. We will use only integer numbers.
Input specification
In the input, there are expressions, they are written in 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
Your output may be different. Type error's messages are not precisely defined and there is no defined precision for floating point numbers.