home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / TESTS / LF / GRAMMARS.LF < prev    next >
Text File  |  1996-06-04  |  1KB  |  49 lines

  1. %
  2. % Translating grammars into LIFE
  3. %
  4. %
  5. % The syntax of the rules is the following:
  6. % Head --> List of Symbols # List of clauses ?
  7. %
  8. % The list of clauses can be used as a list of constraints on attributes of
  9. % the non-terminals.  The symbols are any psi terms with no feature named
  10. % "words": This feature is used to translate a non-terminal into a predicate.
  11. % See the files *.gr for examples of grammars, and the corresponding *.in for
  12. % examples of queries.
  13. %
  14.  
  15. op(999,xfy,-->)?
  16. op(995,xfy,#)?
  17. op(990,xfy,,)?
  18. op(500,xfy,\\)?
  19.  
  20. non_strict(-->)?
  21. non_strict(#)?
  22.  
  23. (Lhs --> Rhs) :- R=transregle(Lhs,Rhs), assert(R).
  24.  
  25. %
  26. % transregle: translates the grammar rules into clauses
  27. %
  28. transregle(Lhs, Rhs # Chs )
  29.                         -> (trad(Xs\\Ys,Lhs) :- trad(Xs\\Ys,Rhs),Chs ).
  30. transregle(Lhs ,Rhs) -> (trad(Xs\\Ys,Lhs) :- trad(Xs\\Ys,Rhs)).
  31.  
  32. non_strict(transregle)?
  33.  
  34. %
  35. % trad is used to translate a list of symbols of the grammar into a list of
  36. % literals.
  37. %
  38. trad(Xs\\Ys,(Symb,Autres)) -> trad(Xs\\Ys1,Symb),trad(Ys1\\Ys,Autres) |
  39.                              nonvar(Autres) .
  40.  
  41. trad(Xs\\Ys,Term:list) -> succeed | Xs=sequence(Term,Ys).
  42. trad(Xs\\Ys,NonTerm) -> Psi | Psi=NonTerm, Psi.words=(Xs\\Ys).
  43.  
  44. sequence([],Ys)-> Ys.
  45. sequence([T|Ts],Ys)-> [T|sequence(Ts,Ys)].
  46.  
  47.  
  48.  
  49.