pike.git / lib / modules / Parser.pmod / LR.pmod / module.pmod

version» Context lines:

pike.git/lib/modules/Parser.pmod/LR.pmod/module.pmod:1:   /* -  * $Id: module.pmod,v 1.1 2002/05/22 11:09:57 grubba Exp $ +  * $Id: module.pmod,v 1.2 2002/05/22 12:33:28 nilsson Exp $    *    * A BNF-grammar in Pike.    * Compiles to a LALR(1) state-machine.    *    * Henrik Grubbström 1996-11-24    */      #pike __REAL_VERSION__      /*! LALR(1) parser generator
pike.git/lib/modules/Parser.pmod/LR.pmod/module.pmod:197:    //!    //! @int    //! @value 0    //! None    //! @value 1    //! Some    //! @endint    int verbose=1;       //! Error code -  int error=0; +  int lr_error=0;       /* Number of next rule (used only for conflict resolving) */    static int next_rule_number = 1;       //! LR0 states that are already known to the compiler.    mapping(string:Kernel) known_states = ([]);       /*    * Sub-classes    */
pike.git/lib/modules/Parser.pmod/LR.pmod/module.pmod:327:       if (sizeof(r->symbols) && intp(r->symbols[0]) &&    !closure_set[r->symbols[0]]) {    closure(r->symbols[0]);    }    }    }    } else {    werror("Error: Definition missing for non-terminal %s\n",    symbol_to_string(nonterminal)); -  error |= ERROR_MISSING_DEFINITION; +  lr_error |= ERROR_MISSING_DEFINITION;    }    }       //! Make the goto-set of this state.    multiset(int|string) goto_set()    {    multiset(int|string) set = (<>);       foreach (items, Item i) {    if (i->offset != sizeof(i->r->symbols)) {
pike.git/lib/modules/Parser.pmod/LR.pmod/module.pmod:1245:    if (verbose) {    werror("All conflicts removed!\n");    }    return (0);    }    }       //! Compiles the grammar into a parser, so that parse() can be called.    int compile()    { -  int error = 0; /* No error yet */ +  int lr_error = 0; /* No error yet */    int state_no = 0; /* DEBUG INFO */    Kernel state;    multiset(int|string) symbols, conflicts;       s_q = State_queue();    s_q->push(first_state());       /* First make LR(0) states */      #ifdef LR_PROFILE
pike.git/lib/modules/Parser.pmod/LR.pmod/module.pmod:1518:    } else {    symbols[symbol] = 1;    }    }    }    }    if (sizeof(conflicts)) {    /* Repair conflicts */    // int ov = verbose;    // verbose = 1; -  error = repair(state, conflicts); +  lr_error = repair(state, conflicts);    // verbose = ov;    } else if (verbose) {    werror("No conflicts in state:\n%s\n",    state_to_string(s_q->arr[index]));    }    }      #ifdef LR_PROFILE    });   #endif /* LR_PROFILE */
pike.git/lib/modules/Parser.pmod/LR.pmod/module.pmod:1561:    start_state = s_q->arr[0];      #ifdef LR_PROFILE    });   #endif /* LR_PROFILE */      #ifdef LR_PROFILE    werror("DONE\n");   #endif /* LR_PROFILE */    -  return (error); +  return (lr_error);    }       //! Parse the input according to the compiled grammar.    //! The last value reduced is returned.    //!    //! @note    //! The parser must have been compiled (with compile())    //! prior to calling this function.    //!    //! @bugs
pike.git/lib/modules/Parser.pmod/LR.pmod/module.pmod:1593:    mixed parse(object|function(void:string|array(string|mixed)) scanner,    void|object action_object)    {    ADT.Stack value_stack = ADT.Stack(4096);    ADT.Stack state_stack = ADT.Stack(4096);    Kernel state = start_state;       string input;    mixed value;    -  error = 0; /* No parse error yet */ +  lr_error = 0; /* No parse error yet */       if (!functionp(scanner) &&    !(objectp(scanner) && functionp(scanner->`()))) {    werror("parser->parse(): scanner not set!\n"); -  error = ERROR_NO_SCANNER; +  lr_error = ERROR_NO_SCANNER;    return(0);    }       value = scanner();       if (arrayp(value)) {    input = value[0];    value = value[1];    } else {    input = value;
pike.git/lib/modules/Parser.pmod/LR.pmod/module.pmod:1632:    /* REDUCE */    string|function (mixed ...:mixed) func = 0;       if (stringp(func = a->action)) {    if (action_object) {    func = action_object[a->action];    if (!functionp(func)) {    if (!func) {    werror("Missing action \"%s\" in object\n",    a->action); -  error |= ERROR_MISSING_ACTION; +  lr_error |= ERROR_MISSING_ACTION;    } else {    werror("Bad type (%s) for action \"%s\" in object\n",    typeof(func), a->action); -  error |= ERROR_BAD_ACTION_TYPE; +  lr_error |= ERROR_BAD_ACTION_TYPE;    func = 0;    }    }    } else {    werror("Missing object for action \"%s\"\n",    a->action); -  error |= ERROR_NO_OBJECT; +  lr_error |= ERROR_NO_OBJECT;    func = 0;    }    }    if (func) {    if (sizeof(a->symbols)) {    value_stack->push(func(@value_stack->pop(sizeof(a->symbols))));    state = state_stack->pop(sizeof(a->symbols))[0];    } else {    value_stack->push(a->action());    }
pike.git/lib/modules/Parser.pmod/LR.pmod/module.pmod:1714:    if (arrayp(value)) {    input = value[0];    value = value[1];    } else {    input = value;    }    } else {    /* ERROR */    if (input = "") {    /* At end of file */ -  error |= ERROR_EOF; +  lr_error |= ERROR_EOF;       if (value_stack->ptr != 1) {    if (value_stack->ptr) {    werror("Error: Bad state at EOF -- Throwing \"%O\"\n",    value_stack->pop());    state=state_stack->pop();    } else {    werror("Error: Empty stack at EOF!\n");    return (0);    }    } else {    werror("Error: Bad state at EOF\n");    return(value_stack->pop());    }    } else { -  error |= ERROR_SYNTAX; +  lr_error |= ERROR_SYNTAX;       werror("Error: Bad input: \""+input+"\"(\""+value+"\")\n");       value = scanner();       if (arrayp(value)) {    input = value[0];    value = value[1];    } else {    input = value;    }    }    }    }    }   }