1
나는 SMLNJ를 처음 사용합니다. 이 작품 :표준 ML (smlnj) : 패턴 일치를위한 "상수"변수
case (tts t2) of
(other, "<+") => parse_append t t2 ts pre c j
| (other, "<<-") => parse_sample t t2 ts pre c j
| (other, "<-") => parse_assign_or_sub t t2 ts pre c j
| (_, _) => error t2 "parse_stmt: Expected sample, append or assignment operator."
(other
는 "데이터 형식 tokentype 매"유형의, t 및 T2는 토큰이며, tts
는 한 쌍의 (tokentype, content)
에 토큰을 매핑 나머지는 여기에 상황에 구체적이고하지 않는 것이 중요합니다..)
하지만 모듈 방식이 아닙니다. 특히 여러 장소에서 동일한 운영자와 대조를 맺고 있으므로 반복해서 반복하지 않기를 바랍니다. 그래서이 작동하지 않는,이 시도 :
(* this should go in a separate file of declarations *)
structure Ops = struct
val APPEND = "<+"
val SAMPLE = "<<-"
val ASSIGN = "<-"
end
(* this stays in the code *)
case (tts t2) of
(other, Op.APPEND) => parse_append t t2 ts pre c j
| (other, Op.SAMPLE) => parse_sample t t2 ts pre c j
| (other, Op.ASSIGN) => parse_assign_or_sub t t2 ts pre c j
| (_, _) => error t2 "parse_stmt: Expected sample, append or assignment operator."
분명히 할 수 있습니다 (방법으로, 의미가 있습니다) 변수의 값에 대한하지 패턴 일치합니다. 별도의 모듈에 값을 넣을 수 있도록 연산자 정의에 적용 할 수있는 "상수"선언이 있습니까? 아니면 SMLNJ에서이 작업을 수행 할 수있는 다른 좋은 방법이 있습니까?
될 수 있습니다 tokenizer,하지만이 작동합니다 부인할 수 없습니다. 하루나 이틀 안에 다른 해결책을 찾지 못하면 받아 들일 것입니다. – Bristol