first commit

This commit is contained in:
Michael Wain 2024-05-25 03:49:08 +03:00
commit 1d44a8bf13
6 changed files with 127 additions and 0 deletions

BIN
asm/test Normal file

Binary file not shown.

5
asm/test.asm Normal file
View File

@ -0,0 +1,5 @@
global _start
_start:
mov rax, 60
mov rdi, 69
syscall

BIN
asm/test.o Normal file

Binary file not shown.

80
haskell/main.hs Normal file
View File

@ -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

1
pascal/test.pas Normal file
View File

@ -0,0 +1 @@
halt(1);

41
pascal/test1.pas Normal file
View File

@ -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.