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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:10:16+00:00 2026-05-10T17:10:16+00:00

The following simple calculator expression grammar (BNF) can be easily parsed with the a

  • 0

The following simple ‘calculator expression’ grammar (BNF) can be easily parsed with the a trivial recursive-descent parser, which is predictive LL(1):

<expr>      :=  <term> + <term>             |   <term> - <term>             |   <term> <term>      :=  <factor> * <factor>                 <factor> / <factor>                 <factor> <factor>    :=  <number>             |   <id>             |   ( <expr> ) <number>    :=  \d+ <id>        :=  [a-zA-Z_]\w+ 

Because it is always enough to see the next token in order to know the rule to pick. However, suppose that I add the following rule:

<command>   :=  <expr>             |   <id> = <expr> 

For the purpose of interacting with the calculator on the command line, with variables, like this:

calc> 5+5 => 10 calc> x = 8 calc> 6 * x + 1 => 49 

Is it true that I can not use a simple LL(1) predictive parser to parse <command> rules ? I tried to write the parser for it, but it seems that I need to know more tokens forward. Is the solution to use backtracking, or can I just implement LL(2) and always look two tokens forward ?

How to RD parser generators handle this problem (ANTLR, for instance)?

  • 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. 2026-05-10T17:10:16+00:00Added an answer on May 10, 2026 at 5:10 pm

    THe problem with

    <command>   :=  <expr>             |   <id> = <expr> 

    is that when you ‘see’ <id> you can’t tell if it’s the beginning of an assignement (second rule) or it’s a ‘<factor>‘. You will only know when you’ll read the next token.

    AFAIK ANTLR is LL(*) (and is also able to generate rat-pack parsers if I’m not mistaken) so it will probably handle this grammare considering two tokens at once.

    If you can play with the grammar I would suggest to either add a keyword for the assignment (e.g. let x = 8) :

    <command>   :=  <expr>             |   'let' <id> '=' <expr> 

    or use the = to signify evaluation:

    <command>   :=  '=' <expr>             |   <id> '=' <expr> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • 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
  • added an answer Seems like the issue with the missing namespace prefix for… May 11, 2026 at 1:57 pm
  • added an answer You might want to take a look here and here:… May 11, 2026 at 1:57 pm
  • added an answer Levenshtein Python extension and C library. https://github.com/ztane/python-Levenshtein/ The Levenshtein Python… May 11, 2026 at 1:57 pm

Related Questions

Given the following simple example: List<string> list = new List<string>() { One, Two, Three,
Consider the following simple C program that read a file into a buffer and
I have written the following simple test in trying to learn Castle Windsor's Fluent
We have the following simple Stored Procedure that runs as an overnight SQL server
Some background information, for a homework assignment I had to write a polish notation
The more and more advanced compilers, languages, and frameworks we have that either automate
I have a very simple Java RMI Server that looks like the following: import
Try the following simple example: <html> <head> <style> div, input { border: 1px solid

Trending Tags

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

Top Members

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.