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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:44:01+00:00 2026-06-06T03:44:01+00:00

I need to get the delta function of a non-deterministic pushdown automaton from a

  • 0

I need to get the delta function of a non-deterministic pushdown automaton from a context-free grammar in DCG form, and the algorithm for doing this is very simple:


For every rule A --> B in the grammar, add a transition [q1, lambda, A] --> [B] to the delta function.

For every rule E --> c in the grammar, add a transition [q1, c, c] --> [lambda] to the delta function.

Add the transitions [q0, lambda, z0] --> [q1, S*z0] and [q1, lambda, z0] --> [q2, z0] to the delta function.

Every uppercase letter is a non-terminal symbol, and every lowercase letter is a terminal symbol. lambda is the empty string, S is the initial symbol of the grammar, * is the concatenation operator and z0 is the symbol on the top of the stack.


This means the grammar

S --> A*b | B | y
A --> w*x | x
B --> A*b

generates a pushdown automaton with the delta function

[q0, lambda, z0] --> [q1, S*z0]
[q1, lambda, S] --> [q1, A*b]
[q1, lambda, S] --> [q1, B]
[q1, lambda, S] --> [q1, y]
[q1, lambda, A] --> [q1, w*x]
[q1, lambda, A] --> [q1, x]
[q1, lambda, B] --> [q1, A*b]
[q1, b, b] --> [q1, lambda]
[q1, w, w] --> [q1, lambda]
[q1, x, x] --> [q1, lambda]
[q1, y, y] --> [q1, lambda]
[q1, lambda, z0] --> [q2, z0]

I have to implement this algorithm in Prolog (getting a grammar from user and returning the delta function) and I’m confused because this is my first time using a logic programming language.

I thought I could maybe translate the grammar into its predicate form and then “iterating” over all the predicates, and somehow adding the already “traversed” predicates to a list, so I can process this list and return the delta function. But I think this is some sort of really complicated imperative way of doing things and using Prolog for this would be pointless.

Maybe there’s a more elegant solution for this problem, so I’d like to know if such solution exists.

  • 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-06T03:44:03+00:00Added an answer on June 6, 2026 at 3:44 am

    Here a possible coding

    g2nfa(Grammar, Delta) :-
        maplist(transitions, Grammar, DeltaT),
        append(DeltaT, DeltaF),
        Initial = (q0, lambda, z0 --> q1, 'S'*z0),
        Final = (q1, lambda, z0 --> q2, z0),
        append([[Initial], DeltaF, [Final]], Delta).
    
    transitions(Sym --> Alternatives, Transitions) :-
        phrase(transition(Sym, Alternatives), Transitions).
    
    transition(Sym, A|As) --> state(Sym, A), !, transition(Sym, As).
    transition(Sym, A) --> state(Sym, A).
    state(Sym, A) --> [(q1, lambda, Sym --> q1, A)].
    
    test :-
        g2nfa([( 'S' --> 'A'*b | 'B' | y ),
               ( 'A' --> w*x | x ),
               ( 'B' --> 'A'*b )
              ], T), maplist(writeln, T).
    

    that seems to satisfy your requirements

    ?- test.
    q0,lambda,z0-->q1,S*z0
    q1,lambda,S-->q1,A*b
    q1,lambda,S-->q1,B
    q1,lambda,S-->q1,y
    q1,lambda,A-->q1,w*x
    q1,lambda,A-->q1,x
    q1,lambda,B-->q1,A*b
    q1,lambda,z0-->q2,z0
    true.
    

    so you can work out the syntactic details. Note that the second rewrite rule (For every rule E –> c in the grammar, add a transition [q1, c, c] –> [lambda] to the delta function.) has not been applied in your sample.

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

Sidebar

Related Questions

I need get documents from db by oid, like: Docs.objects(_id='4f4381f4e779897a2c000009') But how to do
I need to get the revision number from TFS, if i run tf.exe from
I need to get the distinct row values from a table using LINQ. The
I get some GPS coordinates from Google Maps and I need to find the
I have this string (Java 1.5): :alpha;beta:gamma;delta I need to get an array: {:alpha,
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I need get all items these have no categories int? categoryId = null; var
I have two tables with a weak relation. I need get a text value
Need to get the 10 word before and 10 words after for the given
Need to get an div with overflow:hidden; not to wrap its children. I need

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.