[futurebasic] Re: Parsing

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 1997 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Sat, 29 Nov 1997 12:54:28 -0600
> I assume you're looking for mathematical formulas.  Perhaps you could try
> searching for the brackets first, and take action based on whether a
> bracket has been opened yet.  In the SELECT part of the above code, you
> could set flags like this:
>         select a$
>         case "{"
>                 openLarge=_true
>         case "["
>                 openBracket=_true
>         case "("
>                 openParenthesis=_true
>         case "}"
>                 open large=_false
>         etc.
>         case else
>                 ...take action based on what is true at this point...

Don't forget though, that this breaks down if it's possible to have
nested sections with the same type of "enclosers"; e.g.:


It's better to have a counter for each type, that increments whenever
you encounter a "left" encloser, and decrements when you encounter a
"right" encloser.  when the counter reaches zero, you're outside of the

I'd probably approach the whole thing as follows:

1. Use MUNGER to search for every occurrence of right & left versions of
each type of encloser (this involves multiple searches, but they're
fast).  Save the location & type of each occurrence in an array.

2. Sort the array by location.

3. Step through the array, and use "counters" (as mentioned above) to
determine where sections get "opened" and "closed."

By doing this, you've identified exactly which areas of the file are
"outside" of any sections, and which areas are "inside" a section.  You
can save _that_ information in some other array if you like--an array
that indicates the file's "section opening" points and "section closing"
points.  Now, when you find some arbitrary string in the file and you
want to determine whether it's inside or outside of a section, you just
refer to the "opening point" and "closing point" information that you've
already gathered.

- Rick