Difference between revisions of "PLC Laboratory 2"
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
| − | == | + | == Lexical analyzer == |
| − | + | Write a program, that reads an input and converts it into a sequence of lexical symbols – tokens. Each token composes from a type and possibly a value. | |
| − | + | The tokens definition depends on you, and it is considered a part of the solution. | |
== Input specification == | == Input specification == | ||
| − | The | + | The input may be containing the following symbols: |
| + | * ''identifiers'' - consisting of a sequence of letters and numbers starting with a letter | ||
| + | * numbers - formed by a sequence of decimal digits | ||
| + | * operators - symbols '+', '-', '*' and '/', | ||
| + | * delimiters - symbols '(', ')' and ';', | ||
| + | * keywords - <code>div</code> and <code>mod</code>. | ||
| + | |||
| + | Symbols can be separated by a sequence of spaces, tabs, and line breaks. | ||
| + | |||
| + | Notes are preceded by a sequence <code>//</code> and continue to the end of the line. | ||
| + | |||
== Output specification == | == Output specification == | ||
Revision as of 08:33, 26 January 2022
Lexical analyzer
Write a program, that reads an input and converts it into a sequence of lexical symbols – tokens. Each token composes from a type and possibly a value.
The tokens definition depends on you, and it is considered a part of the solution.
Input specification
The input may be containing the following symbols:
- identifiers - consisting of a sequence of letters and numbers starting with a letter
- numbers - formed by a sequence of decimal digits
- operators - symbols '+', '-', '*' and '/',
- delimiters - symbols '(', ')' and ';',
- keywords -
divandmod.
Symbols can be separated by a sequence of spaces, tabs, and line breaks.
Notes are preceded by a sequence // and continue to the end of the line.
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, write text ERROR instead.
Example
- Input
2
2 * (3+5)
15 - 2**7
- Output
16
ERROR