mini.hlp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. The MINI translator writing system
  2. ----------------------------------
  3. MINI processes a BNF-like form into a set of LISP functions, one for each
  4. production, operating on a stack and token-stream. They call each other,
  5. and a set of support routines and built-in recognizers. MINI uses a stack;
  6. the user can access sub-trees on the stack, replacing them by other trees
  7. built from these sub-trees. Primitive recognizers their recognized token
  8. on this stack.
  9. ==================== Load mini by doing LOAD MINI; in RLISP.
  10. ==================== The translator is defined by MINI 'rootname;
  11. MINI 'FOO;
  12. FOO: ID '!- ID +(SUB #2 #1) .(PRINT #1) ;
  13. FIN
  14. defines a complete one rule translator, which recognizes two identifiers
  15. separated by a minus sign (each ID pushes the recognized identifier onto
  16. the stack). The +() expression replaces the top 2 elements on the stack
  17. (#2 pops the first ID pushed onto the stack, while #1 pops the other) with
  18. a LISP statement. The .() expression POPs and prints it.
  19. See also <griss.mini> for demo0.MIN to demo3.MIN
  20. ============Run the Grammer by calling INVOKE 'FOO; % i.e. the rootname
  21. ============Built In Recognizers: ID, NUM, STR, ANYTOKEN
  22. ============Brief list of the operators
  23. ' Used to designate a terminal symbol (i.e. 'WHILE, 'DO, '!=)
  24. Identifier Specifies a nonterminal
  25. ( ) Used for grouping (i.e. (FOO BAR) requires rule FOO to parse
  26. followed immediately by BAR)
  27. < > Optional parse, if it fails then continue (i.e. <FOO> tries
  28. to parse FOO)
  29. / Optional rules (i.e. FOO / BAR allows either FOO or BAR to
  30. parse, with FOO tested first)
  31. STMT[ANYTOKEN]* Parse any number of STMT separated by ANYTOKEN,
  32. create a list and push onto the stack (i.e. ID[,]* will parse a
  33. number of IDentifiers separated by commas, like in an argument
  34. list)
  35. ##n Reference the nth stack location (n must be an integer)
  36. #n Pop the nth stack location (n must be an integer)
  37. +(STMT) Push the unevaluated (STMT) onto the stack
  38. .(SEXPR) Evaluate the SEXPR and ignore the result
  39. =(SEXPR) Evaluate the SEXPR and test if result non-NIL
  40. +.(SEXPR) Evaluate the SEXPR and push the result on the stack
  41. @ANYTOKEN Specifies a statement terminator, used in the error
  42. recovery mechanism to search for when an error occurs;
  43. like 'ANYTOKEN, but causes NEXT!-TOK to not scan ahead
  44. so .(NEXT!-TOK) may be needed
  45. @@ANYTOKEN Specifies a grammer terminator, used in the error
  46. recovery mechanism to search for when an error occurs;
  47. like @ANYTOKEN; fatal exit in Error Recovery
  48. $integer Generates a unique label
  49. ================== Pattern MATCHER
  50. In addition to BNF -like rules that define procedures on 0 arguments (which
  51. scan tokens by calls on NEXT!-TOK() and operate on the stack, MINI also
  52. includes a simple TREE pattern matcher and syntax to define
  53. PatternProcedures that accept and return a single argument, trying a series
  54. of patterns until one succeeds.
  55. E.g. template -> replacement
  56. PATTERN = (PLUS2 &1 0) -> 0,
  57. (PLUS2 &1 &1) -> (LIST 'TIMES2 2 &1),
  58. &1 -> &1;
  59. defines a pattern with 3 rules. &n is used to indicate a matched sub-tree
  60. in both the template and replacement. A repeated &n as in the second rule
  61. requires EQUAL sub-trees.