Ignore:
Timestamp:
Aug 27, 2008, 12:58:58 PM (12 years ago)
Author:
orlov
Message:
  • Draft version of compiler to ASR.
File:
1 edited

Legend:

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

    r3892 r3893  
    88Init e.grammar = <Store &Grammar e.grammar>;
    99
    10 $func? Check t.type (STRING e.string) = ;
    11 Check t.type (STRING e.string) =
    12   <Parse (e.string) (((TYPE 0) DOT t.type 0))> :: e.sets,
     10$func? Check e.prod (e.string) = ;
     11Check e.prod (e.string) =
     12  <Parse (e.string) (((TYPE 0) DOT e.prod 0))> :: e.sets,
    1313  <Map &WriteLn (e.sets)> : e,
    14   e.sets : e (e ((TYPE 0)t.type DOT 0) e);
     14  e.sets : e (e ((TYPE 0 e.info) e.prod DOT 0) e);
     15
     16$public $func Earley t.type e.string = e.set;
     17Earley t.type e.string =
     18  <Parse (e.string) (((TYPE 0) DOT t.type 0))> : e (e.set),
     19  e.set;
    1520
    1621$func Parse (e.string) e.sets = e.sets;
     
    2833Scanner s.ch e.sets (e.current) (e.new) =
    2934  (e.current) (e.new) $iter {
    30     e.items : e (t.type e1 DOT (STRING s.ch e.str) e2 s.n) e.rest =
    31       (e.rest) (e.new (t.type e1 (STRING s.ch) DOT (STRING e.str) e2 s.n));
     35    e.items : e ((TYPE t.name e.info) e1 DOT s.ch e2 s.n) e.rest =
     36      (e.rest) (e.new ((TYPE t.name e.info s.ch) e1 s.ch DOT e2 s.n));
    3237    () (e.new);
    3338  } :: (e.items) (e.new),
     
    4247      (<Or (e.new) (t.type e1 DOT (TYPE t.name) e2 s.n)
    4348        <GetRules (<Get &Grammar>) t.name <Length e.sets>>>);
    44     (t.type e1 DOT (STRING) e2 s.n) e.rest =
    45       ((t.type e1 DOT e2 s.n) e.rest) (e.new);
    4649    t.item e.rest =
    4750      (e.rest) (<Or (e.new) t.item>);
     
    6669  e.sets : e.head (e.current),
    6770  (e.current) (/*e.new*/) $iter {
    68     e.items : e (t.type1 e1 DOT s.n) e.rest =
     71    e.items : e ((TYPE t.name1 e.info1) e1 DOT s.n) e.rest =
    6972      <L s.n e.sets> : (e.prev_items),
    7073      (e.prev_items) (e.new) $iter {
    71         e.prev_items : e (t.type2 e2 DOT t.type1 e3 s.m) e.rest2 =
    72           (e.rest2) (e.new (t.type2 e2 t.type1 DOT e3 s.m));
     74        e.prev_items : e ((TYPE t.name2 e.info2) e2 DOT (TYPE t.name1) e3 s.m) e.rest2 =
     75          (e.rest2) (e.new ((TYPE t.name2 e.info2 (e.info1)) e2 (TYPE t.name1) DOT e3 s.m));
    7376        () (e.new);
    7477      } :: (e.prev_items) (e.new),
     
    8386
    8487Main =
    85   <Init (PROD (TYPE ('E')) ((TYPE ('E')) (STRING '+') (TYPE ('E'))) ((STRING 'n')))>,
    86   <Check (TYPE ('E')) (STRING 'n+n')>,
     88  <Init (PROD (TYPE ('E')) ((TYPE ('E')) '+' (TYPE ('E'))) ('n'))>,
     89  <Check (TYPE ('E'))/* '+' (TYPE ('E'))*/ ('n+n')>,
    8790  <PrintLn>,
    8891  <Init (PROD (TYPE ('S')) ((TYPE ('A')) (TYPE ('A')) (TYPE ('A')) (TYPE ('A'))))
    89         (PROD (TYPE ('A')) ((STRING 'a')) ((TYPE ('E'))))
    90         (PROD (TYPE ('E')) ((STRING)))>,
    91   <Check (TYPE ('S')) (STRING 'a')>;
     92        (PROD (TYPE ('A')) ('a') ((TYPE ('E'))))
     93        (PROD (TYPE ('E')) ())>,
     94  <Check (TYPE ('S')) ('a')>;
Note: See TracChangeset for help on using the changeset viewer.