Personal tools
Document Actions

odra.11 Prolog to prefixed form?

by Paul McJones last modified 2019-05-20 16:52
*PROLOG TO PREFIXED FORM.
*BLANK,COMMA,QUOTE,LEFT AND RIGHT PARENTHESES MUST NOT APPEAR AS TERMS -
 THE STANDARD CHARACTER-RECOGNISING PREDICATES MUST BE USED.
* NO CLAUSE CAN CONTAIN MORE THAN NINE DIFFERENT VARIABLES.
* THE LAST CLAUSE MUST BE +$FIN.

-AJOP(".",1,"X'(X'X)")!
* DRIVING MODULE.
+PREFIX -SUPP(+($FIN).NIL) -/
   - LIGNE -LIGNE
   -SORM("***PREFIX TERMINATED***") -LIGNE -LIGNE.
+PREFIX -INPUT(*CLAUSE) -TRINPUT(*CLAUSE) -PARSE(*CLAUSE,*TREE)
   -TRPARSE(*TREE) -OUTPUT(*TREE) -FAIL.
+PREFIX - PREFIX.
+TRINPUT(*CLAUSE) -TRACEINPUT -LIGNE -SORM("POST INPUT :") -LIGNE
   -SORT(*CLAUSE) -LIGNE -/(-(TRINPUT(*CLAUSE))).
+TRINPUT(*CLAUXE).
+TRPARSE(*TREE) -TRACEPARSE -LIGNE -SORM("POST PARSING :") -LIGNE -SORT(*TREE)
   -LIGNE -/(-(TRPARSE(*TREE))).
+TRPARSE(*TREE).

* READ A CLAUSE,SKIPPING EXTRA  BLANKS,CONVERTING SPECIAL CHARACTERS AND
  YIELDING STRINGS AS ARGUMENTS OF STR.
* LEVEL COUNTS IMMERSION IN PARENTHESES.
+INPUT(*CLAUSE) -NEXTB(*CHAR) -GETCL(*CHAR,*CLAUSE) -/(-(INPUT(*CLAUSE))).

+GETCL(ASTERISK,*CLAUSE) -/ -SKIPCOMMENT -NEXTB(*CH) -GETCL(*CH,*CLAUSE).
+GETCL(PLUS,*CLAUSE) -/ -GCL(PLUS,*CLAUSE,0).
+GETCL(MINUS,*CLAUSE) -/ -GCL(MINUS,*CLAUSE,0).
+GETCL(*CHAR,*CLAUSE) -ERR1(*CHAR,"IS THE FIRST CHARACTER OF A CLAUSE,WHICH WILL
 THEREFORE BE TREATED AS A COMMENT.") -GETCL(ASTERISK,*CLAUSE).

+GCL(PERIOD,CLAUSEND.NIL,0) -/.
+GCL(QUOTE,STR(*STRING).*REST,*LEVEL) -/ -NEXT(*CH)
   -GETSTRING(*CH,*STRING) -NEXTB(*NCH) -GCL(*NCH,*REST,*LEVEL).
+GCL(LPAR,LPAR.*REST,*LEVEL) -/ -PLUS(*LEVEL,1,*LEV)
   -NEXTB(*CH) -GCL(*CH,*REST,*LEV).
+GCL(RPAR,*REST,0) -/ -SKIPRPARS(*NEXTCH) -GCL(*NEXTCH,*REST,0).
+GCL(RPAR,RPAR.*REST,*LEVEL) -/ -MOINS(*LEVEL,1,*LEV) -NEXTB(*CH)
   -GCL(*CH,*REST,*LEV).
+GCL(*CHAR,*CHAR.*REST,*LEVEL) -NEXTB(*CH) -GCL(*CH,*REST,*LEVEL).

+GETSTRING(*CH,*ANS) -GETSTR(*CH,*ANS) -/(-(GETSTRING(*CH,*ANS))).
+GETSTR(QUOTE,NIL).
+GETSTR(*CH,*CH.*REST) -NEXT(*C) -GETSTR(*C,*REST).

+SKIPCOMMENT -SKC -/(-(SKIPCOMMENT)).
+SKC -NEXTB(PERIOD).
+SKC -SKC.

+SKIPRPARS(*CH) -SRP(RPAR,0) -/(-(SKIPRPARS(*CH))).
+SRP(RPAR,*N) -PLUS(*N,1,*M) -NEXTB(*CH) -SRP(*CH,*M).
+SRP(*CH,*N) -ANCETRE(-(SKIPRPARS(*CH)))
   -ERR1(*N," EXTRA RIGHT PARENTHESES WERE SKIPPED").

+NEXT(*CHAR) -LU(*CH) -CONVERT(*CH,*CHAR).
+NEXTB(*CHAR) -LUB(*CH) -CONVERT(*CH,*CHAR).

+CONVERT(*CH,ASTERISK) -ETOILE(*CH) -/.
+CONVERT(*CH,COMMA) -VIRG(*CH) -/.
+CONVERT(*CH,LPAR) -PARG(*CH) -/.
+CONVERT(*CH,RPAR) -PARD(*CH) -/.
+CONVERT(*CH,QUOTE) -GUIL(*CH) -/.
+CONVERT(*CH,PERIOD) -POINT(*CH) -/.
+CONVERT(*CH,BLANK) -BLANC(*CH) -/.
+CONVERT(+,PLUS) -/.
+CONVERT(-,MINUS) -/.
+CONVERT(*CH,*CH).

*   *   *   *   .
* PARSING MODULE - THE OUTPUT IS A STRUCTURE BUILT OF :
   PRED(NAME,N-ARITY,ARGUMENT LIST)
   VAR(A VARIABLE'S NUMBER)
   STR(STRING) AS FROM INPUT.
* PERIODS ARE ADDED TO CONNECT THE LITERALS.
*A CLAUSE ENDS WITH CLAUSEND, AN ARGUMENT LIST WITH ARGEND.
+PARSE(*CLAUSE,*TREE) -SYNTAXE(CLAUSE(*TREE).NIL,*CLAUSE)
   -/(-(PARSE(*CLAUSE,*TREE))).

%CLAUSE(PRED(PERIOD.NILL,2,*A.*B.ARGEND)) == %HEADLIT(*A) %LITLIST(*B).

%LITLIST(CLAUSEND) == #CLAUSEND -/.
%LITLIST(PRED(PERIOD.NILL,2,*A.*B.ARGEND)) == %LIT(*A) %LITLIST(*B).

%HEADLIT(PRED(PLUS.NILL,1,*P.ARGEND)) == #PLUS%LPREDNV(*P) -/.
%HEADLIT(PRED(MINUS.NILL,1,*P.ARGEND)) == #PLUS %LPREDNV(*P) -/.
%HEADLIT(*A) == -ERR("CLAUSE WITH VARIABLE HEAD IS PARSED BUT WON'T WORK")
           %LIT(*A).

%LIT(PRED(MINUS.NILL,1,*P.ARGEND)) == #MINUS -/ %LPRED(*P).
%LIT(PRED(PLUS.NILL,1,*P.ARGEND)) == #PLUS -/ %LPRED(*P).
%LIT(PRED(MINUS.NILL,1,*P.ARGEND)) ==
   -ERR("THERE IS NO SIGN IN FRONT OF A LITERAL - MINUS IS INSERTED")
    %LPRED(*P).

%LPRED(VAR(*N)) == #ASTERISK -/ %LVAR(*N).
%LPRED(*P) == %LPREDNV(*P).

%PRED(VAR(*N)) == #ASTERISK -/ %VAR(*N).
%PRED(*P) == %PREDNV(*P).

%LVAR(*N) == %NUMBER(*NAME) -NUMBVAR(*NAME,*N) -/.
%LVAR(*N) == %LIDENT(*NAME) -NUMBVAR(*NAME,*N) -/.

%VAR(*N) == %NUMBER(*NAME) -NUMBVAR(*NAME,*N) -/.
%VAR(*N) == %IDENT(*NAME) -NUMBVAR(*NAME,*N) -/.

%NUMBER(*C.*R) == #*C -CHIFFRE(*C) %NUMB(*R).
%NUMB(*C.*R) == #*C -CHIFFRE(*C) -/ %NUMB(*R).
%NUMB(NIL) == .

%LPREDNV(PRED(*NAME,*N,*ARGS)) == %LIDENT(*NAME) %ARGUMENTS(*N,*ARGS).
%PREDNV(PRED(*NAME,*N,*ARGS)) == %IDENT(*NAME) %ARGUMENTS(*N,*ARGS).

%ARGUMENTS(*N,*A.*R) == #LPAR %ARG(*A) %ARGLIST(1,*R,*N) #RPAR -/.
%ARGUMENTS(*N,*A.*R) == #LPAR %ARG(*A) %ARGLIST(1,*R,*N) -/
   -ERR("AN ARGUMENT LIST DOES NOT END WITH A RIGHT PARENTHESIS.THE PARENTHESIS
 WAS INSERTED") -/.
%ARGUMENTS(0,ARGEND) ==.

%ARGLIST(*M,*A.*R,*N) == #COMMA -/ -PLUS(*M,1,*MN) %ARG(*A) %ARGLIST(*MN,*R,*N).
%ARGLIST(*M,ARGEND,*M) ==.
%ARG(STR(*A)) == #STR(*A) -/.
%ARG(*P) == %PRED(*P).


%LIDENT (*CH.*REST) == #*C -LNORMAL(*C) -/ -CHECK(*C,*CH) %LIDENT(*REST).
%LIDENT(NILL) == .

%IDENT(*CH.*REST) == #*C -NORMAL(*C) -/ -CHECK(*C,*CH) %IDENT(*REST).
%IDENT(NILL) == .
+LNORMAL(MINUS) -/ -FAIL.
+LNORMAL(PLUS) -/ -FAIL.
+LNORMAL(*CH) -NORMAL(*CH).


+NORMAL(LPAR) -/ -FAIL.
+NORMAL(RPAR) -/ -FAIL.
+NORMAL(COMMA) -/ -FAIL.
+NORMAL(ASTERISK) -/ -FAIL.
+NORMAL(CLAUSEND) -/ -FAIL.
+NORMAL(NIL) -/ -FAIL.
+NORMAL(*X).

+CHECK(*C,*CH) -CHIFFRE(*C) -LIGNE
  -SORM("DIGITS NOT ALLOWED IN PREFIXED PROLOG TERMS :")
   -ECRIT(*C) -SORM(" IS CHANGED TO ") -CD(*C,*CH) -SORT(*CH) -LIGNE
    -/(-(CHECK(*C,*CH))).
+CHECK(*C,*C).
+CD(0,A). +CD(1,B). +CD(2,C). +CD(3,D). +CD(4,E). +CD(5,F).
+CD(6,G). +CD(7,H). +CD(8,I). +CD(9,J).
* NUMBVAR : FIND NUMBER OF VARIABLE,IF NOT THERE ADD A NEW ONE.
* +VARIABLE(RESERVEDVARIABLENAME,0) IS ALWAYS THERE.
+VARIABLE(RESERVEDVARIABLENAME,0).

+NUMBVAR(*NAME,*NUMBER) -VARIABLE(*NAME,*NUMBER) -/.
+NUMBVAR(*NAME,*NUMBER) -VARIABLE(*X,*LAST) -PLUS(*LAST,1,*NUMBER)
   -AJOUT(+(VARIABLE(*NAME,*NUMBER)).-(/).NIL).

*   *   *   *   *   .
*SYNTHESIS OF PREFIXED FORM^  A LIST OF PREDICATES IS MAINTAINED.
+OUTPUT(PRED(PERIOD.NILL,2,PRED(PLUS.NILL,1,PRED($.F.I.N.NILL,0,ARGEND).
           ARGEND).CLAUSEND.ARGEND)
                                                                            ) -/
   -LIGNE -ECRIT(#) -LIGNE
   -AJOUT(+($FIN).NIL) -OUTPREDS.
+OUTPUT(*TREE) -SYNTAXE(PREF(*TREE).NIL,*PREFIXED)
  -/(-(OUTPUT(*TREE)))
   -VARIABLES -WRITE(*PREFIXED) -LIGNE.

%PREF(CLAUSEND) == %ANIL -/.
%PREF(*A.*B) == %PREF(*A) -/ %PREF(*B).
%PREF(PRED(*NAME,*N,*ARGS)) == %OUTID(*NAME) #*N -/
   -ARGCHECK(*NAME,*N)
     -ADDPRED(*NAME,*N) %ARGS(*ARGS).
%PREF(VAR(*NUMBER)) == #*NUMBER -/.
%PREF(STR(*X)) == %OUTSTR(*X).

%ARGS(ARGEND) == -/.
%ARGS(*A.*B) == %PREF(*A) %ARGS(*B).

%OUTSTR(NIL) == %ANIL -/.
%OUTSTR(*A.*B) == #PERIOD #2 #*A #0 %OUTSTR(*B).

%ANIL == #N #I #L #0.

%OUTID(NILL) == .
%OUTID(*C.*R) == #*C -/ %OUTID(*R).

+WRITE(NIL) -/.
+WRITE(*CH.*REST) -CONVERT(*C,*CH) -SORT(*C) -WRITE(*REST).

+VARIABLES -VARIABLE(*X,*N) -VARCHECK(*N) -SORT(*N) -REMOVE -FAIL.
+VARIABLES.

+REMOVE -SUPP(+(VARIABLE(*X,*N)).-(/).NIL) -/ -REMOVE.
+REMOVE. *RESERVEDVARIABLENAME IS SAVED,AS IT IS SLASHLESS.

+ADDPRED(*NAME,*N) -MKATOM(*NAME,*ATOM)
   -AP(*ATOM,*N) -/(-(ADDPRED(*NAME,*N))).
+ADDPRED(*ONE,*CHAR).
+AP(*ATOM,*N) -PREDICATE(*ATOM,*N).
+AP(*ATOM,*N) -AJOUT(+(PREDICATE(*ATOM,*N)).-(/).NIL).

+MKATOM(*NAME,*ATOM) -MKSTR(*NAME,*STR)
   -/ -CHECKCHAR(*STR)
   -UNIV(*ATOM,*STR.NIL).

+MKSTR(*A.*B,*C.*D) -CONVERT(*C,*A) -MKSTR(*B,*D).
+MKSTR(NILL,NIL).
+MKSTR(*X,?.NIL) -ERR1(*X," - BAD PREDICATE NAME").

+CHECKCHAR(*C.NIL) -/ -FAIL.
+CHECKCHAR(*OK).

+OUTPREDS -SUPP(+(PREDICATE(*NAME,*N)).-(/).NIL)
   -/ -SORT(*NAME) -SORT(*N) -OUTPREDS.
+OUTPREDS -SORT(#).

+WRNAME(*X) -ERR1(*X," - PREDICATE NAME BADLY FORMED").

+PREDICATE(STANDARD,PREDICATES).
+PREDICATE(*X,2) -POINT(*X).
+PREDICATE(-,1).
+PREDICATE(+,1).
+PREDICATE(NIL,0).
+PREDICATE(/,0).
+PREDICATE(/,1).
+PREDICATE(LU,1).
+PREDICATE(LUB,1).
+PREDICATE(UNIV,2).
+PREDICATE(AJOUT,1).
+PREDICATE(AJOUTB,1).
+PREDICATE(AJOUTC,0).
+PREDICATE(SUPP,1).
+PREDICATE(PLUS,3).
+PREDICATE(MOINS,3).
+PREDICATE(MULT,3).
+PREDICATE(RESTE,3).
+PREDICATE(DIV,3).
+PREDICATE(LETTRE,1).
+PREDICATE(CHIFFRE,1).
+PREDICATE(SAUVE,0).
+PREDICATE(LIGNE,0).
+PREDICATE(INF,2).
+PREDICATE(ANCETRE,1).
+PREDICATE(ATOME,2).
+PREDICATE(VAR,1).
+PREDICATE(BOOLISTE,0).
+PREDICATE(IMPRIME,0).
+PREDICATE(TTY,0).
+PREDICATE(HEURETAT,0).
+PREDICATE(IMPRHET,0).
+PREDICATE(NIVEAU,0).
+PREDICATE(TRACERES,0).
+PREDICATE(TRACEIMP,0).
+PREDICATE(IMPRRES,0).
+PREDICATE(IMPRANC,0).

+NOTEQUAL(*X,*X) -/ -FAIL.
+NOTEQUAL(*X,*Y).

+VARCHECK(*N) -INF(9,*N) -ERR1(*N," - TOO MANY VARIABLES.PREFIXED FORM IS IMPROP
ER") -LIGNE -FAIL.
+VARCHECK(*N).

+ARGCHECK(*NAME,*N) -INF(9,*N) -ERROR -SORM("PREDICATE ") -PISZP(*NAME)
   -SORM(" HAS ") -SORT(*N) -SORM(" ARGUMENTS.PREFIXED FORM IS IMPROPER.")
   -LIGNE -FAIL.
+ARGCHECK(*NAME,*N).

+PISZP(*A.*B) -CONVERT(*C,*A) -SORT(*C) -PISZP(*B).
+PISZP(NILL) -/.

+ERR(*S) -ERROR -SORM(*S) -LIGNE.
+ERR1(*X,*S) -ERROR -SORT(*X) -SORM("  ") -SORM(*S) -LIGNE.
+ERROR -LIGNE -SORM("* * * ERROR :   * * * ") -LIGNE.

-SOP!

-IMPRHET -PREFIX -IMPRHET!
*PREFIXED PROLOG TO NORMAL NOTATION - CLAUSE ORDER IS NOT CHANGED .
+PARENTH -FIND(#) -FIND(#) -IMPAS.
+PARENTH -PAR -LIGNE.
+FIND(*X) -LUB(*X) -/.
+FIND(*X) -FIND(*X).
+PAR -FIND(.) -CLAUSE(.,*NEXT) -NOMORE(*NEXT).
+PAR -PAR.
+NOMORE(#) -/(-(PAR)) -LIGNE.
* CLAUSE'S NEXT IS FIRST NON-BLANK AFTER LAST NIL0  .
+CLAUSE(.,*NEXT) -LU(2)
   -/ -LU(*X) -LITER(*X) -LU(*N) -CLAUSE(*N,*NEXT).
+CLAUSE(N,*NEXT) -LU(I)-LU(L)-LU(0)-ECRIT(.) -LIGNE -LUB(*NEXT) -/.
+CLAUSE(*A,*B) -SORM("ERROR FOUND BY CLAUSE ")
   -SORT(*A) -SORM(" & ") -SORT(*B) -STOP.
+LITER(-) -/ -LIT(-).
+LITER(+) -/ -LIT(+).
+LITER(*X) -SORM("ERROR FOUND BY LITERAL ") -ECRIT(*X) -STOP.
+LIT(*C) -ECRIT(*C) -LU(1) -/ -LU(*F) -PRED(*F).
+LIT(*C) -SORM("BAD N-ARITY OF ") -ECRIT(*C) -STOP.
* PRED IS GIVEN FIRST CHAR,STOPS ON LAST ARG'S LAST.
+PRED(*F) -CHIFFRE(*F) -/ -SORM("*") -ECRIT(*F).
+PRED(*F) -NAME(*F,*N) -ARGS(*N).
* NAME'S SECOND ARG IS N-ARITY .
+NAME(*C,*C) -CHIFFRE(*C) -/.
+NAME(*C,*N) -ECRIT(*C) -LU(*CH) -NAME(*CH,*N).
+ARGS(0) -/.
+ARGS(*N) -SORM("(") -ARG(*N) -SORM(")").
+ARG(*N) -LU(*C) -PRED(*C) -COMMA(*N).
+ARG(*N) -MOINS(*N,1,*M) -ARG(*M).
+COMMA(1) -/(-(ARG(*N))).
+COMMA(*N) -SORM(",") -IMPAS.
* END OF PARANT.
+$FIN.

+TRACEINPUT .
+TRACEPARSE.
-IMPRHET -PREFIX -IMPRHET!
+A(*1,*2,*3,*4,*5,*6,*7,*8,*9,*10,*11).  *DIAGNOSTICS ? .
+E(X(T(R)),A) -B(R(A),C,K(E),T))))).
+*HEAD -AJOUT(.(+(*HEAD),NIL)) -SORT(*HEAD).
IS-THIS-A-CLAUSE-?.
-AND THIS ?.
+A.
+$FIN.
-TTY!

« November 2020 »
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: