[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Apr 10 04:56:27 2002 
Subject:Re: "run_unix_program" + "pipein" 
From:clintwks 
Volume-ID:1020410.01 

--0-746687406-1018414569=:27638
Content-Type: multipart/alternative; boundary="0-1394542470-1018414569=:27638"

--0-1394542470-1018414569=:27638
Content-Type: text/plain; charset=us-ascii


A few weeks ago you replied back to me regarding SYSIO...  
 Thank you in advance, far in advance.
 Aaron Sloman <A.Sloman@cs.bham.ac.uk> wrote: 
clintwks@yahoo.com writes:

> Date: Fri, 15 Mar 2002 15:11:51 +0000 (UTC)
>
> I am trying to fork a unix shell command from which I
> can use its output to parse with in Poplog. Here is an
> example from "run_unix_program" that I am trying to
> make work.

Hello Aaron,

I took your advice and adapted a workable procedure from the examples

that you offered a few weeks ago. Well, I've been busy coding with it since.

My problem is that when I use a character repeater to bring the input stream

into the program. the data is not useable until I quote the heck of each literal.

I have a version that uses readline() for input and I have to use no quotes at all.

MY QUESTION IS:

How can I get the 'sys_obey_linerep' stream's data and be

addressable just like the readline() data, but without the use of quotes.

Is there a procedure that will 'flatten' or 'normalize' the lists generated in tail.p 

 

tty.p

reads all input from a tty via readline(). It works to

my expectation, it needs much more work, but I have

a handle on what to do next.

tail.p

reads all input from a file via sysobeylinerep ---> tail.

It kinda works, the problem is that the input stream is

interpreted differently than it's readline() counterpart.

I have to use 'quotes' all over the place. Especially inside of

conditionals and grammar structures.



This is an excerpt from tail.p. Notice how command #79 flips things out.

I know, I could use the null() procedure or catch it with a filter...

 

I have included both tail.p and tty.p for reference.

Thank you, far in advance.

 

HERES THE CULPRIT:

vars repeater = sys_obey_linerep('/usr/bin/tail -f /tmp/1');

vars string,list,list2;

until (repeater() ->> list) == newline do 

sysparse_string(list, false)-> list1;

enduntil;

 

SAMPLE OUTPUT:

<cwk@titan> ~ [ 78 ] %echo "John likes Mary" >> /tmp/1

<cwk@titan> ~ [ 79 ] %echo "John likes Mary\n" >> /tmp/1

<cwk@titan> ~ [ 80 ] %echo "John likes Mary and his Dog" >> /tmp/1

<cwk@titan> ~ [ 81 ] %echo "Mary likes Frank" >> /tmp/1

 

 

Setpop

: load tail.p

;;; LOADING tail.p

;;; DECLARING VARIABLE list1

;;; DECLARING VARIABLE respondto

: c();

[John likes Mary]** [Not understood at all by this grammar .]

[John likes Mary]** [Not understood at all by this grammar .]

[]** [Not understood at all by this grammar .]

[John likes Mary and his Dog]** [Not understood at all by this grammar.]

[Mary likes Frank]** [Not understood at all by this grammar .]

Yes, the conditionals understand list1, but the recognize() does not:

** [Not understood at all by this grammar .]

If I had used readline()+ tty.p , these would have tested true.



---------------------------------
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
--0-1394542470-1018414569=:27638
Content-Type: text/html; charset=us-ascii

<P>A few weeks ago you replied back to me regarding SYSIO...&nbsp; 
<P> Thank you in advance, far in advance.
<P>&nbsp;<B><I>Aaron Sloman &lt;A.Sloman@cs.bham.ac.uk&gt;</I></B> wrote: 
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<P>clintwks@yahoo.com writes:<BR><BR>&gt; Date: Fri, 15 Mar 2002 15:11:51 +0000 (UTC)<BR>&gt;<BR>&gt; I am trying to fork a unix shell command from which I<BR>&gt; can use its output to parse with in Poplog. Here is an<BR>&gt; example from "run_unix_program" that I am trying to<BR>&gt; make work.</P><FONT size=2>
<P>Hello Aaron,</P>
<P>I took your advice and adapted a workable procedure from the examples</P>
<P>that you offered a few weeks ago. Well, I've been busy coding with it since.</P>
<P>My problem is that when I use a character repeater to bring the input stream</P>
<P>into the program. the data is not useable until I quote the heck of each literal.</P>
<P>I have a version that uses readline() for input and I have to use no quotes at all.</P>
<P>MY QUESTION IS:</P>
<P>How can I get the 'sys_obey_linerep' stream's data and be</P>
<P>addressable just like the readline() data, but without the use of quotes.</P>
<P>Is there a procedure that will 'flatten' or 'normalize' the lists generated in tail.p </P>
<P>&nbsp;</P>
<P>tty.p</P>
<P>reads all input from a tty via readline(). It works to</P>
<P>my expectation, it needs much more work, but I have</P>
<P>a handle on what to do next.</P>
<P>tail.p</P>
<P>reads all input from a file via sysobeylinerep ---&gt; tail.</P>
<P>It kinda works, the problem is that the input stream is</P>
<P>interpreted differently than it's readline() counterpart.</P>
<P>I have to use 'quotes' all over the place. Especially inside of</P>
<P>conditionals and grammar structures.</P>
<P></P>
<P>This is an excerpt from tail.p. Notice how command #79 flips things out.</P>
<P>I know, I could use the null() procedure or catch it with a filter...</P>
<P>&nbsp;</P>
<P>I have included both tail.p and tty.p for reference.</P>
<P>Thank you, far in advance.</P>
<P>&nbsp;</P>
<P>HERES THE CULPRIT:</P>
<P>vars repeater = sys_obey_linerep('/usr/bin/tail -f /tmp/1');</P>
<P>vars string,list,list2;</P>
<P>until (repeater() -&gt;&gt; list) == newline do </P>
<P>sysparse_string(list, false)-&gt; list1;</P>
<P>enduntil;</P>
<P>&nbsp;</P>
<P>SAMPLE OUTPUT:</P>
<P>&lt;cwk@titan&gt; ~ [ 78 ] %echo "John likes Mary" &gt;&gt; /tmp/1</P>
<P>&lt;cwk@titan&gt; ~ [ 79 ] %echo "John likes Mary\n" &gt;&gt; /tmp/1</P>
<P>&lt;cwk@titan&gt; ~ [ 80 ] %echo "John likes Mary and his Dog" &gt;&gt; /tmp/1</P>
<P>&lt;cwk@titan&gt; ~ [ 81 ] %echo "Mary likes Frank" &gt;&gt; /tmp/1</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<P>Setpop</P>
<P>: load tail.p</P>
<P>;;; LOADING tail.p</P>
<P>;;; DECLARING VARIABLE list1</P>
<P>;;; DECLARING VARIABLE respondto</P>
<P>: c();</P>
<P>[John likes Mary]** [Not understood at all by this grammar .]</P>
<P>[John likes Mary]** [Not understood at all by this grammar .]</P>
<P>[]** [Not understood at all by this grammar .]</P>
<P>[John likes Mary and his Dog]** [Not understood at all by this grammar.]</P>
<P>[Mary likes Frank]** [Not understood at all by this grammar .]</P>
<P>Yes, the conditionals understand list1, but the recognize() does not:</P>
<P>** [Not understood at all by this grammar .]</P></FONT><FONT face="Courier New" size=2>
<P>If I had used readline()+ tty.p , these would have tested true.</P></FONT></BLOCKQUOTE><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/welcome/?http://taxes.yahoo.com/";>Yahoo! Tax Center</a> - online filing with TurboTax
--0-1394542470-1018414569=:27638--
--0-746687406-1018414569=:27638
Content-Type: text/plain; name="tail.p"
Content-Description: tail.p
Content-Disposition: inline; filename="tail.p"

uses readpattern;
uses doesmatch;



define c();
        vars x, y, z;
	vars repeater = sys_obey_linerep('/usr/bin/tail -f /tmp/1');
	vars string,list,list2;

	until (repeater() ->> list) == '\n'  do

		sysparse_string(list, false)-> list1;
		respondto(list1);
	enduntil;
enddefine;


/* define c();
        vars x, y, z;
        [Construct a case sensitive sentence using:]=>;
	[Nouns---> John, Mary or Frank with the verb likes.] =>;
	[For example]=>;
	[John likes Mary]=>
        readline() -> list1;
        until list1 matches [ ??x exit ??y  ] do
            respondto(list1);
            readline() -> list1;
        enduntil;
    enddefine; */

vars grammar_cfg;

  [[SENTENCE [NOUN_PHRASE VERB_PHRASE]]
   [VERB_PHRASE [VERB NOUN_PHRASE]]
   [NOUN_PHRASE [Mary]]
   [NOUN_PHRASE [John]]
   [NOUN_PHRASE [Frank]]
   [VERB [likes]
   ]] -> grammar_cfg;


 define shift(paper) -> new_paper;

      vars left, word, words;

      if paper matches [?left [?word ??words]] then
          [[^^left ^word] ^words] -> new_paper;
      else
          false -> new_paper;
      endif;

  enddefine;
  
  
  
    define reduce(paper,rule) -> new_paper;

      vars cat, rhs, cats, right;

      if rule matches [?cat ?rhs]
      and paper matches [[??cats ^^rhs] ?right] then
          [[^^cats ^cat] ^right] -> new_paper;
      else
          false -> new_paper;
      endif;
  enddefine;
  
/*
 *   This procedure runs each grammar reduction scenario
 *   until it finds the solution. The reason for this is that,
 *   some grammatical sequences have the option of shifting
 *   a string over to the lhs or it can be reduced to a rule.
 *   So instead of always shifting and instead of trying out
 *   a reduction scenario, the the recognize(procedure)
 *   runs the gambit on all such cases using both
 *   reduction and shift(s) until the list (sentence)
 *   is found either true(which means it is a sentence
 *   or false.<-- Which means it is not a sentance or part of the grammar.
 */
  
    define recognize(input,grammar) -> answer;

      vars pile, rule_count, top, new_paper, i;

      [[[] ^input]] -> pile;
      length(grammar) -> rule_count;

      repeat
          if pile = [] then
              false -> answer;
              return();
          endif;
          if pile matches [[[SENTENCE] []] ??papers] then
              true -> answer;
              return();
          endif;
          if pile matches [?top ??pile] then
              shift(top) -> new_paper;
              if new_paper then
                  [^new_paper ^^pile] -> pile;
              endif;
              for i from 1 to rule_count do
                  reduce(top, grammar(i)) -> new_paper;
                  if new_paper then
                      [^new_paper ^^pile] -> pile;
                  endif;
              endfor;
          endif;
      endrepeat;
  enddefine;
  
  
  
define respondto();
	vars w, x, y, k;
/* First see if the responsdto(list1) is part of the grammar before the
conditionals. Do I still have to use so many quotes?? */

if recognize(pr(list1), grammar_cfg) == true then
;;; The above fails in tail.p and works in tty.p.

		if     list1 matches ['John' ??w 'Mary'] then
			[You said, 'John' ^^w 'Mary']=>
		elseif list1 matches ['Mary' ??w ??x] then
			[Mary ^^w ^^x, are you sure about that?]=>
		elseif list1 matches [??w 'Frank' ??x] then
			[^^w Frank ^^x, Thats enough about Frank!!]=>
		elseif list1 matches [??w 'John'  ??x] then
			[^^w John ^^x, glad you did not mention Mary or Frank.]=>
		else
	oneof([[Not part of these conditionals.][Sentence, well?!. Gramatical,
	NO!][Try again]])=>
		endif;
else
	[Not understood at all by this grammar.] =>;
endif;		 
enddefine;
--0-746687406-1018414569=:27638
Content-Type: text/plain; name="tty.p"
Content-Description: tty.p
Content-Disposition: inline; filename="tty.p"

uses readpattern;
uses doesmatch;
popnewline = true;


define c();
        vars x, y, z;
        [Construct a case sensitive sentence using:]=>;
	[Nouns---> John, Mary or Frank with the verb likes.] =>;
	[For example]=>;
	[John likes Mary]=>
        readline() -> list1;
        until list1 matches [ ??x exit ??y  ] do
            respondto(list1);
            readline() -> list1;
        enduntil;
    enddefine;

vars grammar_cfg;

  [[SENTENCE [NOUN_PHRASE VERB_PHRASE]]
   [VERB_PHRASE [VERB NOUN_PHRASE]]
   [NOUN_PHRASE [Mary]]
   [NOUN_PHRASE [John]]
   [NOUN_PHRASE [Frank]]
   [VERB [likes]
   ]] -> grammar_cfg;


 define shift(paper) -> new_paper;

      vars left, word, words;

      if paper matches [?left [?word ??words]] then
          [[^^left ^word] ^words] -> new_paper;
      else
          false -> new_paper;
      endif;

  enddefine;
  
  
  
    define reduce(paper,rule) -> new_paper;

      vars cat, rhs, cats, right;

      if rule matches [?cat ?rhs]
      and paper matches [[??cats ^^rhs] ?right] then
          [[^^cats ^cat] ^right] -> new_paper;
      else
          false -> new_paper;
      endif;
  enddefine;
  
/*
 *   This procedure runs each grammar reduction scenario
 *   until it finds the solution. The reason for this is that,
 *   some grammatical sequences have the option of shifting
 *   a string over to the lhs or it can be reduced to a rule.
 *   So instead of always shifting and instead of trying out
 *   a reduction scenario, the the recognize(procedure)
 *   runs the gambit on all such cases using both
 *   reduction and shift(s) until the list (sentence)
 *   is found either true(which means it is a sentence
 *   or false.<-- Which means it is not a sentance or part of the grammar.
 */
  
    define recognize(input,grammar) -> answer;

      vars pile, rule_count, top, new_paper, i;

      [[[] ^input]] -> pile;
      length(grammar) -> rule_count;

      repeat
          if pile = [] then
              false -> answer;
              return();
          endif;
          if pile matches [[[SENTENCE] []] ??papers] then
              true -> answer;
              return();
          endif;
          if pile matches [?top ??pile] then
              shift(top) -> new_paper;
              if new_paper then
                  [^new_paper ^^pile] -> pile;
              endif;
              for i from 1 to rule_count do
                  reduce(top, grammar(i)) -> new_paper;
                  if new_paper then
                      [^new_paper ^^pile] -> pile;
                  endif;
              endfor;
          endif;
      endrepeat;
  enddefine;
  
  
  
define respondto();
	vars w, x, y, k;
/* First see if the responsdto(list1) is part of the grammar before the
conditionals. */

if recognize(pr(list1), grammar_cfg) == true then

		if     list1 matches [John ??w Mary] then
			[You said, John ^^w Mary]=>
		elseif list1 matches [Mary ??w ??x] then
			[Mary ^^w ^^x, are you sure about that?]=>
		elseif list1 matches [??w Frank ??x] then
			[^^w Frank ^^x, Thats enough about Frank!!]=>
		elseif list1 matches [??w John ??x] then
			[^^w John ^^x, I hope you did not mention Mary or Frank.]=>
		else
	oneof([[Not part of these conditionals.][Sentence, well?!. Gramatical,
	NO!][Try again]])=>
		endif;
else
	[Not understood at all by this grammar.] =>;
endif;		 
enddefine;

--0-746687406-1018414569=:27638--