'YACC Parser Doesn't want to print Accpeted even though the input is right?

This program rules doesn't work on "zero one one" input why?

SS: S { printf("Accepted"); }
;
S: zero T one T one
;
T :  one T |
;


Solution 1:[1]

I tried running your grammar through Bison, and it produced two warnings:

warning: 3 shift/reduce conflicts [-Wconflicts-sr]
warning: rule useless in parser due to conflicts [-Wother]

The second warning applies to the production T : %empty which is the second alternative for T.

Although described as warnings, these messages almost always indicate a problem with your grammar, so they should be addressed (or at least mentioned if you're asking why your grammar doesn't work).

The shift-reduce conflict is to be expected. When the parser has seen a zero, it's in the state (• indicates the current parse position):

S : zero • T one T one

At this point, it has to decide whether the first or second production for T should apply. The second production involves immediately reducing T with an empty match. The first production involves shifting one as the first token in a new T.

The parser cannot tell which of these alternatives apply because in both cases the next token will be one. For shift actions, an LR parser doesn't need to make a decision; it can explore two different shift actions in parallel. But reductions need to be taken immediately or never; the terminal must be recognised when it ends. (For empty reductions, that's right away. But the fact that the reduction is empty doesn't stop it from having to be recognised.)

When Bison can't figure out what the parser should do in a given state, it reports a conflict and then uses a simple default strategy: prefer shift. Thus, the reduction of the empty T is removed from the grammar (which Bison also warned you about). Without that reduction, the parse can never terminate. Each one starts a new T, until the end of the input is reached. At that point, nothing more can be done (since the reduction was removed from the grammar) and the parser reports a syntax error.

Since I have no idea what sentences you expect to be able to recognise, I can't really offer you any good advice about how to fix the grammar.

Solution 2:[2]

  • Your error is a system error "oracle_lib/instantclient_21_4/libclntsh.so: file too short" that is wrapped in the DPI message. It looks like you have some file corruption or other OS error. How is Instant Client getting installed? Does SQL*Plus work?

  • With Instant Client don't set ORACLE_HOME

  • On Linux, the only effect of cx_Oracle.init_oracle_client(lib_dir="oracle_lib/instantclient_21_4") is to immediately load libraries. You still need to make sure that those libraries are in the system library search path (e.g LD_LIBRARY_PATH, or via ldconfig) before the process starts. But make sure you are passing the same directory as used in the system search path otherwise you might get odd behavior or errors.

  • cx_Oracle.init_oracle_client(config_dir="oracle_config/Wallet_pricedb") internally sets TNS_ADMIN so it will override any value of the variable

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rici
Solution 2 Christopher Jones