eval_expr proc pascal near
          call get_token
          cmp token,NULL
          jne @@enable_process
          push NO_EXP
          call serror
@@enable_process:          
          call eval_expr2
          call putback
          ret
eval_expr endp

;EVAL_EXPR2 - provides processing PLUS and MINUS
eval_expr2 proc pascal near
           uses cx,dx

           call eval_expr3
           mov cx,ax
@@cycle:           
           mov dl,token
           cmp dl,PLUS
           je @@get_down
           cmp dl,MINUS
           je @@get_down
           jmp @@exit
@@get_down:          
           call get_token
           call eval_expr3
           cmp dl,MINUS
           jne @@handle_plus
           sub cx,ax
           jmp @@cycle          ;is there more minuses ?
@@handle_plus:           
           add cx,ax              
           jmp @@cycle          ;is there more pluses ?
@@exit:    
           mov ax,cx
           ret
eval_expr2 endp

eval_expr3 proc pascal near
           uses bx,cx,dx
           
           call eval_expr4
           mov cx,ax
@@cycle:           
           mov dl,token
           cmp dl,_MUL
           je @@get_down
           cmp dl,_DIV
           je @@get_down
           jmp @@exit
@@get_down:          
           call get_token
           call eval_expr4
           cmp dl,_MUL
           jne @@handle_div
           imul cx
           mov cx,ax
           jmp @@cycle          ;is there more * ?
@@handle_div:           
           cmp ax,ZERO
           jne @@enable_div
           call putback
           push DIV_BY_ZERO
           call serror
@@enable_div:           
           xor dx,dx
           xchg ax,cx
           idiv cx
           mov cx,ax
           jmp @@cycle          ;is there more / ?
@@exit:    
           mov ax,cx
           ret
eval_expr3 endp


;EVAL_EXPR4 - performs processing of (), unary + and -, numbers
;RETURNS: AX - result
eval_expr4 proc pascal near
           local @@result:RES_TYPE
           
@@switch:
           cmp token_type,NUMBER
           je @@get_number
           cmp token,PLUS
           jne @@check_sign
           call get_token       ;skip unary '+'
           jmp @@switch
@@get_number:           
           push offset token
           call atoi
           cmp ax,OK
           je @@save_number
           push ax
           call serror
@@save_number:
           mov @@result,bx
           call get_token
           jmp @@exit
@@check_sign:
           cmp token,MINUS
           jne @@check_bracket
           call get_token 
           call eval_expr4
           neg ax
           mov @@result,ax
           jmp @@exit
@@check_bracket:                ;check for brackets
           cmp token,LP
           jne @@check_variable
           call get_token
           call eval_expr2
           mov @@result,ax
           cmp token,RP
           je @@next_token
           push UNBAL_PARENS
           call serror
@@next_token:
           call get_token   
           jmp @@exit 
@@check_variable:
           cmp token_type,VARIABLE 
           jne @@default
           push offset token
           call find_var
           mov @@result,ax
           call get_token
           jmp @@exit
@@default:
           call putback
           push SYNTAX
           call serror
@@exit:         
           mov ax,@@result     
           ret
eval_expr4 endp
 