Search code examples
compiler-theory

Type of error in expression evaluating process


Supposing I want to write module to evaluate e simple string expression like "5+3", "(7*8/2)/6" etc... The process that I am thinking of is:

  1. Lexical analysis in order to convert the string to set of atoms (numbers and operation).
  2. Convert the set of atoms from infix to postfix
  3. Evaluate the postfix and output the final result

My question is about the errors that happens in each stage:

  1. In first stage I should handle undefined symbols or empty string and calling them lexical errors. Is that right? anything to add?
  2. In the second stage, having something like two consequence multiplications symbol (*) is a not valid thing. What is this error called?
  3. In the third stage, Division by zero is an example of an error. What are this kind of errors called?

Solution

    1. Lexical error sounds right, though they could be syntax errors too.
    2. Syntax error: valid syntax does not have ** as a valid operator or sequence of operators.
    3. Run-time errors, or sometimes semantic errors.