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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:22:39+00:00 2026-05-15T23:22:39+00:00

This is a follow up question from Grammar: difference between a top down and

  • 0

This is a follow up question from Grammar: difference between a top down and bottom up?

I understand from that question that:

  • the grammar itself isn’t top-down or bottom-up, the parser is
  • there are grammars that can be parsed by one but not the other
  • (thanks Jerry Coffin

So for this grammar (all possible mathematical formulas):

    E -> E T E
    E -> (E)
    E -> D

    T -> + | - | * | /

    D -> 0
    D -> L G

    G -> G G    
    G -> 0 | L

    L -> 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 

Would this be readable by a top down and bottom up parser?

Could you say that this is a top down grammar or a bottom up grammar (or neither)?


I am asking because I have a homework question that asks:

“Write top-down and bottom-up grammars for the language consisting of all …” (different question)

I am not sure if this can be correct since it appears that there is no such thing as a top-down and bottom-up grammar. Could anyone clarify?

  • 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-15T23:22:40+00:00Added an answer on May 15, 2026 at 11:22 pm

    That grammar is stupid, since it unites lexing and parsing as one. But ok, it’s an academic example.

    The thing with bottoms-up and top-down is that is has special corner cases that are difficult to implement with you normal 1 look ahead. I probably think that you should check if it has any problems and change the grammar.

    To understand you grammar I wrote a proper EBNF

    expr:
        expr op expr |
        '(' expr ')' |
        number;
    
    op:
        '+' |
        '-' |
        '*' |
        '/';
    
    number:
        '0' |
        digit digits;
    
    digits:
        '0' |
        digit |
        digits digits;
    
    digit:
        '1' | 
        '2' | 
        '3' | 
        '4' | 
        '5' | 
        '6' | 
        '7' | 
        '8' | 
        '9'; 
    

    I especially don’t like the rule digits: digits digits. It is unclear where the first digits starts and the second ends. I would implement the rule as

    digits:
        '0' |
        digit |
        digits digit;
    

    An other problem is number: '0' | digit digits; This conflicts with digits: '0' and digits: digit;. As a matter of fact that is duplicated. I would change the rules to (removing digits):

    number:
        '0' |
        digit |
        digit zero_digits;
    
    zero_digits:
        zero_digit |
        zero_digits zero_digit;
    
    zero_digit:
        '0' |
        digit;
    

    This makes the grammar LR1 (left recursive with one look ahead) and context free. This is what you would normally give to a parser generator such as bison. And since bison is bottoms up, this is a valid input for a bottoms-up parser.

    For a top-down approach, at least for recursive decent, left recursive is a bit of a problem. You can use roll back, if you like but for these you want a RR1 (right recursive one look ahead) grammar. To do that swap the recursions:

    zero_digits:
        zero_digit |
        zero_digit zero_digits;
    

    I am not sure if that answers you question. I think the question is badly formulated and misleading; and I write parsers for a living…

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

Sidebar

Ask A Question

Stats

  • Questions 523k
  • Answers 523k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Go with calculation on the client. Almost certainly the calculation… May 16, 2026 at 9:35 pm
  • Editorial Team
    Editorial Team added an answer First step : btn.hidden = YES Then you have to… May 16, 2026 at 9:35 pm
  • Editorial Team
    Editorial Team added an answer You can map AWS S3 directory to your local using… May 16, 2026 at 9:35 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

This is a follow-on question from the one I asked here . Can constraints
This is a follow on question from my previously answered question here: Reading characters
This is a follow up question from a previous SO question . Now I
This is a follow up question from Problem with array assignment I now have
this is a follow up question from this one , I don't want to
I'd like to generate completely random piece of html source, possibly from a grammar.
This is continuing questions from Selecting the highest salary Assuming a table ' wagetable
I want a TreeView with checkboxes and I'm trying to follow this tutorial .
Is there a simple way to determine whether a grammar is LL(1), LR(0), SLR(1)...
From PHP, I'm having trouble getting the browser to delete a cookie. To chase

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.