Changeset 3893 for applications/trunk


Ignore:
Timestamp:
Aug 27, 2008, 12:58:58 PM (12 years ago)
Author:
orlov
Message:
  • Draft version of compiler to ASR.
Location:
applications/trunk/LFC
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • applications/trunk/LFC/.classpath

    r3892 r3893  
    33        <classpathentry kind="src" path="parser"/>
    44        <classpathentry kind="src" path="Earley"/>
     5        <classpathentry kind="src" path="ToASR"/>
    56        <classpathentry kind="con" path="org.refal.rfpdt.launching.rfpContainer"/>
    67        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  • 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')>;
  • applications/trunk/LFC/lfc.ast

    r3892 r3893  
    4141t.assign ::= (t.var e.exp)
    4242
    43 t.const ::= (STRING [characters])
     43t.const ::= [a character]
    4444
    4545t.type ::= (TYPE t.name)
  • applications/trunk/LFC/parser/GrammarParser.rf

    r3892 r3893  
    33$func Main = e;
    44Main =
    5   <WriteLn <ParseGrammar <File_Open "samples.g">>>;
     5  <WriteLn <ParseGrammarFile "samples.g">>;
     6
     7$public $func ParseGrammarFile e.fname = e.grammar;
     8ParseGrammarFile e.fname =
     9  <ParseGrammar <File_Open "samples.g">>;
    610
    711$func ParseGrammar stream = e.grammar;
     
    4953    <CheckIdentifier e.ident (e.production)> <ParseItems e.rest (e.production)>;
    5054  e.str s.last '<' e.ident '>' e.rest (e.production), # \{ s.last : '\\'; } =
    51     (STRING <ParseString e.str s.last (e.production)>) <CheckIdentifier e.ident (e.production)> <ParseItems e.rest (e.production)>;
    52   v.str (e.production) = (STRING <ParseString v.str (e.production)>);
     55    <ParseString e.str s.last (e.production)> <CheckIdentifier e.ident (e.production)> <ParseItems e.rest (e.production)>;
     56  v.str (e.production) = <ParseString v.str (e.production)>;
    5357  (e) = /*empty*/;
    5458};
  • applications/trunk/LFC/parser/Parser.rf

    r3812 r3893  
    33
    44$func Main = e;
    5 Main =
    6   <Lexer <File_Open "samples.lfc">> :: e.tokens,
     5Main = <WriteLn <ParseFile "samples.lfc">>;
     6
     7$public $func ParseFile e.fname = e.ast;
     8ParseFile e.fname =
     9  <Lexer <File_Open e.fname>> :: e.tokens,
    710  //<WriteLn e.tokens>,
    8   <WriteLn <GetRAST <Program e.tokens>>>;
    9 
    10 $func GetRAST e.ast = e.ast;
     11  <GetRAST <Program e.tokens>>;
     12
     13$public $func GetRAST e.ast = e.ast;
    1114GetRAST {
    1215  /*empty*/ = /*empty*/;
     
    1417    (IDENT t.name VAR) = (VAR t.name);
    1518    (IDENT t.name CALL e.args) = (CALL t.name <GetRAST e.args>);
    16     (SENTENCE t.name e.exp (WHERE e.assigns)) = (SENTENCE t.name (LET (<GetRAST e.assigns>) <GetRAST e.exp>));
     19    (SENTENCE t.name (e.patterns) e.exp (WHERE e.assigns)) = (SENTENCE t.name (e.patterns) (LET (<GetRAST e.assigns>) <GetRAST e.exp>));
    1720    (PAREN e.exp (WHERE e.assigns)) = (PAREN (LET (<GetRAST e.assigns>) <GetRAST e.exp>));
    1821    (e.exp) = (<GetRAST e.exp>);
     
    127130$func Pattern e.tokens = e.ast (e.tokens);
    128131Pattern e.tokens = {
    129   e.tokens : (STRING e.str t.pos) e.tokens_rest = (STRING e.str) <Parse (e.tokens_rest) (Get &PatConcat)>;
     132  e.tokens : (STRING e.str t.pos) e.tokens_rest = e.str <Parse (e.tokens_rest) (Get &PatConcat)>;
    130133  e.tokens : (IDENTIFIER e) e = <Parse (e.tokens) (VAR (Get &Identifier)) (Get &PatConcat)>;
    131134  <Error (e.tokens) "expected a constant or a variable name">;
     
    161164$func Exp e.tokens = e.ast (e.tokens);
    162165Exp e.tokens = {
    163   e.tokens : (STRING e.str t.pos) e.tokens_rest = (STRING e.str) <ExpConcat e.tokens_rest>;
     166  e.tokens : (STRING e.str t.pos) e.tokens_rest = e.str <ExpConcat e.tokens_rest>;
    164167  e.tokens : (IDENTIFIER e) e = <Parse (e.tokens) (IDENT (Get &Identifier) (Get &ExpVarOrFunc)) (Get &ExpConcat)>;
    165168  e.tokens : (LPAR e) e.tokens_rest = <Parse (e.tokens_rest) (PAREN (Get &ExpWithWhere)) (Skip RPAR) (Get &ExpConcat)>;
     
    170173$func ExpWithWhere e.tokens = e.ast (e.tokens);
    171174ExpWithWhere e.tokens = {
    172   e.tokens : (STRING e.str t.pos) e.tokens_rest = (STRING e.str) <ExpConcatOrWhere e.tokens_rest>;
     175  e.tokens : (STRING e.str t.pos) e.tokens_rest = e.str <ExpConcatOrWhere e.tokens_rest>;
    173176  e.tokens : (IDENTIFIER e) e = <Parse (e.tokens) (IDENT (Get &Identifier) (Get &ExpVarOrFunc)) (Get &ExpConcatOrWhere)>;
    174177  e.tokens : (LPAR e) e.tokens_rest = <Parse (e.tokens_rest) (PAREN (Get &ExpWithWhere)) (Skip RPAR) (Get &ExpConcatOrWhere)>;
Note: See TracChangeset for help on using the changeset viewer.