# Zkouška 19.1.2023 String Expressions Evaluator

<{ForumPost(poster="cart1er", timestamp=2023-01-21 16:51:58)}>
2 testy na základní funkcionalitu (30b), zbytek na errory (20b).  
  
---  
Implement evaluator of string concatenation expressions.  
  
**Summary**  
The executable shall be passed two parameters:  
  
A path to string function definitions  
A path to string expressions  

    prog FUNCS_FILE EXPRS_FILE

The goal is to process all function definitions and evaluate all expressions using obtained functions.  
  
**Function Definitions File Composition**  
Each line contains a single function definition. A single line shall be as follows:  

    FUNCTION_NAME ARGS = BODY

First comes a single word FUNCTION_NAME, which serves as a function identifier. ARGS is a list of whitespace separated words. These define identifiers of the function arguments. BODY is a (possibly empty) list of whitespace separated function argument identifiers (defined in ARGS part). Each word (either function name or argument) is a sequence of letters (std::isalpha).  
  
Examples:  

    foo x = x
    goo x y = y x
    hoo a b c = a a a

**String Expressions File Composition  
**  
Each line contains a single string expression. A single line shall be as follows:  

    FUNCTION_NAME(ARG1,ARG2,...,ARGN)
    

FUNCTION_NAME shall be equal to one of the functions in the function definitions file. Using () notation, the function is called with comma separater arguments. Number of passed arguments shall be equal to the number of arguments specified in the function definition. ARG argument can be twofold: either it is string (a sequence of characters enveloped with ") or another function call.  
  
Example:  

    foo("ahoj")
    goo("a","b")
    hoo(foo("ahoj"),goo("l","m"),"x")

**Task**  
The program shall process function definitions file and print value of each string expression on separate line. The value is computed by passing arguments to the functions and concatenating strings as specified by the body of the function definitions.  
  
The solution using the examples above as file contents:  

    prog funcs.txt exprs.txt

    ahoj
    b a 
    ahoj ahoj ahoj

**Bad Inputs**  
When program encounters a malformed line (bad function name, no equals sign, malformed expression), it shall print **parse error** to standard output.  
Other errors  
- when BODY contains word not present in ARGS - print **def error** to standard output  
- when an expression contains an undefined function name - print **nodef error** to standard output  
- when a function is called with incorrect number of parameters - print **param error** to standard output  
  
When the program encounters erroneous line, it prints error message and continues processing other lines.
<{/ForumPost}>

