"run_unix_program" + "pipein" 
Author Message
 "run_unix_program" + "pipein"

--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.

Quote:

> 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:





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...?
<P> Thank you in advance, far in advance.
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<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>?</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 ---> 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>?</P>
<P>I have included both tail.p and tty.p for reference.</P>
<P>Thank you, far in advance.</P>
<P>?</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() ->> list) == newline do </P>
<P>sysparse_string(list, false)-> list1;</P>
<P>enduntil;</P>
<P>?</P>
<P>SAMPLE OUTPUT:</P>




<P>?</P>
<P>?</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://www.*-*-*.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--



Sun, 26 Sep 2004 12:56:27 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. "run_unix_program" + "pipein"

2. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

3. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

4. Parsing ""D""?

5. "Fifth", "Forth", zai nar?

6. Ruby "finalize", "__del__"

7. beginners "let"/"random" question

8. ANNOUNCE: new "plus"- and "dash"-patches available for Tcl7.5a2/Tk4.1a2

9. Looking for "stdin", "stdout"

10. Hi, this code: text0 = "One $BLAH Three" text1 = "One @BLAH Three" text0.sub!("$BLAH", "Two") text1.sub!("@BLAH", "Two") print text0,"\n" print text1,"\n" produces thiHi, this code: text0 = "One $BLAH Three" text1 = "One @BLAH Three" text0.sub!("$BLAH", "T

11. Match "ab" in "abc", but not in "abd"

12. replace string AFTER "size","initial", "next"

 

 
Powered by phpBB® Forum Software