λ's profile(λabcdefghijklmnopq·fgha...BlogListsGuestbookMore ![]() | Help |
(λabcdefghijklmnopq·fghabc)logicProgrammingLambda is the force, Herbrand is the source. |
|||||||||||||||||||||
|
July 02 'Hello world!' in yet another language.
March 21 Continuation-style passing#light open Parser open Lexer type expr = | Num of int | Add of expr * expr | Sub of expr * expr | Mul of expr * expr | Div of expr * expr | Bracket of expr | NegBracket of expr with static member (+) (x,y) = Add(x,y) static member (-) (x,y) = Sub(x,y) static member (*) (x,y) = Mul(x,y) static member (/) (x,y) = Div(x,y) //Define function name alias let readLine = System.Console.ReadLine printf "Please enter an expression to evaluate\n:>" let input = readLine()//Get User Input let parseExpr str = try Lexing.from_string str |> Parser.expr Lexer.token with e -> failwithf "Error : %s" e.Message //LR Top-down Continuation style evaluation the syntax tree. let eval st = let rec parse tree cont = match tree with |Add(a,b) -> parse a (fun l -> parse b (fun r -> cont (l+r))) |Sub(a,b) -> parse a (fun l -> parse b (fun r -> cont (l-r))) |Mul(a,b) -> parse a (fun l -> parse b (fun r -> cont (l*r))) |Div(a,b) -> parse a (fun l -> parse b (fun r -> if r <> 0 then cont (l/r) --------------------------------------------------------------------------------------------------------- {
open Parser
}
let num = ['0'-'9']+
rule token = parse
|num {NUM (Int32.of_string (Lexing.lexeme lexbuf)) }
|'+' { ADD }
|'-' { SUB }
|'*' { MUL }
|'/' { DIV }
|'(' { OPEN }
|')' { CLOSE }
|eof { EOF }
|_ {failwithf "unrecognized input: '%s'" (Lexing.lexeme lexbuf) }
March 05 Syntax-Directed Translator Series : Simple Calculator F# Lexical analyzerHola! So long, no update -------------------------------------------------------------------------------- #light //Define function name alias let write (x:string) = System.Console.Write(x) let writeLine (x:string) = System.Console.WriteLine(x) let readLine = System.Console.ReadLine let parseInt = System.Int32.Parse let digitCheck = System.Char.IsDigit writeLine("Please enter an expression to evaluate") write(":>") let input = readLine()//Get User Input let charStream = List.of_seq input //decompose a string into char list type token = //token type definition |NUM of int |ADD |MUL |SUB |DIV let lexical stream = //char stream -> token stream let rec buildNumber num list = //number handling using basic recursion match list with |c::tail when digitCheck c -> if tail = [] then (num+c.ToString(),[]) else buildNumber (num+c.ToString()) tail |tail -> (num, tail) let rec lex = function //token matching |c::list when digitCheck c -> (buildNumber "" (c::list)) |> (fun (n,l) -> (NUM (parseInt n))::(lex l)) |'+'::list -> ADD::(lex list) |'*'::list -> MUL::(lex list) |'-'::list -> SUB::(lex list) |'/'::list -> DIV::(lex list) |[] -> [] |_ -> failwith("Unexpected pattern in lex list") lex stream lexical charStream |> print_any //perform lexical on char stream and print to console readLine() |> ignore //For only break console window before it shutdown December 23 Revise your C++ Dynamic Link LibraryC++ is one of the most complicated languages, however, knowing C++ is omnipotent to deal with almost any programming issues.C++ DLL is a common way to reduce the code duplication and make it easier to update the deployed applications by just only update those out of date version. You may need some analgesic before completely erudite with C++ DLL especially if you are very new to C++, but I would say that it’s not that hard, actually C++ and all underlying concepts are comparatively easy.All the scabrousness are came from flexibility, compatilibity, extensibility and optimization. December 20 Functional adventure storyIf you have some experience about using functional programming in your real-life and want to share those good (or bad) experiences.It's your time. You may share whether functional approach success or fail in the real world. |
Link to the extreamly very interesting research groups.
Thanks for visiting! Would you mind leave your sign?
Ao_RhaSha_oAwrote:
ยินดี ที่ได้เข้ามาเจอ Blog ดีๆ อย่างนี้นะครับ
6 days ago
Nuchit Atjanawatwrote:
ผ่านมา เลยลงชื่อครับ เป็น Blog ที่เยี่ยมครับ
June 9
|
||||||||||||||||||||
|
|