Main Menu

KB#00058-Using BBx as a parser with input and output pipes

Title:

Using BBx as a parser with input and output pipes

Description:

The following program and Unix command line shows how to build a rudimentary parser in BBx. Because this is a simple example, it just prepends the 'Got: ' string to every line received. 


BBx program: 
0005 OPEN (1)"IO" 
0010 READ (1,END=0200,TIM=5)A$ 
0020 PRINT "Got: ",A$ 
0030 GOTO 0010 
0200 RELEASE 

Example using a Unix 'ls' for input, parsing in BBx, piping to Unix 'more' 
ls | ./pro5 -tIO testpgm |more 


=================================================================================
C PROGRAM 

#include <stdio.h> 
main (void) 


int *cle[1]; 
*cle[1]=getchar(); 
printf("cle :%s\n\n",cle[1]); 


BBx PROGRAM 

0010 ERASE "./testfile",ERR=0020 
0020 MKEYED "./testfile",10,10,10 
0030 OPEN (1)"./testfile" 
0040 PRINT (1,KEY="a")"a" 
0050 CLOSE (1) 
0060 OPEN (1)"./testfile" 
0070 READ (1,KEY="a")Z$ 
0080 CLOSE (1) 
0090 OPEN (1)"IO" 
0100 PRINT (1)Z$ 
0110 CLOSE (1) 
0120 RELEASE 

THE UNIX COMMAND 

$ ./pro5 -tIO testpgm.bbx | ctestpgm 
cle :a 

This example shows how the BBx program reads in data from a BBx mkeyed file, then prints it out to stdout. This output is piped to the C program, which reads it from stdin and then prints it out to show that it read the data correctly. 

=================================================================================
To modify the previous example to work with a string (as opposed to a char) replace the C and BBx programs with the following: 

C PROGRAM 

#include <stdio.h> 
main (void) 


int ch; 
printf("The following was read from stdin:"); 
while ((ch=getchar()) != EOF) 
putchar(ch); 



BBx PROGRAM 

0010 ERASE "./testfile",ERR=0020 
0020 MKEYED "./testfile",10,10,10 
0030 OPEN (1)"./testfile" 
0040 LET A$="0011abcd" 
0050 PRINT (1,KEY=A$)A$ 
0060 CLOSE (1) 
0070 OPEN (1)"./testfile" 
0080 LET B$=KEY(1) 
0090 READ (1,KEY=B$)Z$ 
0100 CLOSE (1) 
0110 OPEN (1)"IO" 
0120 PRINT (1)Z$ 
0130 CLOSE (1) 
0140 RELEASE 



Last Modified: 11/10/1998 Product: PRO/5 Operating System: Unix

BASIS structures five components of their technology into the BBx Generations.

View BASIS LinkedIN Profile Visit our Twitter Feed Check out our Facebook Public Profile Click to View the BASIS youTube channel