From 1d44a8bf1305bf70df37c8c32929a4b863f38071 Mon Sep 17 00:00:00 2001 From: alterdekim Date: Sat, 25 May 2024 03:49:08 +0300 Subject: [PATCH] first commit --- asm/test | Bin 0 -> 3765 bytes asm/test.asm | 5 +++ asm/test.o | Bin 0 -> 576 bytes haskell/main.hs | 80 +++++++++++++++++++++++++++++++++++++++++++++++ pascal/test.pas | 1 + pascal/test1.pas | 41 ++++++++++++++++++++++++ 6 files changed, 127 insertions(+) create mode 100644 asm/test create mode 100644 asm/test.asm create mode 100644 asm/test.o create mode 100644 haskell/main.hs create mode 100644 pascal/test.pas create mode 100644 pascal/test1.pas diff --git a/asm/test b/asm/test new file mode 100644 index 0000000000000000000000000000000000000000..140cf53e2b12005071006302c4d8b7a6c657cff6 GIT binary patch literal 3765 zcmeHJyH6BB7@s>mgAyKviLo#&K`ksU#2S+$+$E9#M~m1kXYGbWhs8&%&s%T0~Nc)p^HgM4=oDkMwsgTs;e>Bt~& z2wb|BZ|NYc%0EB^mdWc8oN!_c(gMWfMJbOvS$)tY8h|N)&4b+_v0{u{c3x{yOXeLQ z_yucxeJIH6Wr&eEEFi}PtrI{HG+M*x$U&wMai*n_$>=Or;Y2BItuD3a7aMeWrLkIX z(pF=kIY$@fSK3en7#8@X(+yEaT5mU7hD&8AEN&`kU!*)t{0v0{Fm3)OOPMcu8VDHx z4-Jdp8K+4Xwf!g5PogN0=P*((c)G(CCt_PkO2zhucq$~1=nhXskiTaA#34=Fw-C@Z)uBvDE zRR<_7Mbl#(6*XmfHrj0vu^xAd878d5Q`!w#PY;-#1t^0Z-2`LXo*&ICn!UIK`B3E1 H>i~ZP0-U$e literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..b17180d5ca5648fb78a1d99fc16b903c086d5d22 GIT binary patch literal 576 zcmb<-^>JfjWMqH=Mg}_u1P><4z~F#jLfH-stPD&@qU13_c7ZS(n)U{$BY4on1GLos$UUJ4k`>66$G-d`QiXnVFFYo3y=oc!vW<>Kxs*+IFt*g6rhHJ%tr?3 z_V2I(%I4i#S6`YH^8PVsS1*d~r!)Q3<+v0MoJ>Qvd(} literal 0 HcmV?d00001 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