Changeset 3802 for applications


Ignore:
Timestamp:
Jun 3, 2008, 1:44:26 PM (12 years ago)
Author:
orlov
Message:
  • Small fixes, !GetRAST, samples.
Location:
applications/trunk/LFC/parser
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • applications/trunk/LFC/parser/Parser.rf

    r3800 r3802  
    44$func Main = e;
    55Main =
    6   <Lexer <Expr_Open
    7   'dec merge: List*List -> List;'
    8   'var n: Node;'
    9   '    l1, l2: List;'
    10   'def merge (n, l2) = n[]","[]l2 ;'
    11   '    merge (n[]","[]l1, l2) = scat(n, ",", merge(l1, l2)) ;'
    12   >> :: e.tokens,
    13   <WriteLn e.tokens>,
    14   <WriteLn <Program e.tokens>>;
     6  <Lexer <File_Open "samples.lfc">> :: e.tokens,
     7  //<WriteLn e.tokens>,
     8  <WriteLn <GetRAST <Program e.tokens>>>;
     9
     10$func GetRAST e.ast = e.ast;
     11GetRAST {
     12  /*empty*/ = /*empty*/;
     13  t.term e.ast = t.term : {
     14    (IDENT t.name VAR) = (VAR t.name);
     15    (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>));
     17    (PAREN e.exp (WHERE e.assigns)) = (PAREN (LET (<GetRAST e.assigns>) <GetRAST e.exp>));
     18    (e.exp) = (<GetRAST e.exp>);
     19    s.sym = s.sym;
     20  } :: t.term,
     21    t.term <GetRAST e.ast>;
     22};
    1523
    1624$func Parse (e.tokens) e.expr = e.ast (e.tokens);
    1725Parse {
    1826  (e.tokens) /*empty*/ = (e.tokens);
    19   (e.tokens) t.term e.expr = <WriteLn <L 0 e.tokens> PPP t.term e.expr>, t.term : {
     27  (e.tokens) t.term e.expr = t.term : {
    2028    (Get s.func) =
    2129      <Apply s.func e.tokens> : e.ast (e.tokens_rest),
     
    3442
    3543$func Error (e.tokens) e.message = (e.tokens);
    36 Error {((e.tk (e.pos)) e) e.message =
     44Error ((e.tk (e.pos)) e) e.message =
    3745  <Write e.pos> <Print ' --- 'e.message' while ('> <Write e.tk> <PrintLn ') have been got'>,
    3846  $error "Can't parse the program";
    39 (e1) e2 = <WriteLn Eee (e1) e2>, $fail;};
    40 
    41 $public $func Program e.tokens = e.ast (e.tokens);
     47
     48$func Program e.tokens = e.ast (e.tokens);
    4249Program e.tokens = {
    4350  e.tokens : (DEC e) e = <Parse (e.tokens) (FUNC (Get &FunctionDec) (Get &VarDecAndFuncDef)) (Get &ProgramRest)>;
     
    4855ProgramRest e.tokens = {
    4956  e.tokens : (EOF e) = ();
    50   e.tokens : (DEC e) e = <Program (e.tokens)>;
     57  e.tokens : (DEC e) e = <Program e.tokens>;
    5158  <Error (e.tokens) "expected function declaration">;
    5259};
     
    206213  e.tokens : \{ (ELSE e) e; (RPAR e) e; (SC e) e; (THEN e) e; } = (e.tokens);
    207214  e.tokens : (CONCAT e) e.tokens_rest = <ExpWithWhere e.tokens_rest>;
    208   e.tokens : (WHERE e) e.tokens_rest = (WHERE <VarassignList e.tokens_rest>);
     215  e.tokens : (WHERE e) e.tokens_rest = <Parse (e.tokens_rest) (WHERE (Get &VarassignList))>;
    209216  <Error (e.tokens)>;
    210217};
Note: See TracChangeset for help on using the changeset viewer.