Originally posted by lensam69:
Three months ago i implemented a fuzzy logic expression evaluator in CAML. I'll see if i can find it, but trust me: You don't want to see it...
code:<HR>Code:(********************************************************) let rec ident_formula = function [<'NOT ; formula>] -> Negada (ident_formula formula) |[<'LPAR; expr>] -> ident_par expr |[<'EXISTS; 'SIMBOLO var; 'IN; 'SIMBOLO set; form >]-> Exists (var, set, (ident_formula form)) |[<'FORALL; 'SIMBOLO var; 'IN; 'SIMBOLO set; form >]-> Forall (var, set, (ident_formula form)) |[<'SIMBOLO simb; expr>] -> (Lit (ident_literal simb expr)) (********************************************************) and (********************************************************) obt_fset str = function [<'RPAR; 'FIN>] -> ({x1=(stream_next str); x2=(stream_next str); x3=(stream_next str); x4=(stream_next str);}) |[<'LPAR; st2>] -> obt_fset str st2 |[<'INF; st2>] -> obt_fset [<'"T"; str >] st2 |[<'FLOAT flt; st2>] -> obt_fset [< '(string_of_float flt); str>] st2 |[<'COMA; st2>] -> obt_fset str st2 |[<>] -> raise (Failure "Error: Fuzzy set mal declarado") (********************************************************) and (********************************************************) setToString = function [<'RCOR>] -> "" |[<'FLOAT flt; str>] -> (string_of_float flt)^(setToString str) |[<'COMA; str>] -> " "^(setToString str) |[<'SIMBOLO var; str>] -> var^(setToString str) |[<>] -> raise (Failure "Error!!! Conjunto mal declarado") (********************************************************) and (********************************************************) ident_exists nombre st st2= match st2 with [<'RCOR; st3>] -> Exists (nombre ,(setToString [<st; 'RCOR>]) ,(ident_formula st3)) |[<'x>] -> ident_exists nombre [<st; 'x>] st2 |[<>] -> raise (Failure "Error en cuantificador!!!") (********************************************************) and (********************************************************) ident_forall nombre st st2= match st2 with [<'RCOR; st3>] -> Forall (nombre ,(setToString [<st; 'RCOR>]) ,(ident_formula st3)) |[<'x>] -> ident_forall nombre [<st; 'x>] st2 |[<>] -> raise (Failure "Error en cuantificador!!!") (********************************************************) and (********************************************************) ident_literal simb = function [<'LPAR; st>] -> (match st with [<'SIMBOLO var; 'RPAR>] -> Predicado_var (simb, (var)) |[<'FLOAT flt; 'RPAR >] -> Predicado_ctt (simb, (flt)) |[<>] -> raise (Failure "Error: No se pudo identificar literal") ) |[<'SIMBOLO lit2; st>] -> (Modificador (simb, (ident_literal lit2 st))) (********************************************************) and (********************************************************) parse_logic par_left st st2= match st2 with [<'AND>] -> (if (par_left = 0) then (Y (ident_formula st, ident_formula st2)) else (parse_logic par_left [<st; 'AND>] st2) ) |[<'OR>] -> (if (par_left = 0) then (O (ident_formula st, ident_formula st2)) else (parse_logic par_left [<st; 'OR>] st2) ) |[<'LPAR; str>] -> (parse_logic (par_left + 1) [<st; 'LPAR>] st2) |[<'RPAR; str>] -> (parse_logic (par_left - 1) [<st; 'RPAR>] st2) |[<'x>] -> parse_logic par_left [<st ; 'x>] st2 |[<>]-> raise (Failure "Error: Instruccion incorrecta (Parsing for logic) ;") (********************************************************) and (********************************************************) ident_par = function [< '(SIMBOLO term1);st1>] -> (match st1 with [<'(SIMBOLO comparator);st2>] -> (match st2 with [<'(SIMBOLO term2) ; st3>] -> (match st3 with [<'RPAR >] -> Comparar ((Variable term1), comparator, (Variable term2)) |[<>] -> let str_aux = [<'(SIMBOLO term1);'(SIMBOLO comparator);'(SIMBOLO term2); st3>] in (parse_logic 0 [<>] str_aux)) |[<'(FLOAT flt2); st3>] -> match st3 with [<'RPAR >] -> Comparar ((Variable term1), comparator, (Valor flt2)) |[<>] -> raise (Failure "Error analizando un comprador") |[<>] -> let str_aux = [<'(SIMBOLO term1);'(SIMBOLO comparator); st2>] in (parse_logic 0 [<>] str_aux) ) |[<>] -> (let st_aux = [<'(SIMBOLO term1); st1>] in parse_logic 0 [<>] st_aux) ) |[<'(FLOAT flt1); st1>] -> ( match st1 with [<'(SIMBOLO comparator); st2>] -> match st2 with [<'SIMBOLO term2;'RPAR>] -> Comparar ((Valor flt1), comparator, (Variable term2)) |[<'FLOAT flt2; 'RPAR>] -> Comparar ((Valor flt1), comparator, (Valor flt2)) |[<>] -> raise (Failure "Error analizando un comparador") |[<>] -> raise (Failure "Error analizando un comparador") ) |[<st0>] -> parse_logic 0 [<>] st0;; (********************************************)
It is. I'd even say (with my limited COBOL experience) that it's rather nice COBOL.Originally posted by E3:
Crackez: Is that cobol?
![]()
Well, COBOL being nice is relative to what COBOL could be when left uncheckedEdit: euzeka, thanks for the compliment man, it's only my third program this semester in that class... I didn't think you could make any cobol look nice...
Hows that for lack of morals?
code:<HR>Code:alpha STMED r13!, {r2, r3, r4, r14} MOV r2, #65 MOV r3, #1 ADD r5, r5, #1 loopalp LDRB r1, [r0, +r5] CMP r1, #90 BLGT nextlet CMP r1, #90 BGT Exit CMP r1, r2 ADDEQ r3, r3, #1 BLGT nextlet ADD r5, r5, #1 B loopalp Exit LDMED r13!, {r2, r3, r4, r14} MOV PC, r14 hexout STMED r13!, {r0, r2, r3} MOV r2, #8 LOOP MOV r0, r1, LSR #28 CMP r0, #9 ADDGT r0, r0, #'A'-10 ADDLE r0, r0, #'0' SWI SWI_WriteC MOV r1, r1, LSL #4 SUBS r2, r2, #1 BNE LOOP LDMED r13!, {r0, r2, r3} MOV pc, r14
code:<HR>Code:#!/usr/bin/perl use strict; open (PROC,"/proc/net/tcp"); while (<PROC> ) { s/([0-9A-F]{8})/xlateaddr($1)/eg; s/:([0-9A-F]{4})/":" . xlatehex($1)/eg; print; } sub xlateaddr { join ".", map hex , reverse shift =~ m/[0-9A-F]{2}/g;} sub xlatehex { sprintf "%d", hex shift; }