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

  1. %
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %
  4. %
  5. %                         UTILITIES FOR SUPERLINT
  6. %                         -----------------------
  7. %
  8. %  
  9. %
  10. %
  11. %  AUTHOR : Arnaud Venet                     CREATION : September 7th 1993
  12. %  ------                                    --------
  13. %
  14. %
  15. %                             ---------------                        
  16. %
  17. %                    
  18. %                   Last modification : February 19th 1994
  19. %
  20. %
  21. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  22. %
  23. %  (C) Digital Equipment Corporation 1993 - 1994
  24. %
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26. %
  27.  
  28.  
  29.  
  30. module("sl_utils") ?
  31.  
  32.  
  33. public(is_list_member,
  34.        scan_tree,
  35.        error_msg, 
  36.        '*superlint_rules*', 
  37.        '*rule_name*',
  38.        display_rules, yes, no,
  39.        is_token, is_not_token,
  40.        is_operator, 
  41.        is_assignment_operator, 
  42.        is_logical_operator,
  43.        is_arithmetic_operator, 
  44.        is_relation_operator, 
  45.        is_conditional_operator,
  46.        is_unary_operator, 
  47.        is_struct_reference,
  48.        is_assignment,
  49.        features_list,
  50.        newlist,
  51.        writeln,
  52.        expand_type,
  53.        parse_tree,
  54.        basename,
  55.        file_extension,
  56.        current_declaration,
  57.        current_block,
  58.        current_instruction,
  59.        parse_mode,
  60.        string2id) ?
  61.  
  62.  
  63. %
  64. % ------------------------------------------------------------------------------
  65. %
  66.  
  67.  
  68. persistent('*superlint_rules*') ?
  69.  
  70.  
  71. persistent('*display_rules*') ?
  72.  
  73.  
  74. persistent('*rule_name*') ?
  75.  
  76.  
  77. persistent(the_current_declaration) ?
  78.  
  79.  
  80. persistent(the_current_block) ?
  81.  
  82.  
  83. persistent(the_current_instruction) ?
  84.  
  85.  
  86. persistent(parse_mode) ?
  87.  
  88.  
  89. '*display_rules*' <<- yes ?
  90.  
  91.  
  92. %
  93. % ------------------------------------------------------------------------------
  94. %
  95.  
  96.  
  97. load("c_public_terms") ?
  98.  
  99.  
  100. open("c_public_terms") ?
  101.  
  102.  
  103. load("sl_public_terms") ?
  104.  
  105.  
  106. open("sl_public_terms") ?
  107.  
  108.  
  109. load("sl_overload") ?
  110.  
  111.  
  112. load("sl_io_utils") ?
  113.  
  114.  
  115. load("expand_type") ?
  116.  
  117.  
  118. %
  119. % ------------------------------------------------------------------------------
  120. %
  121.  
  122.  
  123. the_current_declaration <<- ref(nothing) ?
  124.  
  125.  
  126. the_current_block <<- ref(nothing) ?
  127.  
  128.  
  129. the_current_instruction <<- ref(nothing) ?
  130.  
  131.  
  132. current_declaration -> the_current_declaration.1.
  133.  
  134.  
  135. current_block -> the_current_block.1.
  136.  
  137.  
  138. current_instruction -> the_current_instruction.1.
  139.  
  140.  
  141. parse_mode <<- prefix ?
  142.  
  143.  
  144. %
  145. % ------------------------------------------------------------------------------
  146. %
  147.  
  148.  
  149. is_list_member(X, Y) :-
  150.   (
  151.     Y = ["common"],
  152.     !
  153.   ;
  154.     member(X, Y),
  155.     !
  156.   ).
  157.  
  158.  
  159. %
  160. % ------------------------------------------------------------------------------
  161. %
  162.  
  163.  
  164. scan_tree(Domain, Rules) :-
  165.   cond(Domain :== @,
  166.     TheDomain = ["common"],
  167.     TheDomain = transform_domain(Domain)
  168.   ),
  169.   cond(Rules :== @,
  170.     TheRules = '*superlint_rules*',
  171.     TheRules = map(psi2str, Rules)
  172.   ),
  173.   V <<- verify_rules,
  174.   V'syntax#.'1 <<- @,
  175.   V'syntax#.'2 <<- TheRules,
  176.   V'syntax#.'3 <<- TheDomain,
  177.   parse_tree(V, syntactic_tree).
  178.  
  179.  
  180. %
  181. % ------------------------------------------------------------------------------
  182. %
  183.  
  184.  
  185. non_strict(transform_domain) ?
  186.  
  187.  
  188. transform_domain((A, B)) -> [psi2str(A) | transform_domain(B)].
  189.  
  190.  
  191. transform_domain(A) -> [psi2str(A)].
  192.  
  193.  
  194. %
  195. % ------------------------------------------------------------------------------
  196. %
  197.  
  198.  
  199. string2id(String:string) -> str2psi(String).
  200.  
  201.  
  202. %
  203. % ------------------------------------------------------------------------------
  204. %
  205.  
  206.  
  207. assignment_operator -> {"="; "*="; "/="; "+="; "-="; "<<="; ">>="; "&="; 
  208.                         "^="; "|="}.
  209.  
  210.  
  211. conditional_operator -> '?'.
  212.  
  213.  
  214. logical_operator -> {"||"; "&&"}.
  215.  
  216.  
  217. arithmetic_operator -> {"|"; "^"; "&"; "<<"; ">>"; "+"; "-"; 
  218.                         "*"; "/"; "%"}.
  219.  
  220.  
  221. relation_operator -> {"=="; "!="; "<"; ">"; ">="; "<="}.
  222.  
  223.  
  224. unary_operator -> {"&"; "*"; "+"; "-"; "~"; "!"; "++"; "--"}.
  225.  
  226.  
  227. struct_reference -> {"."; "->"}.
  228.  
  229.  
  230. %
  231. % ------------------------------------------------------------------------------
  232. %
  233.  
  234.  
  235. is_operator(What) :-
  236.   (
  237.     What :== assignment_operator,
  238.     !
  239.   ;
  240.     What :== conditional_operator,
  241.     !
  242.   ;
  243.     What :== logical_operator,
  244.     !
  245.   ;
  246.     What :== arithmetic_operator,
  247.     !
  248.   ;
  249.     What :== relation_operator,
  250.     !
  251.   ;
  252.     What :== unary_operator,
  253.     !
  254.   ;
  255.     What :== struct_reference,
  256.     !
  257.   ).
  258.  
  259.  
  260. %
  261. % ------------------------------------------------------------------------------
  262. %
  263.  
  264.  
  265. is_assignment_operator(What) :-
  266.   What :== assignment_operator,
  267.   !.
  268.  
  269.  
  270. %
  271. % ------------------------------------------------------------------------------
  272. %
  273.  
  274.  
  275. is_assignment(What) :-
  276.   What :\>< string,
  277.   psi2str(What) :== assignment_operator,
  278.   !.
  279.  
  280.  
  281. %
  282. % ------------------------------------------------------------------------------
  283. %
  284.  
  285.  
  286. features_list(What) ->
  287.   map(psi2str, features(What)).
  288.  
  289.  
  290. %
  291. % ------------------------------------------------------------------------------
  292. %
  293.  
  294.  
  295. is_arithmetic_operator(What) :-
  296.   What :== arithmetic_operator,
  297.   !.
  298.  
  299.  
  300. %
  301. % ------------------------------------------------------------------------------
  302. %
  303.  
  304.  
  305. is_relation_operator(What) :-
  306.   What :== relation_operator,
  307.   !.
  308.  
  309.  
  310. %
  311. % ------------------------------------------------------------------------------
  312. %
  313.  
  314.  
  315. is_logical_operator(What) :-
  316.   What :== logical_operator,
  317.   !.
  318.  
  319.  
  320. %
  321. % ------------------------------------------------------------------------------
  322. %
  323.  
  324.  
  325. is_conditional_operator(What) :-
  326.   What :== conditional_operator,
  327.   !.
  328.  
  329.  
  330. %
  331. % ------------------------------------------------------------------------------
  332. %
  333.  
  334.  
  335. is_unary_operator(What) :-
  336.   What :== unary_operator,
  337.   !.
  338.  
  339.  
  340. %
  341. % ------------------------------------------------------------------------------
  342. %
  343.  
  344.  
  345. is_struct_reference(What) :-
  346.   What :== struct_reference,
  347.   !.
  348.  
  349.  
  350. %
  351. % ------------------------------------------------------------------------------
  352. %
  353.  
  354.  
  355. display_rules(Choice) :-
  356.   '*display_rules*' <<- Choice.
  357.  
  358.  
  359. %
  360. % ------------------------------------------------------------------------------
  361. %
  362.  
  363.  
  364. basename(Name) -> string_of(base_name_of(str2list(Name))).
  365.  
  366.  
  367. base_name_of([]) -> [].
  368.  
  369. base_name_of([47 | L]) -> BaseName  % 47 = asc("/")
  370.   | BaseNameList = zap2slash(L),
  371.     cond(BaseNameList :== [],
  372.       BaseName = L,
  373.       BaseName = base_name_of(BaseNameList)
  374.     ).
  375.  
  376. base_name_of(L) -> BaseName
  377.   | BaseNameList = zap2slash(L),
  378.     cond(BaseNameList :== [],
  379.       BaseName = L,
  380.       BaseName = base_name_of(BaseNameList)
  381.     ).
  382.  
  383.  
  384. zap2slash([]) -> [].
  385.  
  386. zap2slash(L:[47 | @]) -> L.
  387.  
  388. zap2slash([@ | L]) -> zap2slash(L).
  389.  
  390.  
  391. %
  392. % ------------------------------------------------------------------------------
  393. %
  394.  
  395.  
  396. file_extension(String) -> Extension
  397.   | BaseName = basename(String),
  398.     Pos = find_last_dot(str2list(BaseName), 0, 1),
  399.     cond(Pos :== 0,
  400.       Extension = "",
  401.       Extension = substr(BaseName, Pos + 1, strlen(BaseName) - Pos)
  402.     ).
  403.  
  404.  
  405. find_last_dot([], PreviousPos, CurrentPos) -> PreviousPos.
  406.  
  407. find_last_dot([46 | L], PreviousPos, CurrentPos) -> %%% 46 = asc(".")
  408.   find_last_dot(L, CurrentPos, CurrentPos + 1).
  409.  
  410. find_last_dot([@ | L], PreviousPos, CurrentPos) ->
  411.   find_last_dot(L, PreviousPos, CurrentPos + 1).
  412.  
  413. %
  414. % ------------------------------------------------------------------------------
  415. %
  416.  
  417.  
  418. newlist(H, T) -> [H | T].
  419.  
  420.  
  421. %
  422. % ------------------------------------------------------------------------------
  423. %
  424.  
  425.  
  426. W : writeln :-
  427.   strip(W) & write,
  428.   nl.
  429.  
  430.  
  431. %
  432. % ------------------------------------------------------------------------------
  433. %
  434.  
  435.  
  436. parse_the_tree(Operation, What) :-
  437.   (
  438.     parse_tree(Operation, What),
  439.     fail
  440.   ;
  441.     succeed
  442.   ).
  443.  
  444.  
  445. %
  446. % ------------------------------------------------------------------------------
  447. %
  448.  
  449.  
  450. parse_tree(Operation, nothing) :- !.
  451.  
  452.  
  453. parse_tree(Operation, What) :-
  454.   What :== {toplevel; block_declarations},
  455.   !,
  456.   parse_mode <<- prefix,
  457.   Operation.1 <<- ref(What), Operation,
  458.   parse_the_tree(Operation, What.first_declaration),
  459.   parse_mode <<- postfix,
  460.   Operation.1 <<- ref(What), Operation.
  461.  
  462.  
  463. parse_tree(Operation, What) :-
  464.   What :== {external_declaration; local_declaration},
  465.   !,
  466.   the_current_declaration <<- ref(What),
  467.   parse_mode <<- prefix,
  468.   Operation.1 <<- ref(What), Operation,
  469.   parse_the_tree(Operation, What.type),
  470.   parse_the_tree(Operation, What.name),
  471.   parse_the_tree(Operation, What.initialization),
  472.   parse_the_tree(Operation, What.separator),
  473.   the_current_declaration <<- ref(nothing),
  474.   parse_mode <<- postfix,
  475.   Operation.1 <<- ref(What), Operation,
  476.   parse_the_tree(Operation, What.next).
  477.  
  478.  
  479. parse_tree(Operation, What) :-
  480.   What :== type_definition,
  481.   !,
  482.   parse_mode <<- prefix,
  483.   Operation.1 <<- ref(What), Operation,
  484.   parse_the_tree(Operation, What.keyword),
  485.   parse_the_tree(Operation, What.type),
  486.   parse_the_tree(Operation, What.name),
  487.   parse_the_tree(Operation, What.separator),
  488.   parse_mode <<- postfix,
  489.   Operation.1 <<- ref(What), Operation,
  490.   parse_the_tree(Operation, What.next).
  491.  
  492.  
  493. parse_tree(Operation, What) :-
  494.   What :== {struct_declaration; union_declaration;
  495.             enum_declaration},
  496.   !,
  497.   parse_mode <<- prefix,
  498.   Operation.1 <<- ref(What), Operation,
  499.   parse_the_tree(Operation, What.keyword),
  500.   parse_the_tree(Operation, What.name),
  501.   parse_the_tree(Operation, What.semi_colon),
  502.   parse_mode <<- postfix,
  503.   Operation.1 <<- ref(What), Operation,
  504.   parse_the_tree(Operation, What.next).
  505.  
  506.  
  507. parse_tree(Operation, What) :-
  508.   What :== {struct_definition; union_definition; enum_definition},
  509.   !,
  510.   parse_mode <<- prefix,
  511.   Operation.1 <<- ref(What), Operation,
  512.   parse_the_tree(Operation, What.keyword),
  513.   parse_the_tree(Operation, What.name),
  514.   parse_the_tree(Operation, What.body),
  515.   parse_mode <<- postfix,
  516.   Operation.1 <<- ref(What), Operation,
  517.   parse_the_tree(Operation, What.next).
  518.  
  519.  
  520. parse_tree(Operation, What) :-
  521.   What :== {struct; union; enum},
  522.   has_feature(keyword, What),
  523.   !,
  524.   parse_mode <<- prefix,
  525.   Operation.1 <<- ref(What), Operation,
  526.   (
  527.     is_token(What),
  528.     !,
  529.     succeed
  530.   ;    
  531.     parse_the_tree(Operation, What.keyword),
  532.     parse_the_tree(Operation, What.body),
  533.     parse_mode <<- postfix,
  534.     Operation.1 <<- ref(What), Operation
  535.   ).
  536.  
  537.  
  538. parse_tree(Operation, What) :-
  539.   What :== {struct_body; union_body},
  540.   !,
  541.   parse_mode <<- prefix,
  542.   Operation.1 <<- ref(What), Operation,
  543.   parse_the_tree(Operation, What.left_brace),
  544.   parse_the_tree(Operation, What.fields),
  545.   parse_the_tree(Operation, What.right_brace),
  546.   parse_mode <<- postfix,
  547.   Operation.1 <<- ref(What), Operation.
  548.  
  549.  
  550. parse_tree(Operation, What) :-
  551.   What :== enum_body,
  552.   !,
  553.   parse_mode <<- prefix,
  554.   Operation.1 <<- ref(What), Operation,
  555.   parse_the_tree(Operation, What.left_brace),
  556.   parse_the_tree(Operation, What.enumerators),
  557.   parse_the_tree(Operation, What.right_brace),
  558.   parse_mode <<- postfix,
  559.   Operation.1 <<- ref(What), Operation.
  560.  
  561.  
  562. parse_tree(Operation, What) :-
  563.   What :== {fields; enumerators},
  564.   !,
  565.   parse_mode <<- prefix,
  566.   Operation.1 <<- ref(What), Operation,
  567.   parse_the_tree(Operation, What.first_member),
  568.   parse_mode <<- postfix,
  569.   Operation.1 <<- ref(What), Operation.
  570.  
  571.  
  572. parse_tree(Operation, What) :-
  573.   What :== {field; enumerator},
  574.   !,
  575.   parse_mode <<- prefix,
  576.   Operation.1 <<- ref(What), Operation,
  577.   cond(What :== field,
  578.     parse_the_tree(Operation, What.type)
  579.   ),
  580.   parse_the_tree(Operation, What.name),
  581.   (
  582.     has_feature(initialization, What, Initialization),
  583.     !,
  584.     parse_the_tree(Operation, Initialization)
  585.   ;
  586.     succeed
  587.   ),
  588.   parse_the_tree(Operation, What.separator),
  589.   parse_mode <<- postfix,
  590.   Operation.1 <<- ref(What), Operation,
  591.   parse_the_tree(Operation, What.next).
  592.  
  593.  
  594. parse_tree(Operation, What) :-
  595.   What :== protected_type,
  596.   !,
  597.   parse_mode <<- prefix,
  598.   Operation.1 <<- ref(What), Operation,
  599.   parse_the_tree(Operation, What.left_parenthesis),
  600.   parse_the_tree(Operation, What.type),
  601.   parse_the_tree(Operation, What.right_parenthesis),
  602.   parse_mode <<- postfix,
  603.   Operation.1 <<- ref(What), Operation.
  604.  
  605.  
  606. parse_tree(Operation, What) :-
  607.   What :== pointer,
  608.   !,
  609.   parse_mode <<- prefix,
  610.   Operation.1 <<- ref(What), Operation,
  611.   parse_the_tree(Operation, What.to),
  612.   parse_the_tree(Operation, What.star),
  613.   parse_the_tree(Operation, What.qualification),
  614.   parse_mode <<- postfix,
  615.   Operation.1 <<- ref(What), Operation.
  616.  
  617.  
  618. parse_tree(Operation, What) :-
  619.   What :== array,
  620.   !,
  621.   parse_mode <<- prefix,
  622.   Operation.1 <<- ref(What), Operation,
  623.   parse_the_tree(Operation, What.of),
  624.   parse_dimensions(Operation, What.dimensions),
  625.   parse_mode <<- postfix,
  626.   Operation.1 <<- ref(What), Operation.
  627.  
  628.  
  629. parse_tree(Operation, What) :-
  630.   What :== tag,
  631.   !,
  632.   parse_mode <<- prefix,
  633.   Operation.1 <<- ref(What), Operation,
  634.   parse_tree(Operation, What.type),
  635.   parse_mode <<- postfix,
  636.   Operation.1 <<- ref(What), Operation.
  637.  
  638.  
  639. parse_tree(Operation, What) :-
  640.   What :== function,
  641.   !,
  642.   parse_mode <<- prefix,
  643.   Operation.1 <<- ref(What), Operation,
  644.   parse_the_tree(Operation, What.return_type),
  645.   parse_the_tree(Operation, What.left_parenthesis),
  646.   parse_the_tree(Operation, What.parameters),
  647.   (
  648.     What.parameters :\== nothing,
  649.     What.parameters.parameters_number >= 1,
  650.     !,
  651.     parse_the_tree(Operation, What.parameters.1),
  652.     cond(What.parameters.vararg :== true,
  653.       parse_the_tree(Operation, What.parameters.suspension_points)
  654.     )
  655.   ;
  656.     succeed
  657.   ),
  658.   parse_the_tree(Operation, What.right_parenthesis),
  659.   parse_mode <<- postfix,
  660.   Operation.1 <<- ref(What), Operation.
  661.  
  662.  
  663. parse_tree(Operation, What) :-
  664.   What :== parameter,
  665.   !,
  666.   parse_mode <<- prefix,
  667.   Operation.1 <<- ref(What), Operation,
  668.   parse_the_tree(Operation, What.type),
  669.   parse_the_tree(Operation, What.name),
  670.   parse_the_tree(Operation, What.separator),
  671.   parse_mode <<- postfix,
  672.   Operation.1 <<- ref(What), Operation.
  673.  
  674.  
  675. parse_tree(Operation, What) :-
  676.   What :== label_parameter,
  677.   !,
  678.   parse_mode <<- prefix,
  679.   Operation.1 <<- ref(What), Operation,
  680.   parse_the_tree(Operation, What.label),
  681.   parse_mode <<- postfix,
  682.   Operation.1 <<- ref(What), Operation,
  683.   parse_the_tree(Operation, What.next).
  684.  
  685.  
  686. parse_tree(Operation, What) :-
  687.   What :== function_definition,
  688.   !,
  689.   parse_mode <<- prefix,
  690.   Operation.1 <<- ref(What), Operation,
  691.   parse_the_tree(Operation, What.type),
  692.   parse_the_tree(Operation, What.name),
  693.   parse_the_tree(Operation, What.parameters_declarations),
  694.   parse_the_tree(Operation, What.body),
  695.   parse_mode <<- postfix,
  696.   Operation.1 <<- ref(What), Operation,
  697.   parse_the_tree(Operation, What.next).
  698.  
  699.  
  700. parse_tree(Operation, What) :-
  701.   What :== parameters_declarations,
  702.   !,
  703.   parse_mode <<- prefix,
  704.   Operation.1 <<- ref(What), Operation,
  705.   parse_the_tree(Operation, What.first_declaration),
  706.   parse_mode <<- postfix,
  707.   Operation.1 <<- ref(What), Operation.
  708.  
  709.  
  710. parse_tree(Operation, What) :-
  711.   What :== parameter_declaration,
  712.   !,
  713.   parse_mode <<- prefix,
  714.   Operation.1 <<- ref(What), Operation,
  715.   parse_the_tree(Operation, What.parameter),
  716.   parse_mode <<- postfix,
  717.   Operation.1 <<- ref(What), Operation,
  718.   parse_the_tree(Operation, What.next).
  719.  
  720.  
  721. parse_tree(Operation, What) :-
  722.   What :== {struct_name; union_name; enum_name},
  723.   !,
  724.   parse_mode <<- prefix,
  725.   Operation.1 <<- ref(What), Operation,
  726.   parse_the_tree(Operation, What.name),
  727.   parse_the_tree(Operation, What.keyword),
  728.   parse_mode <<- postfix,
  729.   Operation.1 <<- ref(What), Operation.
  730.  
  731.  
  732. parse_tree(Operation, What) :-
  733.   What :== block,
  734.   !,
  735.   the_current_instruction <<- ref(What),
  736.   the_current_block = ref(CurrentBlock),
  737.   parse_mode <<- prefix,
  738.   Operation.1 <<- ref(What), Operation,
  739.   parse_the_tree(Operation, What.left_brace),
  740.   the_current_block <<- ref(What),
  741.   parse_the_tree(Operation, What.block_declarations),
  742.   parse_instructions(Operation, What.instructions),
  743.   the_current_block <<- ref(CurrentBlock),
  744.   parse_the_tree(Operation, What.right_brace),
  745.   parse_mode <<- postfix,
  746.   the_current_instruction <<- ref(What),
  747.   Operation.1 <<- ref(What), Operation.
  748.  
  749.  
  750. parse_tree(Operation, What) :-
  751.   What :== expression_instruction,
  752.   !,
  753.   the_current_instruction <<- ref(What),
  754.   parse_mode <<- prefix,
  755.   Operation.1 <<- ref(What), Operation,
  756.   parse_the_tree(Operation, What.expression),
  757.   parse_the_tree(Operation, What.semi_colon),
  758.   parse_mode <<- postfix,
  759.   the_current_instruction <<- ref(What),
  760.   Operation.1 <<- ref(What), Operation.
  761.  
  762.  
  763. parse_tree(Operation, What) :-
  764.   What :== labeled_instruction,
  765.   !,
  766.   the_current_instruction <<- ref(What),
  767.   parse_mode <<- prefix,
  768.   Operation.1 <<- ref(What), Operation,
  769.   parse_the_tree(Operation, What.label),
  770.   parse_the_tree(Operation, What.colon),
  771.   parse_the_tree(Operation, What.body),
  772.   parse_mode <<- postfix,
  773.   the_current_instruction <<- ref(What),
  774.   Operation.1 <<- ref(What), Operation.
  775.  
  776.  
  777. parse_tree(Operation, What) :-
  778.   What :== case,
  779.   has_feature(keyword, What),
  780.   !,
  781.   the_current_instruction <<- ref(What),
  782.   parse_mode <<- prefix,
  783.   Operation.1 <<- ref(What), Operation,
  784.   parse_the_tree(Operation, What.keyword),
  785.   parse_the_tree(Operation, What.condition),
  786.   parse_the_tree(Operation, What.colon),
  787.   parse_the_tree(Operation, What.body),
  788.   parse_mode <<- postfix,
  789.   the_current_instruction <<- ref(What),
  790.   Operation.1 <<- ref(What), Operation.
  791.  
  792.  
  793. parse_tree(Operation, What) :-
  794.   What :== default,
  795.   has_feature(keyword, What),
  796.   !,
  797.   the_current_instruction <<- ref(What),
  798.   parse_mode <<- prefix,
  799.   Operation.1 <<- ref(What), Operation,
  800.   parse_the_tree(Operation, What.keyword),
  801.   parse_the_tree(Operation, What.colon),
  802.   parse_the_tree(Operation, What.body),
  803.   parse_mode <<- postfix,
  804.   the_current_instruction <<- ref(What),
  805.   Operation.1 <<- ref(What), Operation.
  806.  
  807.  
  808. parse_tree(Operation, What) :-
  809.   What :== if,
  810.   has_feature(keyword, What),
  811.   !,
  812.   the_current_instruction <<- ref(What),
  813.   parse_mode <<- prefix,
  814.   Operation.1 <<- ref(What), Operation,
  815.   parse_the_tree(Operation, What.keyword),
  816.   parse_the_tree(Operation, What.left_parenthesis),
  817.   parse_the_tree(Operation, What.condition),
  818.   parse_the_tree(Operation, What.right_parenthesis),
  819.   parse_the_tree(Operation, What.then_body),
  820.   the_current_instruction <<- ref(What),
  821.   parse_the_tree(Operation, What.else_keyword),
  822.   parse_the_tree(Operation, What.else_body),
  823.   parse_mode <<- postfix,
  824.   the_current_instruction <<- ref(What),
  825.   Operation.1 <<- ref(What), Operation.
  826.  
  827.  
  828. parse_tree(Operation, What) :-
  829.   What :== {switch; while},
  830.   has_feature(keyword, What),
  831.   !,
  832.   the_current_instruction <<- ref(What),
  833.   parse_mode <<- prefix,
  834.   Operation.1 <<- ref(What), Operation,
  835.   parse_the_tree(Operation, What.keyword),
  836.   parse_the_tree(Operation, What.left_parenthesis),
  837.   parse_the_tree(Operation, What.condition),
  838.   parse_the_tree(Operation, What.right_parenthesis),
  839.   parse_the_tree(Operation, What.body),
  840.   parse_mode <<- postfix,
  841.   the_current_instruction <<- ref(What),
  842.   Operation.1 <<- ref(What), Operation.
  843.  
  844.  
  845. parse_tree(Operation, What) :-
  846.   What :== do_while,
  847.   !,
  848.   the_current_instruction <<- ref(What),
  849.   parse_mode <<- prefix,
  850.   Operation.1 <<- ref(What), Operation,
  851.   parse_the_tree(Operation, What.do_keyword),
  852.   parse_the_tree(Operation, What.body),
  853.   parse_the_tree(Operation, What.while_keyword),
  854.   parse_the_tree(Operation, What.left_parenthesis),
  855.   parse_the_tree(Operation, What.condition),
  856.   parse_the_tree(Operation, What.right_parenthesis),
  857.   parse_the_tree(Operation, What.semi_colon),
  858.   parse_mode <<- postfix,
  859.   the_current_instruction <<- ref(What),
  860.   Operation.1 <<- ref(What), Operation.
  861.  
  862.  
  863. parse_tree(Operation, What) :-
  864.   What :== for,
  865.   has_feature(keyword, What),
  866.   !,
  867.   the_current_instruction <<- ref(What),
  868.   parse_mode <<- prefix,
  869.   Operation.1 <<- ref(What), Operation,
  870.   parse_the_tree(Operation, What.keyword),
  871.   parse_the_tree(Operation, What.left_parenthesis),
  872.   parse_the_tree(Operation, What.initialization),
  873.   parse_the_tree(Operation, What.first_semi_colon),
  874.   parse_the_tree(Operation, What.condition),
  875.   parse_the_tree(Operation, What.second_semi_colon),
  876.   parse_the_tree(Operation, What.step),
  877.   parse_the_tree(Operation, What.right_parenthesis),
  878.   parse_the_tree(Operation, What.body),
  879.   parse_mode <<- postfix,
  880.   the_current_instruction <<- ref(What),
  881.   Operation.1 <<- ref(What), Operation.
  882.  
  883.  
  884. parse_tree(Operation, What) :-
  885.   What :== {continue; break},
  886.   has_feature(keyword, What),
  887.   !,
  888.   the_current_instruction <<- ref(What),
  889.   parse_mode <<- prefix,
  890.   Operation.1 <<- ref(What), Operation,
  891.   parse_the_tree(Operation, What.keyword),
  892.   parse_the_tree(Operation, What.semi_colon),
  893.   parse_mode <<- postfix,
  894.   the_current_instruction <<- ref(What),
  895.   Operation.1 <<- ref(What), Operation.
  896.  
  897.  
  898. parse_tree(Operation, What) :-
  899.   What :== goto,
  900.   has_feature(keyword, What),
  901.   !,
  902.   the_current_instruction <<- ref(What),
  903.   parse_mode <<- prefix,
  904.   Operation.1 <<- ref(What), Operation,
  905.   parse_the_tree(Operation, What.keyword),
  906.   parse_the_tree(Operation, What.label),
  907.   parse_the_tree(Operation, What.semi_colon),
  908.   parse_mode <<- postfix,
  909.   the_current_instruction <<- ref(What),
  910.   Operation.1 <<- ref(What), Operation.
  911.  
  912.  
  913. parse_tree(Operation, What) :-
  914.   What :== return,
  915.   has_feature(keyword, What),
  916.   !,
  917.   the_current_instruction <<- ref(What),
  918.   Operation.1 <<- ref(What), Operation,
  919.   parse_the_tree(Operation, What.keyword),
  920.   parse_the_tree(Operation, What.value),
  921.   parse_the_tree(Operation, What.semi_colon),
  922.   parse_mode <<- postfix,
  923.   the_current_instruction <<- ref(What),
  924.   Operation.1 <<- ref(What), Operation.
  925.  
  926.  
  927. parse_tree(Operation, What) :-
  928.   What :== void_instruction,
  929.   !,
  930.   the_current_instruction <<- ref(What),
  931.   parse_mode <<- prefix,
  932.   Operation.1 <<- ref(What), Operation,
  933.   parse_the_tree(Operation, What.semi_colon),
  934.   parse_mode <<- postfix,
  935.   the_current_instruction <<- ref(What),
  936.   Operation.1 <<- ref(What), Operation.
  937.  
  938.  
  939. parse_tree(Operation, What) :-
  940.   What :== setting,
  941.   !,
  942.   parse_mode <<- prefix,
  943.   Operation.1 <<- ref(What), Operation,
  944.   parse_the_tree(Operation, What.keyword),
  945.   parse_the_tree(Operation, What.setting),
  946.   parse_mode <<- postfix,
  947.   Operation.1 <<- ref(What), Operation.
  948.  
  949.  
  950. parse_tree(Operation, What) :-
  951.   What :== complex_initialization,
  952.   !,
  953.   Operation.1 <<- ref(What), Operation,
  954.   parse_the_tree(Operation, What.left_brace),
  955.   parse_complex_initialization(Operation, What.body),
  956.   parse_the_tree(Operation, What.right_brace),
  957.   parse_mode <<- postfix,
  958.   Operation.1 <<- ref(What), Operation.
  959.  
  960.  
  961. parse_tree(Operation, What) :-
  962.   What :== conditional_operator,
  963.   !,
  964.   parse_mode <<- prefix,
  965.   Operation.1 <<- ref(What), Operation,
  966.   parse_the_tree(Operation, What.condition),
  967.   parse_the_tree(Operation, What.operator),
  968.   parse_the_tree(Operation, What.then),
  969.   parse_the_tree(Operation, What.colon),
  970.   parse_the_tree(Operation, What.else),
  971.   parse_mode <<- postfix,
  972.   Operation.1 <<- ref(What), Operation.
  973.  
  974.  
  975. parse_tree(Operation, What) :-
  976.   What :== protected_expression,
  977.   !,
  978.   parse_mode <<- prefix,
  979.   Operation.1 <<- ref(What), Operation,
  980.   parse_the_tree(Operation, What.left_parenthesis),
  981.   parse_the_tree(Operation, What.1),
  982.   parse_the_tree(Operation, What.right_parenthesis),
  983.   parse_mode <<- postfix,
  984.   Operation.1 <<- ref(What), Operation.
  985.  
  986.  
  987. parse_tree(Operation, What) :-
  988.   What :== cast,
  989.   !,
  990.   parse_mode <<- prefix,
  991.   Operation.1 <<- ref(What), Operation,
  992.   parse_the_tree(Operation, What.left_parenthesis),
  993.   parse_the_tree(Operation, What.type),
  994.   parse_the_tree(Operation, What.right_parenthesis),
  995.   parse_the_tree(Operation, What.expression),
  996.   parse_mode <<- postfix,
  997.   Operation.1 <<- ref(What), Operation.
  998.  
  999.  
  1000. parse_tree(Operation, What) :-
  1001.   What :== function_call,
  1002.   !,
  1003.   parse_mode <<- prefix,
  1004.   Operation.1 <<- ref(What), Operation,
  1005.   parse_the_tree(Operation, What.call),
  1006.   parse_the_tree(Operation, What.left_parenthesis),
  1007.   Arguments = What.arguments,
  1008.   parse_the_tree(Operation, Arguments),
  1009.   cond(Arguments.arguments_number > 0,
  1010.     (
  1011.       FirstArgument = Arguments.1,
  1012.       parse_arguments(Operation, FirstArgument)
  1013.     )
  1014.   ),
  1015.   parse_the_tree(Operation, What.right_parenthesis),
  1016.   parse_mode <<- postfix,
  1017.   Operation.1 <<- ref(What), Operation.
  1018.  
  1019.  
  1020. parse_tree(Operation, What) :-
  1021.   What :== array_reference,
  1022.   !,
  1023.   parse_mode <<- prefix,
  1024.   Operation.1 <<- ref(What), Operation,
  1025.   parse_the_tree(Operation, What.array),
  1026.   parse_the_tree(Operation, What.left_bracket),
  1027.   parse_the_tree(Operation, What.index),
  1028.   parse_the_tree(Operation, What.right_bracket),
  1029.   parse_mode <<- postfix,
  1030.   Operation.1 <<- ref(What), Operation.
  1031.  
  1032.  
  1033. parse_tree(Operation, What) :-
  1034.   What :== sequence,
  1035.   !,
  1036.   parse_mode <<- prefix,
  1037.   Operation.1 <<- ref(What), Operation,
  1038.   parse_the_tree(Operation, What.1),
  1039.   parse_the_tree(Operation, What.operator),
  1040.   parse_the_tree(Operation, What.2),
  1041.   parse_mode <<- postfix,
  1042.   Operation.1 <<- ref(What), Operation.
  1043.  
  1044.  
  1045. parse_tree(Operation, What) :-
  1046.   What :\>< string,
  1047.   is_operator(psi2str(What)),
  1048.   !,
  1049.   parse_mode <<- prefix,
  1050.   Operation.1 <<- ref(What), Operation,
  1051.   Mode = What.mode,
  1052.   (
  1053.     Mode :== prefix,
  1054.     !,
  1055.     parse_the_tree(Operation, What.operator),
  1056.     parse_the_tree(Operation, What.1)
  1057.   ;
  1058.     Mode :== infix,
  1059.     !,
  1060.     parse_the_tree(Operation, What.1),
  1061.     parse_the_tree(Operation, What.operator),
  1062.     parse_the_tree(Operation, What.2)
  1063.   ;
  1064.     parse_the_tree(Operation, What.1),
  1065.     parse_the_tree(Operation, What.operator)
  1066.   ),
  1067.   parse_mode <<- postfix,
  1068.   Operation.1 <<- ref(What), Operation.
  1069.  
  1070.  
  1071. parse_tree(Operation, What) :-
  1072.   parse_mode <<- prefix,
  1073.   Operation.1 <<- ref(What), Operation.
  1074.  
  1075.  
  1076. %
  1077. % ------------------------------------------------------------------------------
  1078. %
  1079.  
  1080.  
  1081. parse_arguments(Operation, nothing) :- !.
  1082.  
  1083.  
  1084. parse_arguments(Operation, Argument) :-
  1085.   parse_mode <<- prefix,
  1086.   Operation.1 <<- ref(Argument), Operation,
  1087.   parse_the_tree(Operation, Argument.1),
  1088.   parse_arguments(Operation, Argument.next).
  1089.  
  1090.  
  1091. %
  1092. % ------------------------------------------------------------------------------
  1093. %
  1094.  
  1095.  
  1096. parse_dimensions(Operation, Dimensions : @(dimensions_number => N)) :-
  1097.   parse_dimension(Operation, Dimensions, 1, N + 1).  
  1098.  
  1099.  
  1100. %
  1101. % ------------------------------------------------------------------------------
  1102. %
  1103.  
  1104.  
  1105. parse_dimension(Operation, Dimension, Total, Total) :-
  1106.   !.
  1107.  
  1108.  
  1109. parse_dimension(Operation, Dimensions, Number, Total) :-
  1110.   Dimension = Dimensions.Number,
  1111.   parse_mode <<- prefix,
  1112.   Operation.1 <<- ref(Dimension), Operation,
  1113.   parse_the_tree(Operation, Dimension.left_bracket),
  1114.   parse_the_tree(Operation, Dimension.size),
  1115.   parse_the_tree(Operation, Dimension.right_bracket),
  1116.   parse_dimension(Operation, Dimensions, Number + 1, Total).
  1117.  
  1118.  
  1119. %
  1120. % ------------------------------------------------------------------------------
  1121. %
  1122.  
  1123.  
  1124. parse_instructions(Operation, []) :- !.
  1125.  
  1126.  
  1127. parse_instructions(Operation, [Instruction | Instructions]) :-
  1128.   parse_the_tree(Operation, Instruction),
  1129.   parse_instructions(Operation, Instructions).
  1130.  
  1131.  
  1132. %
  1133. % ------------------------------------------------------------------------------
  1134. %
  1135.  
  1136.  
  1137. parse_complex_initialization(Operation, [Initializer | Initializers]) :-
  1138.   !,
  1139.   parse_the_tree(Operation, Initializer),
  1140.   parse_complex_initialization(Operation, Initializers).
  1141.  
  1142.  
  1143. parse_complex_initialization(Operation, []).
  1144.  
  1145.  
  1146. %
  1147. % ------------------------------------------------------------------------------
  1148. %
  1149.  
  1150.  
  1151. non_strict(verify_rules) ?
  1152.  
  1153.  
  1154. verify_rules(Node, ["main" | Rules], Domain) :-
  1155.   !,
  1156.   verify_rules(Node, Rules, Domain).
  1157.  
  1158.  
  1159. verify_rules(Node, [Rule | Rules], Domain) :-
  1160.   !,
  1161.   (
  1162.     TheNode = Node.1,
  1163.     '*rule*'(Rule, TheNode, Domain),
  1164.     !
  1165.   ;
  1166.     write_err(">>> superlint : verification of rule ", Rule,
  1167.               " failed"),
  1168.     nl_err,
  1169.     fail
  1170.   ),
  1171.   verify_rules(Node, Rules, Domain).
  1172.  
  1173.  
  1174. verify_rules(Node, []).
  1175.  
  1176.  
  1177. %
  1178. % ------------------------------------------------------------------------------
  1179. %
  1180.  
  1181.  
  1182. max_string_length -> 20.
  1183.  
  1184.  
  1185. %
  1186. % ------------------------------------------------------------------------------
  1187. %
  1188.  
  1189.  
  1190. error_msg(Message, Prompt) :-
  1191.   cond('*display_rules*' :== yes,
  1192.     write(":-< Rule ", '*rule_name*'.1," : ")
  1193.   ), 
  1194.   (
  1195.     Prompt :== @,
  1196.     !
  1197.   ;
  1198.     is_token(Prompt),
  1199.     !,
  1200.     Prompt = @(line => Line, file => File),
  1201.     write(File, ", line ", Line),
  1202.     write(" near '", display_token(Prompt), "'")
  1203.   ;
  1204.     write_err(">>> superlint : bad prompt in error_msg, ",
  1205.               "in rule : ", Rule),
  1206.     nl_err,
  1207.     halt
  1208.   ),
  1209.   cond(Message :== @,
  1210.     (
  1211.     write_err(">>> superlint : no message in error_msg, ",
  1212.               "in rule : ", Rule),
  1213.     nl_err,
  1214.     halt
  1215.     ),
  1216.     (
  1217.       nl,
  1218.       write("    ", Message),
  1219.       nl
  1220.     )
  1221.   ).
  1222.  
  1223.  
  1224. %
  1225. % ------------------------------------------------------------------------------
  1226. %
  1227.  
  1228.  
  1229. is_token(What) :-
  1230.   has_feature(file, What).
  1231.  
  1232.  
  1233. %
  1234. % ------------------------------------------------------------------------------
  1235. %
  1236.  
  1237.  
  1238. is_not_token(What) :-
  1239.   (
  1240.     has_feature(file, What),
  1241.     !,
  1242.     fail
  1243.   ;
  1244.     succeed
  1245.   ).
  1246.  
  1247.  
  1248. %
  1249. % ------------------------------------------------------------------------------
  1250. %
  1251.  
  1252.  
  1253. str2list(String) -> make_list_from_string(String, strlen(String)).
  1254.  
  1255.  
  1256. %
  1257. % ------------------------------------------------------------------------------
  1258. %
  1259.  
  1260.  
  1261. make_list_from_string("", 0) -> [].
  1262.  
  1263.  
  1264. make_list_from_string(String, Length) ->
  1265.   [asc(substr(String, 1, 1)) | 
  1266.    make_list_from_string(substr(String, 2, Length - 1), Length - 1)].
  1267.  
  1268.  
  1269. %
  1270. % ------------------------------------------------------------------------------
  1271. %
  1272.  
  1273. string_of([]) -> "".
  1274.  
  1275. string_of([Char | LChars]) -> strcon(chr(Char), string_of(LChars)).
  1276.  
  1277.  
  1278. %
  1279. % ------------------------------------------------------------------------------
  1280. %
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.