0

In the university they ask me for use grammar and Pushdown automaton to check the syntax of a portion of Java code. Due i have not used this automaton before, i have learnt a bit about how they work and i think that this automaton is not very useful in the check of code syntax because the pushdown automaton is used to verify a grammar with some proportion between any token like "0^n 1^2n | n >= 0".

This proportions between tokens are not present in code syntax, therefore i think that the pushdown automaton is not useful in this case.

  • I'm right?
  • do i have to complain about this work they ask me for?

1 Answers1

0

Nondeterministic Push Down Acceptors(NPDA) and Context Free Grammars(CFG) have the same power in representing languages.

As most(if not all) of a programming language (like java) syntax can be presented by a CFG, it can be presented by an NPDA too.

So, no complain, do the assignment.

Hassan Abbasi
  • 272
  • 1
  • 3
  • Thanks for the answer but how could you use the stack in a grammar that is completely lineal? I mean, in the syntax of a code line there is no need to use the stack because the amount of tokens have no relation. Could you make an pushdown acceptor for this code line "int var = 25 + x"? – vanillaHoman Oct 27 '16 at 12:45