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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:05:29+00:00 2026-06-01T11:05:29+00:00

I have a practice exam for my compilers course with the following questions that

  • 0

I have a practice exam for my compilers course with the following questions that I can’t get:

  1. Why can’t we use a context-free grammer (CFG) to scan/tokenize?
  2. Why don’t we use a deterministic finite automaton (DFA) for parsing?

Does anyone have any ideas?

  • 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-01T11:05:31+00:00Added an answer on June 1, 2026 at 11:05 am

    Both of these statements are incorrect.

    You absolutely can use a CFG to do scanning and tokenization. In fact, every regular language is also context-free, so you could rewrite your scanner to scan using a context-free grammar instead of a regular expression. The main reason for not doing this is that it’s usually overkill; tokens rarely have a complex structure to them, and a regular expression usually works just fine. However, you can think of instances where you might want to use a CFG. For example, in C++, the treatment of close angle braces in templates often requires special-casing by the compiler. For example, vector<vector<int>> should tokenize as vector < vector < int > >, though using a standard set of regular expressions the two closing braces would be scanned as the >> token. Using a context-free grammar to do scanning could alleviate this by having more context.

    Also, you absolutely can use regular expressions for parsing, provided that your language is sufficiently simple. Most languages are too complex to be encoded with a regular expression (for example, anything involving nested parentheses cannot be parsed with regular expressions), so we tend to use CFGs instead, but there are languages that could be parsed with regular expressions. For example, a description of a DFA as a table like this one could definitely be parsed by a regular expression:

         0    1
     q0  q1   q0
     q1  q0   q1
    

    Most real programming languages don’t have a regular structure, though, and so in practice context-free grammars are used instead.

    Hope this helps!

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

Sidebar

Related Questions

I have the following code which has two fields that are queried. How can
I have some practice exam questions and answers which are as follows: However, I
So I'm working on some code (going over a practice exam for a course
Well, this is another question taken from this practice exam that was given to
I have written a practice code for a 'battle' that allows you to select
I have a two part question Best-Practice I have an algorithm that performs some
Is it good practice to have a class constructor that uses default parameters, or
I read that a good practice have entities light, only getters and setters. But
Is it good practice to have a link that just exists for its tooltip?
I'm reviewing for an exam, one of the practice questions is as follows: give

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.