2017-03-10 2 views
1

난에 "다른"표현이 누락되어지고있어 오류 :계획 프로그래밍 컴파일 오류

(if (not (eq? current_token next_token)) 
    (return #f)) 

나는 당신이 볼 수있는 아래의 이미지에서 다른 문이있다. 왜 프로그램이 그것을 찾을 수 없는지 확실하지 않습니다.

scheme code image

답변

0

참고가 if 조건부의 신택스가 있음 : #f 이외의 값을 생성 test-expr 경우

(if test-expr then-expr else-expr) 

그런 다음 then-expr 평가 도착한다는 및 #f 경우가 생성되고 else-expr이 평가됩니다.

(if test-expr then-expr) 
; test-expr = (not (eq? current_token next_token)) 
; then-expr = (return #f) 
; Not complete - missing an else expression 

이 문제를 해결하기 위해 else expression를 추가하는 것과 같습니다

(if (not (eq? current_token next_token)) (return #f)) 

:

현재 다음있다. 예를 들어

:

> (if true 0)  ; test-expr = true, then-expr = 0 
if: missing an "else" expression in: (if true 0) 
> (if true 0 1) ; test-expr = true, then-expr = 0, else-expr = 1 
0 
> (if false 0 1) ; test-expr = false, then-expr = 0, else-expr = 1 
1 
0

이미지는 질문에 코드를 포함하는 정말 가난한 방법입니다. 의 경우 각각if 세 가지 추가 요소가 필요합니다. (if predicate consequence alternative). 포함 된 코드에는 포함 된 (not (eq? current_token next_token)) 형식의 술어가 있고 (return #f)은 결과 집합이지만 조건부가 거짓 인 경우에는 대안이 없습니다. cond에있는 else 용어와 아무 관련이 없습니다. 선택 사항이며 cond 중 하나 인 이 아닌 cond입니다.

current-tokennext-token 두 기호가 모두 일치하는 경우 어떻게 표시됩니까? 일단 용어가 치면 결과가 나오고 다른 곳은 방문하지 않을 것입니다. if은 두 개가 같은지 확인합니다. 일치하지 않으면 오류가 발생합니다.