-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
43 lines (31 loc) · 1.32 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Seminar project for Non-procedural Programming, NPRG005 in Summer semester 2022/23
on MFF CUNI.
Author: Tomas Sourada, 3rd year on undergraduate studies of Computer Science,
study field Artificial Intelligence.
Topic: Arithmetic expression parser and evaluator.
Task: Create a Prolog predicate, which takes a string containing an arithmetic
expression written in words in the Czech language, converts it to its
number-operator variant and evaluates it.
Supports usual Czech language, input string tokens separated by space, without
commas. Supports integers written with or without diacritis and usual operators
'+', '-', '*', '-' and simple parentheses '(', ')'.
Implemented on SWI-Prolog version 8.4.3 for x86_64-linux.
Date of implementation: from 2022-09-09 to 2022-09-14.
Example call:
# Start SWI-prolog:
> swipl
# Compile `main.pl`:
?- [main].
true.
# Run the predicate:
?- evaluateExpressionString("třináct krát tři", Value).
Input string: třináct krát tři
Expression: 13 * 3
Result: 39
Value = 39.
# Run the predicate:
?- evaluateExpressionString("jedna plus dva krát tři minus závorka sedm minus čtyři konec závorky deleno tremi", Value).
Input string: jedna plus dva krát tři minus závorka sedm minus čtyři konec závorky deleno tremi
Expression: 1 + 2 * 3 - ( 7 - 4 ) / 3
Result: 6
Value = 6.