commit 1d44a8bf1305bf70df37c8c32929a4b863f38071 Author: alterdekim Date: Sat May 25 03:49:08 2024 +0300 first commit diff --git a/asm/test b/asm/test new file mode 100644 index 0000000..140cf53 Binary files /dev/null and b/asm/test differ diff --git a/asm/test.asm b/asm/test.asm new file mode 100644 index 0000000..273b1b6 --- /dev/null +++ b/asm/test.asm @@ -0,0 +1,5 @@ +global _start +_start: + mov rax, 60 + mov rdi, 69 + syscall \ No newline at end of file diff --git a/asm/test.o b/asm/test.o new file mode 100644 index 0000000..b17180d Binary files /dev/null and b/asm/test.o differ diff --git a/haskell/main.hs b/haskell/main.hs new file mode 100644 index 0000000..fdb893e --- /dev/null +++ b/haskell/main.hs @@ -0,0 +1,80 @@ +import System.IO +import Data.List +import Data.Char (ord) + +data TokenType = Quotes | Dot | Colon | EndStatement | EOF | Literal | Number | Letter | Digit | Equals | OpenParen | CloseParen | BinaryOperator | Empty deriving (Show, Eq) +data Token = Token {value :: [Char], token_type :: TokenType} deriving (Show) + +parseSingleChar :: Char -> Token +parseSingleChar c + | c == '(' = Token [c] OpenParen + | c == ')' = Token [c] CloseParen + | c == '+' || c == '-' || c == '*' || c == '/' || c == '<' || c == '>' = Token [c] BinaryOperator + | c == '=' = Token [c] Equals + | c == ';' = Token [c] EndStatement + | c == ':' = Token [c] Colon + | c == '.' = Token [c] Dot + | c == '\'' = Token [c] Quotes + | elem c ['0'..'9'] = Token [c] Digit + | elem c $ ['a'..'z'] ++ ['A'..'Z'] = Token [c] Letter + | otherwise = Token " " Empty + +tokenize :: [Char] -> [Token] +tokenize sourceCode = filter (\t -> token_type t /= Empty && token_type t /= EOF) (reduceTokens ((map parseSingleChar sourceCode) ++ [Token " " EOF]) 0) + +conTokType :: TokenType -> TokenType +conTokType tt + | tt == Digit = Number + | otherwise = Literal + +reduceTokens :: [Token] -> Int -> [Token] +reduceTokens all_tokens i + | token_type ct == Digit || token_type ct == Letter = (Token (makeIdentifier (drop i all_tokens) 0) (conTokType $ token_type ct)):(_reduceTokens all_tokens (findFirstEmpty all_tokens i)) + | token_type ct == Quotes = (Token (_makeQuoteString (drop (succ i) all_tokens) 0) Literal):(_reduceTokens all_tokens (findFirstQuotes all_tokens (succ i))) + | otherwise = ct:(_reduceTokens all_tokens (succ i)) + where ct = all_tokens !! i + +_reduceTokens :: [Token] -> Int -> [Token] +_reduceTokens all_tokens i + | i >= length all_tokens = [Token " " EOF] + | otherwise = reduceTokens all_tokens i + +_makeQuoteString :: [Token] -> Int -> [Char] +_makeQuoteString t i + | i >= length t = "" + | otherwise = makeQuoteString t i + +makeQuoteString :: [Token] -> Int -> [Char] +makeQuoteString t i + | tt == Quotes = "" + | otherwise = ((value $ t !! i) !! 0):(_makeQuoteString t (succ i)) + where tt = token_type $ t !! i + +makeIdentifier :: [Token] -> Int -> [Char] +makeIdentifier t i + | i >= length t || (tt /= Letter && tt /= Digit) = "" + | otherwise = ((value $ t !! i) !! 0):(makeIdentifier t (succ i)) + where tt = token_type $ t !! i + +findFirstEmpty :: [Token] -> Int -> Int +findFirstEmpty t i + | i >= length t || (tt /= Letter && tt /= Digit) = i + | otherwise = findFirstEmpty t $ succ i + where tt = token_type $ t !! i + +findFirstQuotes :: [Token] -> Int -> Int +findFirstQuotes t i + | i >= length t || tt == Quotes = succ i + | otherwise = findFirstQuotes t $ succ i + where tt = token_type $ t !! i + +main = do + handle <- openFile "test.pas" ReadMode + contents <- hGetContents handle + let x = tokenize contents + print x + --print $ findFirstEmpty x 0 + --print $ take (findFirstEmpty x 0) x + --print $ makeInt x + --print $ makeIdentifier x + hClose handle \ No newline at end of file diff --git a/pascal/test.pas b/pascal/test.pas new file mode 100644 index 0000000..e7f489c --- /dev/null +++ b/pascal/test.pas @@ -0,0 +1 @@ +halt(1); \ No newline at end of file diff --git a/pascal/test1.pas b/pascal/test1.pas new file mode 100644 index 0000000..3e6223d --- /dev/null +++ b/pascal/test1.pas @@ -0,0 +1,41 @@ +program InsertionSort; + +Var x: Integer; +Var numbers : array[1..5] of Integer; + +procedure InsertionSort(size : Integer ); +Var i, j, index : Integer; +Begin + For i := 2 to size do + Begin + index := numbers[i]; + j := i; + While ((j > 1) AND (numbers[j-1] > index)) do + Begin + numbers[j] := numbers[j-1]; + j := j - 1; + End; + numbers[j] := index; + End; +End; + +Begin + writeln('Insertion Example: '); + + numbers[1] := 9001; + numbers[2] := 42; + numbers[3] := 32; + numbers[4] := 64; + numbers[5] := 2; + + for x:= 0 to 5 do + writeln('unsorted[', x, '] = ', numbers[x] ); + + InsertionSort(5); + + writeln('=== sorted ==='); + + for x:= 0 to 5 do + writeln('sorted[', x, '] = ', numbers[x] ); + +End. \ No newline at end of file