home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l216 / 1.ddi / PARSER.PAR < prev    next >
Encoding:
Text File  |  1987-03-23  |  5.1 KB  |  150 lines

  1. /***********************************************************
  2.  
  3.      Turbo Prolog Toolbox
  4.      (C) Copyright 1987 Borland International.
  5.  
  6.         PARSING PREDICATES
  7. ***********************************************************/
  8.  
  9. PREDICATES
  10.   s_parser(TOKL,TOKL,PARSER)
  11.   s_productions(TOKL,TOKL,PRODUCTIONS)
  12.   s_productions1(TOKL,TOKL,PRODUCTIONS)
  13.   s_prodgroups(TOKL,TOKL,PRODGROUPS)
  14.   s_prodgroups1(TOKL,TOKL,PRODGROUPS)
  15.   s_priorgroup(TOKL,TOKL,PRIORGROUP)
  16.   s_priorgroup1(TOKL,TOKL,PRIORGROUP)
  17.   s_gramtokl(TOKL,TOKL,GRAMTOKL)
  18.   s_prodnames(TOKL,TOKL,PRODNAMES)
  19.   s_prodnames1(TOKL,TOKL,PRODNAMES)
  20.   s_section(TOKL,TOKL,SECTION)
  21.   s_production(TOKL,TOKL,PRODUCTION)
  22.   s_prodbody(TOKL,TOKL,PRODBODY)
  23.   s_star_plus(TOKL,TOKL,STAR_PLUS)
  24.   s_separator(TOKL,TOKL,SEPARATOR)
  25.   s_singprod(TOKL,TOKL,SINGPROD)
  26.   s_assoc(TOKL,TOKL,ASSOC)
  27.   s_gramtok(TOKL,TOKL,GRAMTOK)
  28.   s_cursordemand(TOKL,TOKL,CURSORDEMAND)
  29.   s_tokk(TOKL,TOKL,TOKK)
  30.   s_tokk1(TOKL,TOKL,STRING,CURSOR,TOKK)
  31.   s_term(TOKL,TOKL,TERM)
  32.   s_term1(TOKL,TOKL,STRING,CURSOR,TERM)
  33.   s_prodname(TOKL,TOKL,PRODNAME)
  34.  
  35. CLAUSES
  36.   s_section([t(userdefined_,_)|LL1],LL0,userprods_(PRODNAMES)):-
  37.     expect(t(productions_,_),LL1,LL2),
  38.     s_prodnames(LL2,LL0,PRODNAMES),!.
  39.   s_section([t(userdefined_,_)|LL1],LL0,userdoms_(PRODNAMES)):-!,
  40.     expect(t(domains_,_),LL1,LL2),
  41.     s_prodnames(LL2,LL0,PRODNAMES).
  42.   s_section([t(productions_,_)|LL1],LL0,productions_(PRODUCTIONS)):-!,
  43.     s_productions(LL1,LL0,PRODUCTIONS).
  44.   s_section(LL,_,_):-syntax_error(section,LL),fail.
  45.  
  46.   s_production([t(upper(STRING),CURSOR)|LL1],LL0,p(PRODNAME,CURSOR,PRODBODY)):-!,
  47.     expect(t(equal,_),LL1,LL2),
  48.     s_prodbody(LL2,LL0,PRODBODY),STRING=PRODNAME.
  49.   s_production(LL,_,_):-syntax_error(production,LL),fail.
  50.  
  51.   s_prodbody([t(upper(STRING),CURSOR)|LL1],LL0,list(PRODNAME,CURSOR,STAR_PLUS,SEPARATOR)):-
  52.     s_star_plus(LL1,LL2,STAR_PLUS),
  53.     s_separator(LL2,LL0,SEPARATOR),!,STRING=PRODNAME.
  54.   s_prodbody(LL1,LL0,groups(PRODGROUPS)):-
  55.     s_prodgroups(LL1,LL0,PRODGROUPS),!.
  56.   s_prodbody(LL,_,_):-syntax_error(prodbody,LL),fail.
  57.  
  58.   s_star_plus([t(star,_)|LL],LL,star):-!.
  59.   s_star_plus([t(plus,_)|LL],LL,plus):-!.
  60.   s_star_plus(LL,_,_):-syntax_error(star_plus,LL),fail.
  61.  
  62.   s_separator([t(separator_,_)|LL1],LL0,sep(STRING)):-
  63.     expect(t(id(STRING),_),LL1,LL0),!.
  64.   s_separator(LL,LL,none):-!.
  65.  
  66.   s_singprod(LL1,LL0,prod(ASSOC,GRAMTOKL,CURSOR,TERM)):-
  67.     s_assoc(LL1,LL2,ASSOC),
  68.     s_gramtokl(LL2,LL3,GRAMTOKL),
  69.     expect(t(arrow,CURSOR),LL3,LL4),
  70.     s_term(LL4,LL0,TERM),!.
  71.  
  72.   s_assoc([t(rightassoc_,CURSOR)|LL],LL,right(CURSOR)):-!.
  73.   s_assoc(LL,LL,left):-!.
  74.  
  75.   s_gramtok([t(upper(STRING),CURSOR)|LL],LL,prodname(PRODNAME,CURSOR)):-!,STRING=PRODNAME.
  76.   s_gramtok(LL1,LL0,tok(TOKK,CURSORDEMAND)):-
  77.     s_tokk(LL1,LL2,TOKK),
  78.     s_cursordemand(LL2,LL0,CURSORDEMAND),!.
  79.   s_gramtok(LL,_,_):-syntax_error(gramtok,LL),fail.
  80.  
  81.   s_cursordemand([t(colon,_)|LL1],LL0,curdemand(PRODNAME)):-
  82.     s_prodname(LL1,LL0,PRODNAME),!.
  83.   s_cursordemand(LL,LL,none):-!.
  84.  
  85.   s_tokk([t(id(STRING),CURSOR)|LL1],LL0,TOKK_):-!,
  86.     s_tokk1(LL1,LL0,STRING,CURSOR,TOKK_).
  87.   s_tokk(LL,_,_):-syntax_error(tokk,LL),fail.
  88.  
  89.   s_term([t(upper(STRING),CURSOR)|LL],LL,dom(PRODNAME,CURSOR)):-!,STRING=PRODNAME.
  90.   s_term([t(id(STRING),CURSOR)|LL1],LL0,TERM_):-!,
  91.     s_term1(LL1,LL0,STRING,CURSOR,TERM_).
  92.   s_term(LL,_,_):-syntax_error(term,LL),fail.
  93.  
  94.   s_prodname([t(upper(STRING),_)|LL],LL,PRODNAME):-!,STRING=PRODNAME.
  95.   s_prodname(LL,_,_):-syntax_error(prodname,LL),fail.
  96.  
  97.   s_tokk1([t(lpar,_)|LL1],LL0,STRING,CURSOR,cmp(STRING,CURSOR,PRODNAMES)):-!,
  98.     s_prodnames(LL1,LL2,PRODNAMES),
  99.     expect(t(rpar,_),LL2,LL0).
  100.   s_tokk1(LL,LL,STRING,CURSOR,name(STRING,CURSOR)):-!.
  101.  
  102.   s_term1([t(lpar,_)|LL1],LL0,STRING,CURSOR,term(STRING,CURSOR,PRODNAMES)):-!,
  103.     s_prodnames(LL1,LL2,PRODNAMES),
  104.     expect(t(rpar,_),LL2,LL0).
  105.   s_term1(LL,LL,STRING,CURSOR,name(STRING,CURSOR)):-!.
  106.  
  107.   s_parser(LL1,LL0,[SECTION|PARSER]):-
  108.     s_section(LL1,LL2,SECTION),!,
  109.     s_parser(LL2,LL0,PARSER).
  110.   s_parser(LL,LL,[]).
  111.  
  112.   s_productions(LL1,LL0,[PRODUCTION|PRODUCTIONS]):-
  113.     s_production(LL1,LL2,PRODUCTION),
  114.     s_productions1(LL2,LL0,PRODUCTIONS).
  115.  
  116.   s_productions1(LL1,LL0,[PRODUCTION|PRODUCTIONS]):-
  117.     s_production(LL1,LL2,PRODUCTION),!,
  118.     s_productions1(LL2,LL0,PRODUCTIONS).
  119.   s_productions1(LL,LL,[]).
  120.  
  121.   s_prodgroups(LL1,LL0,[PRIORGROUP|PRODGROUPS]):-
  122.     s_priorgroup(LL1,LL2,PRIORGROUP),
  123.     s_prodgroups1(LL2,LL0,PRODGROUPS).
  124.  
  125.   s_prodgroups1([t(priorsepp,_)|LL1],LL2,PRODGROUPS):-!,
  126.     s_prodgroups(LL1,LL2,PRODGROUPS).
  127.   s_prodgroups1(LL,LL,[]).
  128.  
  129.   s_priorgroup(LL1,LL0,[SINGPROD|PRIORGROUP]):-
  130.     s_singprod(LL1,LL2,SINGPROD),
  131.     s_priorgroup1(LL2,LL0,PRIORGROUP).
  132.  
  133.   s_priorgroup1([t(comma,_)|LL1],LL2,PRIORGROUP):-!,
  134.     s_priorgroup(LL1,LL2,PRIORGROUP).
  135.   s_priorgroup1(LL,LL,[]).
  136.  
  137.   s_gramtokl(LL1,LL0,[GRAMTOK|GRAMTOKL]):-
  138.     s_gramtok(LL1,LL2,GRAMTOK),!,
  139.     s_gramtokl(LL2,LL0,GRAMTOKL).
  140.   s_gramtokl(LL,LL,[]).
  141.  
  142.   s_prodnames(LL1,LL0,[PRODNAME|PRODNAMES]):-
  143.     s_prodname(LL1,LL2,PRODNAME),
  144.     s_prodnames1(LL2,LL0,PRODNAMES).
  145.  
  146.   s_prodnames1([t(comma,_)|LL1],LL2,PRODNAMES):-!,
  147.     s_prodnames(LL1,LL2,PRODNAMES).
  148.   s_prodnames1(LL,LL,[]).
  149.  
  150.