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

  • Home
  • SEARCH
  • 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 4337232
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:54:57+00:00 2026-05-21T10:54:57+00:00

I’m currently writing my own parser for a fictional Assembly language. The instructions are

  • 0

I’m currently writing my own parser for a fictional Assembly language. The instructions are very similar to any normal assembly instruction:

[INSTRUCTION] [OP]*

where op can be 0-3 operands. I want to be able to use an expression that matches this. This is being written in C++ with boost::regex. I myself am a regexp noobie, trying to understand the boost documentation of what each symbol does.

Now, I already have an expression that can match 0-3 operands like so:

Sample Instructions:
    MOVI 8 10
    ADDI 8 8 10
    NOP
    BNEZI -1

Expression: ^([a-z]+)( ([-,0-9]+))*

However, I can’t create a suitable expression that handles the same instructions when comma-delimited:

Sample Instructions:
    MOVI 8, 10
    ADDI 8, 8, 10

This is really tripping me up. I tried rewriting my expression like so:

^([a-z]+)( ([-,0-9]+))*(, ([-,0-9]+))*

This looks to be extremely green, poor regexp. It also isn’t working correctly. I was thinking of using a recursive expression, but I looked at the documentation and I might as well scribble “overkill” on my forehead.

I realize I could just format the line to take out all the commas, but I would rather like to be able to write and understand a regexp expression first, then do it the easy way. Any help would be appreciated.

  • 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-21T10:54:58+00:00Added an answer on May 21, 2026 at 10:54 am

    A string like:

    ADDI 8, 8, 10
    

    can be matched by a regex like this:

    [a-zA-Z]+[ \t]+-?[0-9]+([ \t]*,[ \t]*-?[0-9]+)*
    

    A (short) explanation:

    [a-zA-Z]+   # match an instruction
    [ \t]+      # match one or more spaces or tabs
    -?[0-9]+    # match an integer value with an option minus sign in front of it
    (           # open group 1
      [ \t]*    #   match zero or more spaces or tabs
      ,         #   match a comma
      [ \t]*    #   match zero or more spaces or tabs
      -?[0-9]+  #   match an integer value with an option minus sign in front of it
    )*          # close group 1, and repeat it zero or more times
    

    Having said all that, I must agree with dmckee’s comment: a proper parser is the way to go, even if this is just a fictional language you’re parsing.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string
I am writing an app with both english and french support. The app requests
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.