      SUBROUTINE MAIN
      LOGICAL*1 EXP(128,10), PAT(128,10), LIN(400), ARG(128), INFILE(40)
      INTEGER I, GETARG, EXCEPT, ANDPAT, COUNT, ELEVEL, ITOC, GETPAT, MC
     *OUNT, GETLIN, MATCHD, STATUS, GMATCH, INDEX, INT, OPEN
      DATA EXCEPT/0/
      DATA ANDPAT/0/
      DATA COUNT /0/
      DATA ELEVEL/0/
      CALL ADRFIL(INFILE)
      INT = OPEN(INFILE, 1)
      IF(.NOT.(INT .EQ. -3))GOTO 23000
      CALL CANT(INFILE)
23000 CONTINUE
      I=1
23002 IF(.NOT.(GETARG(I, ARG, 128) .NE. -1))GOTO 23004
      IF(.NOT.(ARG(1) .EQ. 63 .AND. ARG(2) .EQ. 0))GOTO 23005
      CALL RESERR
      GOTO 23006
23005 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45))GOTO 23007
      CALL SCOPY(ARG, 1, LIN, 1)
      CALL FOLD(LIN)
      IF(.NOT.(INDEX(LIN, 97) .GT. 0))GOTO 23009
      ANDPAT = 1
23009 CONTINUE
      IF(.NOT.(INDEX(LIN, 99) .GT. 0))GOTO 23011
      COUNT = 1
23011 CONTINUE
      IF(.NOT.(INDEX(LIN, 120) .GT. 0))GOTO 23013
      EXCEPT = 1
23013 CONTINUE
      GOTO 23008
23007 CONTINUE
      IF(.NOT.(ELEVEL .LT. 10))GOTO 23015
      ELEVEL = ELEVEL + 1
      CALL FOLD(ARG)
      CALL SCOPY(ARG, 1, EXP(1, ELEVEL), 1)
      GOTO 23016
23015 CONTINUE
      CALL PUTLIN(43HMaximum number of expressions permitted is , 3)
      STATUS = ITOC(10, ARG, 128)
      CALL ERROR(ARG)
23016 CONTINUE
23008 CONTINUE
23006 CONTINUE
23003 I=I+1
      GOTO 23002
23004 CONTINUE
      IF(.NOT.(ELEVEL .EQ. 0))GOTO 23017
      CALL RESERR
23017 CONTINUE
      I=1
23019 IF(.NOT.(I .LE. ELEVEL))GOTO 23021
      IF(.NOT.(GETPAT(EXP(1,I), PAT(1,I)) .EQ. -3))GOTO 23022
      CALL PUTLIN(17Hillegal pattern: , 3)
      CALL ERROR(EXP(1,I))
23022 CONTINUE
23020 I=I+1
      GOTO 23019
23021 CONTINUE
      MCOUNT = 0
23024 IF(.NOT.(GETLIN(LIN, INT) .NE. -1))GOTO 23025
      MATCHD = GMATCH(LIN, PAT, ELEVEL, ANDPAT)
      IF(.NOT.((MATCHD .EQ. 1 .AND. EXCEPT .EQ. 0) .OR. (MATCHD .EQ. 0 .
     *AND. EXCEPT .EQ. 1)))GOTO 23026
      IF(.NOT.(COUNT .EQ. 1))GOTO 23028
      MCOUNT = MCOUNT + 1
      GOTO 23029
23028 CONTINUE
      CALL PUTLIN(LIN, 2)
23029 CONTINUE
23026 CONTINUE
      GOTO 23024
23025 CONTINUE
      IF(.NOT.(COUNT .EQ. 1))GOTO 23030
      CALL PUTDEC(MCOUNT, 1)
      CALL PUTC(10)
23030 CONTINUE
      RETURN
      END
      SUBROUTINE RESERR
      CALL ERROR(50Husage:  resolve [-acx] expression [expression ...])
      RETURN
      END
