Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3397890
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:35:00+00:00 2026-05-18T04:35:00+00:00

rephrase… I’d like to know how to best to parse functions/conditionals. so if you

  • 0

rephrase…

I’d like to know how to best to parse functions/conditionals. so if you have something like: [if {a} is {12 or 34}][if {b} not {55}] show +c+ [/if][/if] which is a conditional inside a conditional. Looks like I can’t do this with regex only.


original question

for now I have a pretty simple way of parsing out some commands through actionscript.

I’m using regexp to find tags, commands and operands using…

+key_word+  // any text surrounded by +
[ifempty +val_1+]+val_2+[/ifempty]  //simple conditional
[ifisnot={`true,yes`} +ShowTitle+]+val_3+[/ifisnot]  // conditional with operands

my current algorithm matches the opening tag[**] with the first closing tag [/**] even though it doesn’t match. Which means that I could not do something like [ifempty +val_2+][ifnotempty +val_2]+val_3+[/ifnotempty]+val_4+[/ifempty] – essentially putting one conditional inside another one.

I’m using an inline way of parsing that splits the string into an array of strings based on this regexp \[[^\/](?:[^\]])*\](?:[^\]])*\[\/(?:[^\]])*\]

can anyone suggest a more robust algorithm with a more robust parsing convention/standard? especially for as3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:35:01+00:00Added an answer on May 18, 2026 at 4:35 am

    Regular expressions define Regular Languages. Regular Languages cannot have regions of constrained, but potentially infinite, recursion.

    One way of thinking about it is that all Regular Languages can be represented by a Finite State Machine. You would need a state for every possible number of if’s, but the machine must be ‘finite’, so your in a bind. A classic example is:

    a{n}b{n}, n >= 0
    (meaning n a's, followed by n b's)
    

    As you parse each a, you would need to go to another state (FSMs have no memory beyond the state their in, that’s the only way they could remember n to match it later). To parse any number of n’s, you would need an infinite number of states.

    This is the same situation you’re in, a regular expression could express a finite number of ifs (although it would take quite a bit of copy-pasting), but not an infinite number. Note however that some regular expression implementations cheat a bit, giving them more power than their mathematical equivalents.

    In any case, your best bet is to use a more powerful parsing method. A recursive descent parser is particularly fun to implement, and could easily do what you need. You could also look into an LR-parser, or build a simple parser using a stack. Depending on your language, you might be able to find a parsing library such as pyparse for Python or Boost Spirit for C++.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string which may or may not end with whitespace and I'm
To Rephrase I am newbie to haskell. I am trying to parse a pcap
Please feel free to rephrase the title if it is not appropriate. I am
I would like to hook into this question, however perhaps rephrase it from a
I know this question would have run across in the minds a lot of
I'd like to create a generic class with type parameter T which then creates
Okay, since none of you guys like my question, let me rephrase it. User
Sorry I had to rephrase my question, I have a list preference with some
To rephrase the question: should I avoid sharing instances of classes which implement java.sql.Connection
This is an attempt to rephrase a question I asked earlier. I'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.