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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:29:37+00:00 2026-05-26T00:29:37+00:00

Generally DFA’s are used to check, whether given string is present in a certain

  • 0

Generally DFA’s are used to check, whether given string is present in a certain language.
e.g _ab1c is present in the Language of variables in C.

What I am doing?
But as stated in this question,I am using DFA to trace all comments,strings etc.

How I am doing?
Consider an example of tracing a //comments in a given string/program.

static int makeTransition[][] = {
        /*     Transition Table        */
              /*{other,\n, \, /, *, ', "}  */  
            /*q0*/ { 0, 0, 0, 1, 0, 0, 0},
            /*q1*/ { 0, 0,-1, 2, 0, 0, 0},
            /*q2*/ { 2, 0, 2, 2, 2, 2, 2},
        };

For this, If I have,

void assignPointerValuesInPairs(int index) 
    {
/*comments is an ArrayList
before marking start hotpointer = -1
after marking start hotpointer = 0
after marking end hotpointer is resetted to -1*/
        switch(currentState)
            {   
            case 2:     /*q2*/
                      comments.add(/*mark start*/);
                      hotPointer = 0;
                      break;
            case 0:    /*On initial state q0*/
                switch(hotPointer)
                {
                case 0: //If I am in end of comment.
                    comments.add(/*mark end*/);                            
                     hotPointer = -1; //Resetting the hotPointer.
                             break;

                case -1: /*Already in q1 only*/
                    /*Do nothing*/
                }
        }
     }

 public static void traceOut(String s) //entire program is accepted as string.
    {
            int index = 0;
        while (index < s.length() ) {                
                      char c = s.charAt(index);
                      try{
             currentState = makeTransition[currentState][symbolToInteger(c)];
              if(currentState == -1)
              throw new InvalidSyntaxException();
                  }
              catch(InvalidSyntaxException e){
              currentState = 0;
              invalidSyntax.add(index);                      
              }
                assignPointerValuesInPairs(index);
                index++;    
            }
                
                
                
                currentState = 0;
                assignPointerValuesInPairs(index);  //These 2 statements help to color while typing.. (i.e) It forces the current state to get finished abruptly.   
      }

}

My Question is…

can I use the DFA, to mark the end and start of the //comment in this way,
or I have to follow some other way like CFG etc..

i.e

My Statement: I can use DFA, not only to check for a particular language also to
trace out certain strings belong to certain languages in a given
string. (proof : by above method).

Does my above statement correct?

  • 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-26T00:29:37+00:00Added an answer on May 26, 2026 at 12:29 am

    My Statement: I can use DFA, not only to check for a particular language also to trace out certain strings belong to certain languages in a given string.

    Does my above statement correct?

    Your statement is trivially correct. Certain languages can be checked using DFAs.
    (The proof is by existence. If any such language exists, then your statement is true. And the language

            <program> ::= 'A'
    

    is a trivial example to satisfy the existence proof.)

    But this is not a particularly useful statement, because it says nothing about what kind of languages can be checked using a DFA.

    For example, if your comment language supported nesting of comment blocks (as some historical programming languages have done), then a DFA won’t work.

    A second point that your statement ignores is whether use of a DFA is practical for a given language. For a language with bounds on all forms of nesting / recursion in the grammar, etc you could in theory translate the grammar into a single finite DFA. However the DFA would be so large that it would be unimplementable.

    (Aside – no modern programming language has such bounds at the grammatical level … not that this question is exclusively about programming languages.)

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

Sidebar

Related Questions

Generally when I use ClickOnce when I build a VB.NET program but it has
Generally I seem to be able to fix IE problems nowadays.. but this one
Generally, final static members especially, variables (or static final of course, they can be
Generally, welcome file lists are used to show first page of application. What if,
Generally I've no complaints about the speed of Visual Studio, but if I write
Generally speaking, I'm a decent programmer, (C++, Java, Ruby, Python) but I at the
I generally use Subclipse, but there's some wonkiness in my code right now and
Generally I use lxml for my HTML parsing needs, but that isn't available on
Generally I work with CSV files but for this project I need to support
I generally check if obj.pk to knwo if the objects is saved. This wont

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.