home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
snobol
/
aisnobol
/
wang.spt
< prev
Wrap
Text File
|
1987-10-16
|
3KB
|
88 lines
* WANG.SPT - SPITBOL Version
*
* Wang's algorlthm
*
* Adapted from
* Griswold, R. E., Poage, J. F., & Polonsky, I. P.
* The SNOBOL4 Programming Language.
* Pp. 183-185.
*
* To run:
* spitbol wang.spt <wang.in
*
DEFINE('WANG(ANTECEDENT,CONSEQUENT)PHI,PSI')
UNOP = 'NOT'
BINOP = ('AND' | 'IMP' | 'OR' | 'EQU')
UNOP.FORMULA = ' ' (UNOP . OP) '(' (BAL . PHI) ')'
BINOP.FORMULA = ' ' (BINOP . OP) '(' (BAL . PHI) ','
+ (BAL . PSI) ')'
FORMULA = UNOP.FORMULA | BINOP.FORMULA
ATOM = (NOTANY(' ') (BREAK(' ') | REM)) . A
+ :(WANG.END)
*
WANG
OUTPUT = ANTECEDENT ' >>> ' CONSEQUENT
ANTECEDENT FORMULA = NULL
+ :F(WANG1)S( $('WANG.A.' OP) )
WANG.A.NOT
WANG(ANTECEDENT, CONSEQUENT ' ' PHI)
+ :S(RETURN)F(FRETURN)
WANG.A.AND
WANG(ANTECEDENT ' ' PHI ' ' PSI, CONSEQUENT)
+ :S(RETURN)F(FRETURN)
WANG.A.OR
WANG(ANTECEDENT ' ' PHI, CONSEQUENT) :F(FRETURN)
WANG(ANTECEDENT ' ' PSI, CONSEQUENT)
+ :S(RETURN)F(FRETURN)
WANG.A.IMP
WANG(ANTECEDENT ' ' PSI, CONSEQUENT) :F(FRETURN)
WANG(ANTECEDENT, CONSEQUENT ' ' PHI)
+ :S(RETURN)F(FRETURN)
WANG.A.EQU
WANG(ANTECEDENT ' ' PHI ' ' PSI, CONSEQUENT)
+ :F(FRETURN)
WANG(ANTECEDENT, CONSEQUENT ' ' PHI ' ' PSI)
+ :S(RETURN)F(FRETURN)
WANG1
CONSEQUENT FORMULA =
+ :F(WANG2)S( $('WANG.C.' OP) )
WANG.C.NOT
WANG(ANTECEDENT ' ' PHI, CONSEQUENT)
+ :S(RETURN)F(FRETURN)
WANG.C.AND
WANG(ANTECEDENT, CONSEQUENT ' ' PHI) :F(FRETURN)
WANG(ANTECEDENT, CONSEQUENT ' ' PSI)
+ :S(RETURN)F(FRETURN)
WANG.C.OR
WANG(ANTECEDENT, CONSEQUENT ' ' PHI ' ' PSI)
+ :S(RETURN)F(FRETURN)
WANG.C.IMP
WANG(ANTECEDENT ' ' PHI, CONSEQUENT ' ' PSI)
+ :S(RETURN)F(FRETURN)
WANG.C.EQU
WANG(ANTECEDENT ' ' PHI, CONSEQUENT ' ' PSI)
+ :F(FRETURN)
WANG(ANTECEDENT ' ' PSI, CONSEQUENT ' ' PHI)
+ :S(RETURN)F(FRETURN)
WANG2
ANTECEDENT ATOM = :F(FRETURN)
CONSEQUENT A :S(RETURN)F(WANG2)
WANG.END
*
*
*
&ANCHOR = 0
&TRIM = 1
SETEXIT(.CONTINUE)
*
READ
EXPRESSION = INPUT :F(END)
OUTPUT =
OUTPUT = 'FORMULA: ' EXPRESSION
OUTPUT =
OUTPUT = WANG( NULL, ' ' EXPRESSION ) 'VALID'
+ :S(READ)
OUTPUT = 'INVALID'
+ :(READ)
END