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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:41:10+00:00 2026-05-25T00:41:10+00:00

I am reading this bison introduction. I have two questions and it will be

  • 0

I am reading this bison introduction.

I have two questions and it will be great if someone can help me understand:

  1. What does term context free grammar mean?

  2. From the link above: Not all context-free languages can be handled by Bison, only those that are LALR(1). In brief, this means that it must be possible to tell how to parse any portion of an input string with just a single token of look-ahead. What does it mean by “possible to tell how to parse any portion of an input string with just a single token of look-ahead`”

  • 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-25T00:41:10+00:00Added an answer on May 25, 2026 at 12:41 am

    A context-free grammar is a description of a set of strings that is strictly more powerful than the regular expressions, but still easily handled by a machine. More formally, a context-free grammar consists of four things:

    • A set of terminal symbols, which are the elements of the strings being produced. For a bison parser, this is typically the set of the tokens produced by the scanner. For a grammar for a natural language like English, this might be the set of all English words.

    • A set of nonterminal symbols. Intuitively, a nonterminal symbol represents something like a part of speech, such as “noun” or “verb.”

    • A set of productions. Each production says how to replace a nonterminal symbol with some other set of terminals and nonterminals. For example, the production Variable -> Type Name says that if we see the nonterminal Variable, we may replace it with the string Type Name.

    • A start symbol, which is the nonterminal from which the derivation begins.

    As an example, consider this simple context-free grammar for C-style function declarations:

    Function -> Type ident(Arguments)
    Type -> int
    Type -> Type *
    Arguments -> e   (the empty string)
    Arguments -> ArgList
    ArgList -> Type ident
    ArgList -> Type ident, ArgList
    

    Here, the start symbol is Function. Given this grammar, we can produce C-style function declarations by repeatedly picking a nonterminal symbol and replacing it with one of the right-hand sides of a matching production. At each step, the string we’ve built so far is called a sentential form. For example, here are some different function declarations that can be derived from the above grammar:

    Sentential Form                       Production
    -------------------------------------------------------------------
    Function                              Function -> Type ident(Arguments)
    Type ident(Arguments)                 Type -> int
    int ident(Arguments)                  Arguments -> e
    int ident()
    
    Sentential Form                       Production
    -------------------------------------------------------------------
    Function                              Function -> Type ident(Arguments)
    Type ident(Arguments)                 Type -> Type*
    Type* ident(Arguments)                Type -> int
    int* ident(Arguments)                 Arguments -> ArgList
    int* ident(ArgList)                   ArgList -> Type ident, ArgList
    int* ident(Type ident, ArgList)       ArgList -> Type ident
    int* ident(Type ident, Type ident)    Type -> Type*
    int* ident(Type* ident, Type ident)   Type -> Type*
    int* ident(Type** ident, Type ident)  Type -> int
    int* ident(int** ident, Type ident)   Type -> int
    int* ident(int** ident, int ident)
    

    Most programming languages have a structure that can be described by a context-free grammar. The job of the parser is to take a program and a grammar and to determine how that program can be generated by the grammar.

    As for LALR(1), unfortunately the formal definition of LALR(1) is not trivial. I just finished teaching a compiler construction course and we were only able to talk about LALR(1) after first spending two lectures discussing related parsing techniques. If you’d like a formal introduction to the material, my slides on bottom-up parsing are available at the course website.

    LALR(1) is a type of parsing algorithm called a bottom-up parsing algorithm, which means that it tries to apply the productions of the grammar in reverse order to reduce the program back to the start symbol. For example, let’s consider this string, which is generated by the above grammar:

    int** ident(int* ident)
    

    In a bottom-up parse, we would parse this string by looking at the program one token at a time. Whenever we found something that could be reversed back to some nonterminal, we do so. (To be more precise, LALR(1) only does these sorts of reductions when other criteria are met as well so that the algorithm has more context, but for this example we don’t need to worry about this). Each step in the parse is said either to be a shift or a reduce. A shift means that we look at one more token of the input to gain more information about what reductions to apply. A reduce means that we take some number of the tokens and nonterminals and reverse a production to get back to some nonterminal.

    Here’s a trace of the bottom-up parse of the string:

    Workspace           Input                     Action
    -----------------------------------------------------------------
                 int** ident(int* ident)   Shift
    int             ** ident(int* ident)   Reduce Type -> int
    Type            ** ident(int* ident)   Shift
    Type*            * ident(int* ident)   Reduce Type -> Type*
    Type             * ident(int* ident)   Shift
    Type*              ident(int* ident)   Reduce Type -> Type*
    Type               ident(int* ident)   Shift
    Type ident              (int* ident)   Shift
    Type ident(              int* ident)   Shift
    Type ident(int              * ident)   Reduce Type -> int
    Type ident(Type             * ident)   Shift
    Type ident(Type*              ident)   Reduce Type -> Type*
    Type ident(Type               ident)   Shift
    Type ident(Type ident              )   Reduce ArgList -> Type ident
    Type ident(ArgList                 )   Reduce Arguments -> ArgList
    Type ident(Arguments               )   Shift
    Type ident(Arguments)                  Reduce Function -> Type ident(Arguments)
    Function                               ACCEPT
    

    It’s important to know about shifts and reductions because you will invariable encounter shift/reduce conflicts and reduce/reduce conflicts when using bison. These errors mean that the parser generator determined that the parser might get into a state where it can’t tell whether to shift or reduce, or which of two reductions it’s supposed to perform. Consult the bison manual for more details about how to deal with this.

    If you’d like to learn more about context-free grammars and parsing algorithms in general, there is an excellent book entitled Parsing Techniques: A Practical Guide, Second Edition by Grune and Jacobs that has, by far, the best treatment of the material I’ve ever seen. It covers all sorts of parsing algorithms, including many techniques that are substantially more powerful than LALR(1) that are starting to get wider usage (GLR and Earley, for example). I highly recommend this book – it’s the main reason I understand parsing so well!

    Hope this helps!

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

Sidebar

Related Questions

after reading this question i wonder if someone can help me understand how to
Reading this MSDN article titled Working with ObjectSet (Entity Framework) It shows two examples
Reading this question got me thinking: For a given function f , how can
Reading this page http://code.google.com/p/closure-stylesheets/ , I can't seem to find any documentation explaining how
In reading this and this and then reading this (which references the other two
After reading this SE Discussion a question pops up. Why jquery defined two methods
Reading this: http://guides.rubyonrails.org/routing.html#adding-more-restful-actions What does it mean to add a 'member route'? or do
Reading this question , a doubt popped into my head: char and varchar can
Reading this zero copy article , Does Zero-copy exist in Windows OS (server 2003,
Reading this blog post it mentions you can get your DI container to automatically

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.