/[svn]/linuxsampler/trunk/src/network/lscp.y
ViewVC logotype

Diff of /linuxsampler/trunk/src/network/lscp.y

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2514 by schoenebeck, Thu Jan 23 04:00:26 2014 UTC revision 2515 by schoenebeck, Wed Feb 5 20:45:18 2014 UTC
# Line 36  Line 36 
36  #include "lscpevent.h"  #include "lscpevent.h"
37  #include "lscpsymbols.h"  #include "lscpsymbols.h"
38  #include <algorithm>  #include <algorithm>
39    #include "lscp.h"
40    
41  namespace LinuxSampler {  namespace LinuxSampler {
42    
# Line 428  set_instruction       :  AUDIO_OUTPUT_DE Line 429  set_instruction       :  AUDIO_OUTPUT_DE
429                        |  DB_INSTRUMENT SP DESCRIPTION SP db_path SP stringval_escaped                     { $$ = LSCPSERVER->SetDbInstrumentDescription($5,$7);              }                        |  DB_INSTRUMENT SP DESCRIPTION SP db_path SP stringval_escaped                     { $$ = LSCPSERVER->SetDbInstrumentDescription($5,$7);              }
430                        |  DB_INSTRUMENT SP FILE_PATH SP filename SP filename                               { $$ = LSCPSERVER->SetDbInstrumentFilePath($5,$7);                 }                        |  DB_INSTRUMENT SP FILE_PATH SP filename SP filename                               { $$ = LSCPSERVER->SetDbInstrumentFilePath($5,$7);                 }
431                        |  ECHO SP boolean                                                                  { $$ = LSCPSERVER->SetEcho((yyparse_param_t*) yyparse_param, $3);  }                        |  ECHO SP boolean                                                                  { $$ = LSCPSERVER->SetEcho((yyparse_param_t*) yyparse_param, $3);  }
432                          |  SHELL SP INTERACT SP boolean                                                     { $$ = LSCPSERVER->SetShellInteract((yyparse_param_t*) yyparse_param, $5); }
433                        |  VOLUME SP volume_value                                                           { $$ = LSCPSERVER->SetGlobalVolume($3);                            }                        |  VOLUME SP volume_value                                                           { $$ = LSCPSERVER->SetGlobalVolume($3);                            }
434                        |  VOICES SP number                                                                 { $$ = LSCPSERVER->SetGlobalMaxVoices($3);                         }                        |  VOICES SP number                                                                 { $$ = LSCPSERVER->SetGlobalMaxVoices($3);                         }
435                        |  STREAMS SP number                                                                { $$ = LSCPSERVER->SetGlobalMaxStreams($3);                        }                        |  STREAMS SP number                                                                { $$ = LSCPSERVER->SetGlobalMaxStreams($3);                        }
# Line 920  REMOVE                :  'R''E''M''O''V' Line 922  REMOVE                :  'R''E''M''O''V'
922  SET                   :  'S''E''T'  SET                   :  'S''E''T'
923                        ;                        ;
924    
925    SHELL                 :  'S''H''E''L''L'
926                          ;
927    
928    INTERACT              :  'I''N''T''E''R''A''C''T'
929                          ;
930    
931  APPEND                :  'A''P''P''E''N''D'  APPEND                :  'A''P''P''E''N''D'
932                        ;                        ;
933    
# Line 1372  static void walkAndFillExpectedSymbols(s Line 1380  static void walkAndFillExpectedSymbols(s
1380  #endif  #endif
1381  }  }
1382    
1383    inline static int _yyReduce(std::vector<YYTYPE_INT16>& stack, const int& rule) {
1384        if (stack.empty()) throw 1; // severe error
1385        const int len = yyr2[rule];
1386        stack.resize(stack.size() - len);
1387        YYTYPE_INT16 newState = yypgoto[yyr1[rule] - YYNTOKENS] + stack.back();
1388        if (0 <= newState && newState <= YYLAST && yycheck[newState] == stack.back())
1389            newState = yytable[newState];
1390        else
1391            newState = yydefgoto[yyr1[rule] - YYNTOKENS];
1392        stack.push_back(newState);
1393        return newState;
1394    }
1395    
1396    inline static int _yyDefaultReduce(std::vector<YYTYPE_INT16>& stack) {
1397        if (stack.empty()) throw 2; // severe error
1398        int rule = yydefact[stack.back()];
1399        if (rule <= 0 || rule >= YYNRULES) throw 3; // no rule, something is wrong
1400        return _yyReduce(stack, rule);
1401    }
1402    
1403    #define DEBUG_PUSH_PARSE 0
1404    
1405    static bool yyPushParse(std::vector<YYTYPE_INT16>& stack, char ch) {
1406        startLabel:
1407    
1408    #if DEBUG_PUSH_PARSE
1409        //printf("\n");
1410        //for (int i = 0; i < depth; ++i) printf("\t");
1411        printf("State stack:");
1412        for (int i = 0; i < stack.size(); ++i) {
1413            printf(" %d", stack[i]);
1414        }
1415        printf(" char='%c'(%d)\n", ch, (int)ch);
1416    #endif
1417    
1418        if (stack.empty()) return false;
1419    
1420        int state = stack.back();
1421        int n = yypact[state];
1422        if (n == YYPACT_NINF) { // default reduction required ...
1423    #if DEBUG_PUSH_PARSE
1424            printf("(def reduce 1)\n");
1425    #endif
1426            state = _yyDefaultReduce(stack);
1427            goto startLabel;
1428        }
1429        if (!(YYPACT_NINF < n && n <= YYLAST)) return false;
1430    
1431        YYTYPE_INT16 token = (ch == YYEOF) ? YYEOF : yytranslate[ch];
1432        n += token;
1433        if (n < 0 || YYLAST < n || yycheck[n] != token) {
1434    #if DEBUG_PUSH_PARSE
1435            printf("(def reduce 2) n=%d token=%d\n", n, token);
1436    #endif
1437            state = _yyDefaultReduce(stack);
1438            goto startLabel;
1439        }
1440        int action = yytable[n]; // yytable[yypact[state] + token]
1441        if (action == 0 || action == YYTABLE_NINF) throw 4;
1442        if (action < 0) {
1443    #if DEBUG_PUSH_PARSE
1444            printf("(reduce)\n");
1445    #endif
1446            int rule = -action;
1447            state = _yyReduce(stack, rule);
1448            goto startLabel;
1449        }
1450        if (action == YYFINAL) return true; // final state reached
1451    
1452    #if DEBUG_PUSH_PARSE
1453        printf("(push)\n");
1454    #endif
1455        // push new state
1456        state = action;
1457        stack.push_back(state);
1458        return true;
1459    }
1460    
1461    static bool yyValid(std::vector<YYTYPE_INT16>& stack, char ch) {
1462        try {
1463            return yyPushParse(stack, ch);
1464        } catch (int i) {
1465    #if DEBUG_PUSH_PARSE
1466            printf("exception %d\n", i);
1467    #endif
1468            return false;
1469        } catch (...) {
1470            return false;
1471        }
1472    }
1473    
1474    static int yyValidCharacters(std::vector<YYTYPE_INT16>& stack, const String& line) {
1475        int i;
1476        for (i = 0; i < line.size(); ++i) {
1477            if (!yyValid(stack, line[i])) return i;
1478        }
1479        return i;
1480    }
1481    
1482  /**  /**
1483   * Should only be called on syntax errors: returns a set of non-terminal   * Should only be called on syntax errors: returns a set of non-terminal
1484   * symbols expected to appear now/next, just at the point where the syntax   * symbols expected to appear now/next, just at the point where the syntax
# Line 1395  static std::set<String> yyExpectedSymbol Line 1502  static std::set<String> yyExpectedSymbol
1502    
1503  namespace LinuxSampler {  namespace LinuxSampler {
1504    
1505    String lscpParserProcessShellInteraction(String& line, yyparse_param_t* param) {
1506        std::vector<YYTYPE_INT16> stack;
1507        stack.push_back(0); // every Bison symbol stack starts with zero
1508        String l = line + '\n';
1509        int n = yyValidCharacters(stack, l);
1510        String result = line;
1511        result.insert(n <= result.length() ? n : result.length(), LSCP_SHK_GOOD_FRONT);
1512        int code = (n > line.length()) ? LSCP_SHU_COMPLETE : (n < line.length()) ?
1513                   LSCP_SHU_SYNTAX_ERR : LSCP_SHU_INCOMPLETE;
1514        result = "SHU:" + ToString(code) + ":" + result;
1515        //if (n > line.length()) result += " [OK]";
1516    #if DEBUG_PUSH_PARSE
1517        printf("%s\n", result.c_str());
1518    #endif
1519        return result;
1520    }
1521    
1522  /**  /**
1523   * Clears input buffer.   * Clears input buffer.
1524   */   */

Legend:
Removed from v.2514  
changed lines
  Added in v.2515

  ViewVC Help
Powered by ViewVC