Changeset 3980 for applications


Ignore:
Timestamp:
Oct 19, 2008, 12:45:34 AM (12 years ago)
Author:
orlov
Message:
  • Earley algorithm in Refal-5 without repeated et-variables.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/trunk/LFC/Earley/Earley.ref

    r3979 r3980  
    88
    99Check {
    10   (e.grammar) (TYPE t.name) e.string,
    11     <Parse (e.grammar) (e.string) () (((TYPE START) (DOT (TYPE t.name)) ())) () ()> : e.sets (e.last) =
    12     <FindSuccessRule t.name e.last>;
     10  (e.grammar) (TYPE s.name) e.string,
     11    <Parse (e.grammar) (e.string) () (((TYPE START) (DOT (TYPE s.name)) ())) () ()> : e.sets (e.last) =
     12    <FindSuccessRule s.name e.last>;
    1313}
    1414
    1515FindSuccessRule {
    16   t.name ((TYPE t.name e.info) e.prod (DOT) ()) e.rules = (e.info) (e.prod);
    17   t.name t.rule e.rules = <FindSuccessRule t.name e.rules>;
    18   t.name = "Parsing failed";
     16  s.name ((TYPE s.name e.info) e.prod (DOT) ()) e.rules = (e.info) (e.prod);
     17  s.name t.rule e.rules = <FindSuccessRule s.name e.rules>;
     18  s.name = "Parsing failed";
    1919}
    2020
     
    3030  (e.grammar) (e.string) (e.step) e.sets (t.rule e.rules) (e.current) (e.next), t.rule : {
    3131* Scanner
    32     ((TYPE t.name e.info) e.1 (DOT s.char e.2) (e.n)), e.string : {
     32    ((TYPE s.name e.info) e.1 (DOT s.char e.2) (e.n)), e.string : {
    3333      s.char e.rest_chars =
    3434        <Parse (e.grammar) (e.string) (e.step) e.sets (e.rules) (e.current t.rule)
    35           (e.next ((TYPE t.name e.info s.char) e.1 s.char (DOT e.2) (e.n)))>;
     35          (e.next ((TYPE s.name e.info s.char) e.1 s.char (DOT e.2) (e.n)))>;
    3636      e.string =
    3737        <Parse (e.grammar) (e.string) (e.step) e.sets (e.rules) (e.current t.rule) (e.next)>;
    3838    };
    3939* Predictor
    40     (t.type e.1 (DOT (TYPE t.name) e.2) (e.n)),
     40    (t.type e.1 (DOT (TYPE s.name) e.2) (e.n)),
    4141      e.current t.rule : e.current2 =
    4242      <Parse (e.grammar) (e.string) (e.step) e.sets
    43         (<AddPredictions (e.grammar) (e.rules) (e.current2) t.name (e.step)>) (e.current2) (e.next)>;
     43        (<AddPredictions (e.grammar) (e.rules) (e.current2) s.name (e.step)>) (e.current2) (e.next)>;
    4444* Completer
    45     ((TYPE t.name e.info) e.1 (DOT) (e.n)),
     45    ((TYPE s.name e.info) e.1 (DOT) (e.n)),
    4646      e.current t.rule : e.current2 =
    4747      <Parse (e.grammar) (e.string) (e.step) e.sets
    48         (<AddCompletions (e.n) (e.sets) (e.rules) (e.current2) t.name e.info>) (e.current2) (e.next)>;
     48        (<AddCompletions (e.n) (e.sets) (e.rules) (e.current2) s.name e.info>) (e.current2) (e.next)>;
    4949  };
    5050}
    5151
    5252AddPredictions {
    53   ((PROD (TYPE t.name) e.prods) e.grammar) (e.rules) (e.current) t.name (e.step) =
    54     <AddPredictions (e.grammar) (<AddPredictions2 (e.prods) (e.rules) (e.current) t.name (e.step)>) (e.current) t.name (e.step)>;
    55   (t.prod e.grammar) (e.rules) (e.current) t.name (e.step) = <AddPredictions (e.grammar) (e.rules) (e.current) t.name (e.step)>;
    56   () (e.rules) (e.current) t.name (e.step) = e.rules;
     53  ((PROD (TYPE s.name) e.prods) e.grammar) (e.rules) (e.current) s.name (e.step) =
     54    <AddPredictions (e.grammar) (<AddPredictions2 (e.prods) (e.rules) (e.current) s.name (e.step)>) (e.current) s.name (e.step)>;
     55  (t.prod e.grammar) (e.rules) (e.current) s.name (e.step) = <AddPredictions (e.grammar) (e.rules) (e.current) s.name (e.step)>;
     56  () (e.rules) (e.current) s.name (e.step) = e.rules;
    5757}
    5858
    5959AddPredictions2 {
    60   ((e.prod) e.rest_prods) (e.rules) (e.current) t.name (e.step),
    61     ((TYPE t.name) (DOT e.prod) (e.step)) : t.prediction,
     60  ((e.prod) e.rest_prods) (e.rules) (e.current) s.name (e.step),
     61    ((TYPE s.name) (DOT e.prod) (e.step)) : t.prediction,
    6262    <IsIn e.rules t.prediction> : {
    63       True = <AddPredictions2 (e.rest_prods) (e.rules) (e.current) t.name (e.step)>;
     63      True = <AddPredictions2 (e.rest_prods) (e.rules) (e.current) s.name (e.step)>;
    6464      False, <IsIn e.current t.prediction> : {
    65         True = <AddPredictions2 (e.rest_prods) (e.rules) (e.current) t.name (e.step)>;
    66         False = <AddPredictions2 (e.rest_prods) (e.rules t.prediction) (e.current) t.name (e.step)>;
     65        True = <AddPredictions2 (e.rest_prods) (e.rules) (e.current) s.name (e.step)>;
     66        False = <AddPredictions2 (e.rest_prods) (e.rules t.prediction) (e.current) s.name (e.step)>;
    6767      };
    6868    };
    69   () (e.rules) (e.current) t.name (e.step) = e.rules;
     69  () (e.rules) (e.current) s.name (e.step) = e.rules;
    7070}
    7171
    7272AddCompletions {
    73   (I e.n) (t.set e.rest_sets) (e.rules) (e.current) t.name e.info = <AddCompletions (e.n) (e.rest_sets) (e.rules) (e.current) t.name e.info>;
    74   () ((e.set) e.rest_sets) (e.rules) (e.current) t.name e.info = <AddCompletions2 (e.set) (e.rules) (e.current) t.name e.info>;
    75   () () (e.rules) (e.current) t.name e.info = e.rules;
     73  (I e.n) (t.set e.rest_sets) (e.rules) (e.current) s.name e.info = <AddCompletions (e.n) (e.rest_sets) (e.rules) (e.current) s.name e.info>;
     74  () ((e.set) e.rest_sets) (e.rules) (e.current) s.name e.info = <AddCompletions2 (e.set) (e.rules) (e.current) s.name e.info>;
     75  () () (e.rules) (e.current) s.name e.info = e.rules;
    7676}
    7777
    7878AddCompletions2 {
    79   (((TYPE t.name2 e.info2) e.1 (DOT (TYPE t.name) e.2) (e.step)) e.set) (e.rules) (e.current) t.name e.info,
    80     ((TYPE t.name2 e.info2 (e.info)) e.1 (TYPE t.name) (DOT e.2) (e.step)) : t.completion,
     79  (((TYPE s.name2 e.info2) e.1 (DOT (TYPE s.name) e.2) (e.step)) e.set) (e.rules) (e.current) s.name e.info,
     80    ((TYPE s.name2 e.info2 (e.info)) e.1 (TYPE s.name) (DOT e.2) (e.step)) : t.completion,
    8181    <IsIn e.rules t.completion> : {
    82       True = <AddCompletions2 (e.set) (e.rules) (e.current) t.name e.info>;
     82      True = <AddCompletions2 (e.set) (e.rules) (e.current) s.name e.info>;
    8383      False, <IsIn e.current t.completion> : {
    84         True = <AddCompletions2 (e.set) (e.rules) (e.current) t.name e.info>;
    85         False = <AddCompletions2 (e.set) (e.rules t.completion) (e.current) t.name e.info>;
     84        True = <AddCompletions2 (e.set) (e.rules) (e.current) s.name e.info>;
     85        False = <AddCompletions2 (e.set) (e.rules t.completion) (e.current) s.name e.info>;
    8686      };
    8787    };
    88   (t.rule e.set) (e.rules) (e.current) t.name e.info = <AddCompletions2 (e.set) (e.rules) (e.current) t.name e.info>;
    89   () (e.rules) (e.current) t.name e.info = e.rules;
     88  (t.rule e.set) (e.rules) (e.current) s.name e.info = <AddCompletions2 (e.set) (e.rules) (e.current) s.name e.info>;
     89  () (e.rules) (e.current) s.name e.info = e.rules;
    9090}
    9191
     
    9999  = <Prout
    100100* E -> E '+' E | 'n'
    101       <Check ((PROD (TYPE ('E')) ((TYPE ('E')) '+' (TYPE ('E'))) ('n'))) (TYPE ('E')) 'n+n'> '\n'
    102       <Check ((PROD (TYPE ('E')) ((TYPE ('E')) '+' (TYPE ('E')))) (PROD (TYPE ('E')) ('n'))) (TYPE ('E')) 'n+n+n'>>;
     101      <Check ((PROD (TYPE "E") ((TYPE "E") '+' (TYPE "E")) ('n'))) (TYPE "E") 'n+n'> '\n'
     102      <Check ((PROD (TYPE "E") ((TYPE "E") '+' (TYPE "E"))) (PROD (TYPE "E") ('n'))) (TYPE "E") 'n+n+n'>>;
    103103}
    104104
Note: See TracChangeset for help on using the changeset viewer.