Author Topic: Regular Expression Demo by AIR  (Read 149 times)

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 680
    • View Profile
Regular Expression Demo by AIR
« on: November 03, 2020, 09:18:35 AM »
Armando Rivera included this demo with his modified version of BCX (MBC) almost 10 years ago.

I noticed it was written targeting systems that had an ISO compiler system. 

BCX 761 translated the demo and Pelles C compiles it in 32 and 64 bit.


LccWin32, Mingw, MSVC, and Clang all reported regex.h not found.


I'm not a big regular expression user but because this is all native code (fast), I may have
to think about ways to give this capability some work to do.

It appears to run correctly, based on my understanding of the demo.

OUTPUT

Raw  sS1 As  stdstr
Raw  sS2 As  stdstr
Raw  sS3 As  stdstr
global  window as  HANDLE*
raw  Z[6] AS  INTEGER PTR
raw  a[6] as  integer
raw  b as  integer
raw  c[7] as  integer
dim  hg as  long
dim  ig as  long
dim  jg as  long
dim  st[20] dynamic as  long

Press any key to continue . . .

« Last Edit: November 13, 2020, 07:18:40 AM by MrBcx »

Robert

  • Hero Member
  • *****
  • Posts: 527
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #1 on: November 03, 2020, 11:53:59 AM »
Armando Rivera included this demo with his modified version of BCX (MBC) almost 10 years ago.

I noticed it was written targeting systems that had an ISO compiler system. 

BCX 761 translated the demo and Pelles C compiles it in 32 and 64 bit.


LccWin32, Mingw, MSVC, and Clang all reported regex.h not found.


I'm not a big regular expression user but because this is all native code (fast), I may have
to think about ways to give this capability some work to do.

It appears to run correctly, based on my understanding of the demo.

OUTPUT

Raw  sS1 As  stdstr
Raw  sS2 As  stdstr
Raw  sS3 As  stdstr
global  window as  HANDLE*
raw  Z[6] AS  INTEGER PTR
raw  a[6] as  integer
raw  b as  integer
raw  c[7] as  integer
dim  hg as  long
dim  ig as  long
dim  jg as  long
dim  st[20] dynamic as  long

Press any key to continue . . .

Hi MrBCX:

MBC was built for Linux and Mac and more recently Raspberry Pi. The Linux GCC setup has all the regex bits included. Pelle added the regex bits as an extension to his compiler. Porting regex from GCC to Windows may be a bit difficult.  I thought someone had done Henry Spencer's regex in BCX. I will look.
« Last Edit: November 13, 2020, 07:19:00 AM by MrBcx »

Robert

  • Hero Member
  • *****
  • Posts: 527
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #2 on: November 03, 2020, 12:03:35 PM »
Code: [Select]

'BCX@yahoogroups.com; on behalf of; Michael S. Sanders [mjs@nts-online.net]
'Tue 2008-06-17 07:53
'BCX] BCX/COM/RegExp!

'Absolutely great, how simple does it get? =)

? Rx$("xyz123", "[a-z]", "*") ' replace letters
? Rx$("xyz123", "[0-9]", "*") ' reaplce numbers

'----------------------------------------------------------
Function Rx$(MainStr$, Pattern$, Replacement$)
'----------------------------------------------------------
Dim rx As OBJECT : rx = CREATEOBJECT("VBScript.RegExp")

With rx
.IgnoreCase = True
.Global = True
.Pattern = Pattern$
End With

Dim tmp$ : tmp$ = rx.Replace(MainStr$, Replacement$)

SET rx = NOTHING

Function = tmp$
End Function


« Last Edit: November 13, 2020, 07:19:17 AM by MrBcx »

jcfuller

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #3 on: November 03, 2020, 12:37:04 PM »
I use the STL regex with VSCPP in my bcxpp.dll with great success.
Source will be available with the BcxAdp release

James


« Last Edit: November 13, 2020, 07:19:30 AM by MrBcx »

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 680
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #4 on: November 03, 2020, 01:38:28 PM »
Code: [Select]

'BCX@yahoogroups.com; on behalf of; Michael S. Sanders [mjs@nts-online.net]
'Tue 2008-06-17 07:53
'BCX] BCX/COM/RegExp!

'Absolutely great, how simple does it get? =)

? Rx$("xyz123", "[a-z]", "*") ' replace letters
? Rx$("xyz123", "[0-9]", "*") ' reaplce numbers

'----------------------------------------------------------
Function Rx$(MainStr$, Pattern$, Replacement$)
'----------------------------------------------------------
Dim rx As OBJECT : rx = CREATEOBJECT("VBScript.RegExp")

With rx
.IgnoreCase = True
.Global = True
.Pattern = Pattern$
End With

Dim tmp$ : tmp$ = rx.Replace(MainStr$, Replacement$)

SET rx = NOTHING

Function = tmp$
End Function


I've used the MS COM component before.  Sluggish. 

Another good regex library for plain C is SLRE by Sergey Lyubka.  I integrated it into FFS many
years ago.  Although it is not PCRE or Henry Spencer grade, what it lacks is easily made up for in its
size and ease of integration.  I once used BCX and SLRE to locate files containing Social Security Numbers
that our secretary had amassed and scattered all over our network server.  This was back in the early
2000's when data security was gaining prominence among common folk.
« Last Edit: November 13, 2020, 07:19:41 AM by MrBcx »

dragon57

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #5 on: November 05, 2020, 11:57:34 AM »
I use regular expressions in my AutoHotkey scripts to parse XML and JSON files. I would love to have the same regular expression support in BCX!
« Last Edit: November 13, 2020, 07:19:56 AM by MrBcx »

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 680
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #6 on: November 05, 2020, 02:10:21 PM »
I'm not a AHK user but a quick look at its wiki indicates it uses PCRE. 

One of the beautiful things about BCX is that you can often use C libraries without needing to translate the
headers to some form of BASIC or create a long list of DECLARE statements, just to use the functions.  I don't
see integrating PCRE into BCX ever happening but that doesn't mean you can't download the files that you
need and begin experimenting. 

http://gnuwin32.sourceforge.net/packages/pcre.htm

The developers zip has the headers and .lib and the binary zip has pcre3.dll in it.   I'd start there.
I've never used the PCRE package, so I can't offer any help with an example.
« Last Edit: November 13, 2020, 07:20:12 AM by MrBcx »

Robert

  • Hero Member
  • *****
  • Posts: 527
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #7 on: November 05, 2020, 02:30:20 PM »
Pelle used Henry Spencer's library in his implementation.

Attached is the source code to the 1995 version.

« Last Edit: November 13, 2020, 07:20:29 AM by MrBcx »

jcfuller

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #8 on: November 05, 2020, 02:56:19 PM »
The Nuwen distro includes pcre but of course it is only 64bit

I have an old 32bit version I built for use with the OLD TDM around here somewhere.

James
« Last Edit: November 13, 2020, 07:20:42 AM by MrBcx »

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 680
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #9 on: November 05, 2020, 03:34:10 PM »

The Nuwen distro includes pcre but of course it is only 64bit

I have an old 32bit version I built for use with the OLD TDM around here somewhere.

James

It looks like AHK has supported 32 and 64 bit for several years.
« Last Edit: November 13, 2020, 07:20:58 AM by MrBcx »

Robert

  • Hero Member
  • *****
  • Posts: 527
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #10 on: November 05, 2020, 04:48:48 PM »
Armando Rivera included this demo with his modified version of BCX (MBC) almost 10 years ago.

I noticed it was written targeting systems that had an ISO compiler system. 

BCX 761 translated the demo and Pelles C compiles it in 32 and 64 bit.


LccWin32, Mingw, MSVC, and Clang all reported regex.h not found.


I'm not a big regular expression user but because this is all native code (fast), I may have
to think about ways to give this capability some work to do.

It appears to run correctly, based on my understanding of the demo.

OUTPUT

Raw  sS1 As  stdstr
Raw  sS2 As  stdstr
Raw  sS3 As  stdstr
global  window as  HANDLE*
raw  Z[6] AS  INTEGER PTR
raw  a[6] as  integer
raw  b as  integer
raw  c[7] as  integer
dim  hg as  long
dim  ig as  long
dim  jg as  long
dim  st[20] dynamic as  long

Press any key to continue . . .

This program will compile cleanly but nothing happens on execution if "/STACK:10485760" is not on the POLink command line.

That took several W.T.F.s.

« Last Edit: November 13, 2020, 07:21:28 AM by MrBcx »

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 680
    • View Profile
Re: Regular Expression Demo by AIR
« Reply #11 on: November 05, 2020, 05:20:17 PM »
Interesting.

I haven't scrutinized the code but heavy stack usage is often a sign of deep nesting of function calls and/or recursion.

I added 1MB stacks to my Pelles and Lcc batch files years ago which explains why AIR's demo worked for me right out of the box.
« Last Edit: November 13, 2020, 07:21:14 AM by MrBcx »