Explain if the CFG is recognized by Non-deterministic push down automata
Context Free Grammars (CFG) are definitely recognized by Non-deterministic push down automata (NPDA), but Programming languages are translated to binary (Machine Code) via Deterministic PDA.
This is because it has the following below mentioned impacts −
- If Programming languages were supposed to be translated via NPDA then for one given program instance we will have multiple versions of binary(Machine code) generated for the same program, which ideally shouldn't be the scenario.
- For a given program only 1 version of binary code should be generated and that should remain consistent across all OS Platforms.
- Outputs will vary significantly: If we have multiple object files, then in 1 case output may be as expected, and on running the program again the outputs will differ since due to NPDA the process of compilation is changing and hence the object code generation also changed. So outputs are varying and in many cases it will result in wrong output.
- Multiple interpretation of syntax may lead to infinite loops: Consider a scenario where we have a loop body with terminating criteria. Via multiple ways of compilation, many keywords may be interpreted wrongly and this may lead to infinite loops if proper termination criteria are not evaluated. For example, for loop (i = 0; i< n ; i++), if that gets compiled as (i = n; i >0; i++), this will result in an infinite loop.
- Hard to debug − Due to multiple versions of object files being generated due to the
NPDA process, we will find it hard to debug bugs in the code to fix them.
Published on 16-Jun-2021 12:27:41