Everything2
Near Matches
Ignore Exact
Full Text
Everything2

properly matched string

created by cadex

(idea) by cadex (4.3 y) (print)   ?   (I like it!) Sun Mar 25 2001 at 12:17:45

An Algorithm for Checking Nested Parentheses

This algorithm is useful in programming and computation theory to determine if a string has properly nested parentheses. A string is a finite sequence of characters, two of which can be the left parenthesis '(' and right parenthesis ')'. The set of properly matched strings is defined as follows:

  1. If a string X contains no parentheses, then it is properly matched.
  2. If X is a properly matched string, then so is (X).
  3. If X and Y are properly matched strings, then so is XY.
  4. Only strings that can be formed by rules 1-3 are properly matched strings.

Example 1: (5 * (1 + 2))(4)

Properly matched.
Start with 1 + 2 by rule 1;
(1 + 2) by rule 2;
5 * (1 + 2) by rules 1,3;
(5 * (1 + 2)) by rule 2;
(5 * (1 + 2))(4) by rules 1,3.

Example 2:
Properly matched. A string can be empty. (see rule 1)

Example 3: if(!(!(0.999 == 1))
Not properly matched.
There is an extra left parenthesis. (see rules 2,4)

Example 4: how to be a better monkey )tm(
Not properly matched.
Parentheses are out of order. (see rules 2,4)


Related topics: nested parentheses, Theory of Computation, context-free grammar, LISP.


printable version
chaos

nested parentheses Cap'n Magneto Yule's Characteristic Catalan number
Heidi Klum Book of Sheep Theta Tau context-free grammar
Computational linguistics Theory of Computation Stevens' physical proof of the sine rule pumping lemma proof that the balanced braces language is not regular
Myhill Theorem proof that the balanced braces language is not regular TM Detroit Auto Show Euchre
tabbouleh One equals point nine repeating Out of order parenthesis
Empty LISP parentheses sequence
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Nodes to live by:
September 11, 2001 - III
Rules of program optimization
Irish Wake
Louisiana Purchase
Critias
CCBBA Karate Curriculum
sorghum
Thomas Jefferson's First Inaugural Address
How to meet the most girls
hypoglycemia
Gloria Anzaldúa Memorial Quest
Making an F-16 from a cereal box, some Scotch tape, and a penny
Cy Twombly
New Writeups
XWiz
Trism(review)
artman2003
Briefcase Full of Souls - Part I(fiction)
Dreamvirus
Alan Ladd(person)
waverider37
Harold Holt(person)
The Debutante
Until death do us part(fiction)
Ysardo
a brother to a sister(personal)
antigravpussy
your warm whispers(personal)
Clarke
Multiculturalism(idea)
aneurin
Earl of Landaff(person)
Heitah
Pseudocide(idea)
XWiz
Google Knol(lede)
Mythi
July 24, 2008(personal)
locke baron
The fall of Earth(fiction)
BookReader
Fear the Cold(dream)
Pavlovna
Kathleen MacInnes(person)
This affordable entertainment brought to you by The Everything Development Company