readin.pro

来自「经典的基于Context-Free_Grammer 的语法分析器。」· PRO 代码 · 共 25 行

PRO
25
字号
% File readin.pl - Prolog program to read in a file of sentences
%   using built in library(readin)
%   To use readin from standard input, used CTRL-D for eol, CTRL-Z for eof
%   readin tokenizes words on blanks, punctuations, and white spaces and
%    removes whitespaces. readin reads up to 1st line that ends in '.'
%    See reference manual for more details
:- ensure_loaded(library(readin)).
%process: current input stream is assumed to have been established before
process :-   % used to read in sentence using Prolog library read_in
         % repeat is a procedural predicate used for iteration
         repeat,   %repeat until the complete file is processed
              read_in(X),   %creates list X using library builtin
              (X = end_of_file, seen, !; 
               X = [''], seen, !;
               test(X,F),  %test is a predicate that can be used to process sentence 
               fail
              ).
%process: established Infile as current input stream before processing
process(Infile) :- see(Infile), process.             
            
%test(+Sentence,-ProcessedSentence) is a predicate for testing sentence readin
% It writes out sentence to standard output
test(S,S) :- write(S),  %this could be substituted with a predicate that processes S
             nl.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?