Bonjour, pourriez-vous m expliquer le code suivant particulierement
comment sont evaluer les expressions.
|||%%|
line| ||:|| |
| || || |Lint| |inst| |Leol| || || || || || || || || || || || || || ||
|{| |Ligne| |{num|=$||1|;| |inst|=$||2|}| |}
| ||||| |Lcmd| || || || || || || || |Leol| || || || || || || || || || ||
|| || || || || || || || || |{| |phrase_of_cmd| ||$||1|| |}
| |;
inst| ||:|
| || || |Lrem| || || || || || || || || || || || || || || || || || || ||
|| || || || || |{| |Rem| ||$||1|| |}
| ||||| |Lgoto| |Lint| || || || || || || || || || || || || || || || ||
|| || |{| |Goto| ||$||2|| |}
| ||||| |Lprint| |exp| || || || || || || || || || || || || || || || ||
|| || |{| |Print| ||$||2|| |}
| ||||| |Linput| |Lident| || || || || || || || || || || || || || || ||
|{| |Input| ||$||2|| |}
| ||||| |Lif| |exp| |Lthen| |Lint| || || || || || || || || || || |{|
|If| |(|$||2||,|| ||$||4|)| |}
| ||||| |Llet| |Lident| |Legal| |exp| || || || || || || || |{| |Let|
|(|$||2||,|| ||$||4|)| |}
| |;
exp| ||:|
| || || |Lint| || || || || || || || || || || || || || || || || || || ||
|| || || || || |{| |ExpInt| ||$||1|| |}
| ||||| |Lident| || || || || || || || || || || || || || || || || || ||
|| || || || |{| |ExpVar| ||$||1|| |}
| ||||| |Lstring| || || || || || || || || || || || || || || || || || ||
|| || || |{| |ExpStr| ||$||1|| |}
| ||||| |Lneg| |exp| || || || || || || || || || || || || || || || || ||
|| || || |{| |ExpUnr| |(NON|,|| ||$||2|)| |}
| ||||| |exp| |Lplus| |exp| || || || || || || || || || || || || || || ||
|{| |ExpBin| |(|$||1||,|| |PLUS|,|| ||$||3|)| |}
| ||||| |exp| |Lmoins| |exp| || || || || || || || || || || || || || ||
|{| |ExpBin| |(|$||1||,|| |MOINS|,|| ||$||3|)| |}
| ||||| |exp| |Lmult| |exp| || || || || || || || || || || || || || || ||
|{| |ExpBin| |(|$||1||,|| |MULT|,|| ||$||3|)| |}
| ||||| |exp| |Ldiv| |exp| || || || || || || || || || || || || || || ||
|| || || || || || || || |{| |ExpBin| |(|$||1||,|| |DIV|,|| ||$||3|)| |}
| ||||| |exp| |Lmod| |exp| || || || || || || || || || || || || || || ||
|| || || || || || || || |{| |ExpBin| |(|$||1||,|| |MOD|,|| ||$||3|)| |}
| ||||| |exp| |Legal| |exp| || || || || || || || || || || || || || || ||
|{| |ExpBin| |(|$||1||,|| |EGAL|,|| ||$||3|)| |}
| ||||| |exp| |Lrel| |exp| || || || || || || || || || || || || || || ||
|| || || || || || || || |{| |ExpBin| |(|$||1||,|| |(op_bin_of_rel|
||$||2|)|,|| ||$||3|)| |}
| ||||| |exp| |Land| |exp| || || || || || || || || || || || || || || ||
|| |{| |ExpBin| |(|$||1||,|| |ET|,|| ||$||3|)| |}
| ||||| |exp| |Lor| |exp| || || || || || || || || || || || || || || ||
|| || |{| |ExpBin| |(|$||1||,|| |OU|,|| ||$||3|)| |}
| ||||| |Lmoins| |exp| ||%|prec| |Lopp| || || || || || || || |{|
|ExpUnr(OPPOSE|,|| ||$||2|)| |}
| ||||| |Lpar| |exp| |Rpar| || || || || || || || || || || || || || || ||
|{| ||$||2|| |}
| |;
| ||%%|
{
| |*open*| |Basic_parser| |;;
| |*let*| |string_chars| |s| ||=|| |String.sub| |s| ||1||
|((String.length| |s)|-||2|)| |;;
}
rule| |lexer| ||=|| |parse
| || || ||[||' '|| ||'\t'||]|| || || || || || || || || || || || |{|
|lexer| |lexbuf| |}
| ||||| ||'\n'|| || || || || || || || || || || || || || || || || || |{|
|Leol| |}
| ||||| ||'!'|| || || || || || || || || || || || || || || || || || ||
|{| |Lneg| |}
| ||||| ||'&'|| || || || || || || || || || || || || || || || || || ||
|{| |Land| |}
| ||||| ||'|'|| || || || || || || || || || || || || || || || || || ||
|{| |Lor| |}
| ||||| ||'='|| || || || || || || || || || || || || || || || || || || ||
|| || || || || |{| |Legal| |}
| ||||| ||'%'|| || || || || || || || || || || || || || || || || || || ||
|| || || || || |{| |Lmod| |}
| ||||| ||'+'|| || || || || || || || || || || || || || || || || || || ||
|| || || || || |{| |Lplus| |}
| ||||| ||'-'|| || || || || || || || || || || || || || || || || || || ||
|| || || || || |{| |Lmoins| |}
| ||||| ||'*'|| || || || || || || || || || || || || || || || || || || ||
|| || || || || |{| |Lmult| |}
| ||||| ||'/'|| || || || || || || || || || || || || || || || || || || ||
|| || || || || |{| |Ldiv| |}
| ||||| ||[||'<'|| ||'>'||]|| || || || || || || || || || || || || |{|
|Lrel| |(Lexing.lexeme| |lexbuf)| |}
| ||||| ||"<="|| || || || || || || || || || || || || || || || || || ||
|| || || || || || |{| |Lrel| |(Lexing.lexeme| |lexbuf)| |}
| ||||| ||">="|| || || || || || || || || || || || || || || || || || ||
|| || || || || || |{| |Lrel| |(Lexing.lexeme| |lexbuf)| |}
| ||||| ||"REM"|| ||[||^|| ||'\n'||]*|| || || || || || || |{| |Lrem|
|(Lexing.lexeme| |lexbuf)| |}
| ||||| ||"LET"|| || || || || || || || || || || || || || || || || |{|
|Llet| |}
| ||||| ||"PRINT"|| || || || || || || || || || || || || || || |{|
|Lprint| |}
| ||||| ||"INPUT"|| || || || || || || || || || || || || || || |{|
|Linput| |}
| ||||| ||"IF"|| || || || || || || || || || || || || || || || || || |{|
|Lif| |}
| ||||| ||"THEN"|| || || || || || || || || || || || || || || || |{|
|Lthen| |}
| ||||| ||"GOTO"|| || || || || || || || || || || || || || || || |{|
|Lgoto| |}
| ||||| ||"RUN"|| || || || || || || || || || || || || || || || |{|
|Lcmd| |(Lexing.lexeme| |lexbuf)| |}
| ||||| ||"LIST"|| || || || || || || || || || || || || || || |{| |Lcmd|
|(Lexing.lexeme| |lexbuf)| |}
| ||||| ||"END"|| || || || || || || || || || || || || || || || |{|
|Lcmd| |(Lexing.lexeme| |lexbuf)| |}
| |
| ||||| ||[||'0'||-||'9'||]+|| || || || || || || || || || || |{| |Lint|
|(int_of_string| |(Lexing.lexeme| |lexbuf))| |}
| ||||| ||[||'A'||-||'z'||]+|| || || || || || || || || || || |{|
|Lident| |(Lexing.lexeme| |lexbuf)| |}
| ||||| ||'"'|| ||[||^|| ||'"'||]*|| ||'"'|| || || || || |{| |Lstring|
|(string_chars| |(Lexing.lexeme| |lexbuf))| |}
*let*| |une_commande| |etat| ||=|
| || || |print_string| ||"> "|| |;| |flush| |stdout| |;
| || || |*try*| |
| || || || || |*match*| |||||||line| |lexer| |(Lexing.from_string|
|((input_line| |stdin)|^||"\n"|))||* with*| |
| || || || || || || || |Ligne| |l| |->| |{| |etat| |*with*| |prog| ||=||
|inserer| |l| |etat|.|prog| |}
| || || || || || ||||| |List| || |->| |(print_prog| |etat|.|prog| |;|
|etat| |)
| || || || || || ||||| |Run| |
| || || || || || || |->| |*let*| |tprog| ||=|| |assemble| |etat|.|prog|
|*in*
| || || || || || || || || || |*let*| |xetat| ||=|| |run| |{| |ligne|
||=|| ||0|;| |xprog| ||=|| |tprog;| |xenv| ||=|| |etat|.|env| |}| |*in*
| || || || || || || || || || || |{etat| |*with*| |env| ||=||
|xetat|.|xenv| |}
line| |lexer| |(Lexing.from_string| |((input_line| |stdin)|^||"\n"|))|||
|| || || || || ||||| |End| |->| |raise| |Fin
| || || |*with*| |
| || || || || || || |LexerErreur| |->| |print_string| ||"Illegal
character\n"|;| |etat| |
| || || || || ||||| |ParseErreur| |->| |print_string| ||"syntax
error\n"|;| |etat| |
| || || || || ||||| |RunErreur| |n| |->| |
| || || || || || || || || |print_string| ||"runtime error at line "|;
| || || || || || || || || |print_int| |n| |;
| || || || || || || || || |print_string| ||"\n"|;| || |
| || || || || || || || || |etat| |;;
|val une_commande : etat_boucle -> etat_boucle = <fun>|
Emmanuel
ps: ce code est extrait du livre de chailloux
||||||||||||||
---- Liste gulliver ----
Se d�sinscrire, mailto:gulliver-unsubscribe at listes dot gulliver dot eu dot org
GULLIVER, http://gulliver.eu.org/