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 8604945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:42:09+00:00 2026-06-12T02:42:09+00:00

I am writing a flex parser for gawk scripts. I am running into a

  • 0

I am writing a flex parser for gawk scripts. I am running into a problem differentiating between uses for a forward slash (/) character.

Obviously, a single / would be an operator for division, but two slashes could be both a regular expression or division. Right now, it parses

int((r-1)/3)*3+int((c-1)/3)+1

as having the regular expression

/3)*3+int((c-1)/

instead of the intended division operations. How do I get flex to recognize it as a mathematical expression?

Right now, this is my flex regular expression to recognize regular expressions in gawk:

EXT_REG_EXP "\/"("\\\/"|[^\/\n])*"\/"

and the division operator should be caught by my list of operators:

OPERATOR "+"|"-"|"*"|"/"|"%"|"^"|"!"|">"|"<"|"|"|"?"|":"|"~"|"$"|"="

But since the flex regular expressions are greedy I guess it treats two divisions as a regular expression.

  • 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-06-12T02:42:10+00:00Added an answer on June 12, 2026 at 2:42 am

    I don’t think it’s possible to define a simple token expression to unambiguously identify regular expressions. The Posix spec for Awk notes the ambiguity thusly:

    In some contexts, a slash ( ‘/’ ) that is used to surround an ERE
    could also be the division operator. This shall be resolved in such a
    way that wherever the division operator could appear, a slash is
    assumed to be the division operator. (There is no unary division
    operator.)

    And later:

    There is a lexical ambiguity between the token ERE and the tokens ‘/’
    and DIV_ASSIGN. When an input sequence begins with a slash character
    in any syntactic context where the token ‘/’ or DIV_ASSIGN could
    appear as the next token in a valid program, the longer of those two
    tokens that can be recognized shall be recognized. In any other
    syntactic context where the token ERE could appear as the next token
    in a valid program, the token ERE shall be recognized.

    (“ERE” stands for “extended regular expression.”) From this, I think you can safely conclude that a tokenizer for Awk has to be aware of the syntactic context, and hence there is no possible regular expression that could successfully identify regular expression tokens.

    It’s also worth looking at how Awk itself (or at least one of the implementations) is defined to parse regexes. In the original Awk (sometimes called the One True Awk), identifying regular expressions is the job of the parser, which explicitly sets the lexer into “regex mode” when it has figured out that it should expect to read a regex:

    reg_expr:
          '/' {startreg();} REGEXPR '/'     { $$ = $3; }
        ;
    

    (startreg() is a function defined in lex.c.) The reg_expr rule itself is only ever matched in contexts where a division operator would be invalid.

    Sorry to disappoint, but I hope this helps nonetheless.

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

Sidebar

Related Questions

I am writing a business app in Flex that uses web services to communicate
I'm writing a Python parser to learn Flex and Bison, and I'm trying to
I'm writing a Bison/Flex program to convert LaTeX into MathML. At the moment, dealing
I am writing a desktop application and trying to decide between using AIR (FLex)
I'm writing up a small parser which parses constraints, using Flex and Lemon. Lemon
We have a large, multi-module product we are writing in Flex 4.1 running on
I am writing a parser with flex and bison and so far have these
I'm writing a Flex application and I came across what I think is a
I'm writing a custom flex file to generate a lexer for use with JSyntaxpane.
I am writing a custom flex preloader which extends the IPreloaderDisplay class. How can

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.