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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:16:05+00:00 2026-05-17T01:16:05+00:00

I’ve got a simple grammar. Actually, the grammar I’m using is more complex, but

  • 0

I’ve got a simple grammar. Actually, the grammar I’m using is more complex, but this is the smallest subset that illustrates my question.

Expr ::= Value Suffix
       | "(" Expr ")" Suffix

Suffix ::= "->" Expr
         | "<-" Expr
         | Expr
         | epsilon

Value matches identifiers, strings, numbers, et cetera. The Suffix rule is there to eliminate left-recursion. This matches expressions such as:

a -> b (c -> (d) (e))

That is, a graph where a goes to both b and the result of (c -> (d) (e)), and c goes to d and e. I’m trying to produce an abstract syntax tree for these expressions, but I’m running into difficulty because all of the operators can accept any number of operands on each side. I’d rather keep the logic for producing the AST within the recursive descent parsing methods, since it avoids having to duplicate the logic of extracting an expression. My current strategy is as follows:

  1. If a Value appears, push it to the output.

  2. If a From or To appears:

    1. Output a separator.

    2. Get the next Expr.

    3. Create a Link node.

    4. Pop the first set of operands from output into the Link until a separator appears.

    5. Erase the separator discovered.

    6. Pop the second set of operands into the Link until a separator.

    7. Push the Link to the output.

If I run this through without obeying steps 2.3–2.7, I get a list of values and separators. For the expression quoted above, a -> b (c -> (d) (e)), the output should be:

A sep_1 B sep_2 C sep_3 D E

Applying the To rule would then yield:

A sep_1 B sep_2 (link from C to {D, E})

And subsequently:

(link from A to {B, (link from C to {D, E})})

The important thing to note is that sep_2, crucial to delimit the left-hand operands of the second ->, does not appear, so the parser believes that the expression was actually written:

a -> (b c -> (d) (e))

In order to solve this with my current strategy, I would need a way to produce a separator between adjacent expressions, but only if the current expression is a From or To expression enclosed in parentheses. If that’s possible, then I’m just not seeing it and the answer ought to be simple. If there’s a better way to go about this, however, then please let me know!

  • 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-17T01:16:06+00:00Added an answer on May 17, 2026 at 1:16 am

    I haven’t tried to analyze it in detail, but: “From or To expression enclosed in parentheses” starts to sound a lot like “context dependent”, which recursive descent can’t handle directly. To avoid context dependence you’ll probably need a separate production for a From or To in parentheses vs. a From or To without the parens.

    Edit: Though it may be too late to do any good, if my understanding of what you want to match is correct, I think I’d write it more like this:

    Graph := 
           | List Sep Graph
           ;
    
    Sep := "->"
         | "<-"
         ;
    
    List :=
          | Value List
          ;
    
    Value := Number 
          | Identifier 
          | String 
          | '(' Graph ')'
          ;
    

    It’s hard to be certain, but I think this should at least be close to matching (only) the inputs you want, and should make it reasonably easy to generate an AST that reflects the input correctly.

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

Sidebar

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.