struscan.rig 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #STRUSCAN
  2. -- Structured scaner is very useful if your input is not from
  3. -- a textual representation but from some code generated by
  4. -- another program, that can output both text and special characters.
  5. -- You can create any RIGAL data simply by reading such code.
  6. -- You can also create such code from RIGAL.
  7. -- The special characters have code chr(21) .. chr(25).
  8. -- Reads "strusca1.inp" and prints it.
  9. -- Note chr(21) and chr(22) there
  10. -- Reads "strusca2.inp" and prints it.
  11. -- Note chr(21) ... chr(25) there
  12. $T:=#CALL_PAS(35 'strusca1.inp');
  13. PRINT $T;
  14. $T:=#CALL_PAS(35 'strusca2.inp');
  15. PRINT $T;
  16. OPEN S 'strusca3.out';
  17. #emit_spec($T);
  18. CLOSE S;
  19. $K:=#CALL_PAS(35 'strusca3.out');
  20. PRINT $K;
  21. -- Not all text editors support editing of files with
  22. -- special characters. Usually it is posible to enter
  23. -- them (in PC) by holding the ALT-key and entering,e.g., 0 2 1
  24. -- in right, numeric keyboard.
  25. ##
  26. #emit_spec
  27. -- This rule creates code that can be read again by
  28. -- the structured scaner.
  29. NULL / S <] #CHR(21) #CHR(22) / ;; --
  30. $LABEL::(.
  31. / IF $LABEL -> S<] #CHR(25); #emit_spec($LABEL); FI;
  32. S<] #CHR(21)/
  33. (* #emit_spec *)
  34. .) / S <] #CHR(22);S<<; /
  35. ;;
  36. $LABEL :: <* $SEL :
  37. / IF $LABEL -> S<] #CHR(25); #emit_spec($LABEL);$LABEL:=NULL; FI;
  38. IF NOT $START-> S<] #CHR(23);$START:=T; FI;
  39. #emit_spec($SEL)
  40. / #emit_spec
  41. *>
  42. / S<] #CHR(24);S<< /
  43. ;;
  44. $ATOM / S <] ' ' $ATOM ' ' /
  45. ##