Compare commits
No commits in common. "53cfd52dcd841180e0e20e874df0f0f9d0b92264" and "e4a7bcccc0172f8703c11bd7063063d965bd53b2" have entirely different histories.
53cfd52dcd
...
e4a7bcccc0
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 0x4261756D
|
||||
Copyright (c) <year> <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
@ -1,9 +1,3 @@
|
||||
# kurz
|
||||
|
||||
Queue based language
|
||||
|
||||
## Roadmap
|
||||
- [x] turing completeness
|
||||
- [ ] compiled
|
||||
- [ ] cross-plattform
|
||||
- [ ] self-hosted
|
||||
|
@ -1,29 +0,0 @@
|
||||
filetype: kurz
|
||||
|
||||
detect:
|
||||
filename: "\\.qbl$"
|
||||
|
||||
rules:
|
||||
- comment:
|
||||
start: "//"
|
||||
end: "$"
|
||||
rules:
|
||||
- todo: "(TODO|FIXME):?"
|
||||
- constant.string:
|
||||
start: "\""
|
||||
end: "\""
|
||||
skip: "\\\\."
|
||||
rules:
|
||||
- constant.specialChar: "\\\\."
|
||||
- constant.bool: "\\b(true|false)\\b"
|
||||
# ints
|
||||
- constant.number: "\\b([0-9]*)\\b"
|
||||
- symbol.brackets: "[{}]"
|
||||
# function
|
||||
- identifier: "function"
|
||||
- type: "\\b(bool|int|str|any)\\b"
|
||||
- symbol.operator: "([-+<>]|==|!=|=>|print(ln)?)"
|
||||
- identifier: "\\b(if|else|while)\\b"
|
||||
- special: "\\b(deq|swp|dup|req|depth|decrease)\\b"
|
||||
- special: "\\?\\?\\?"
|
||||
- statement: "arr"
|
42
src/main.rs
42
src/main.rs
@ -180,6 +180,7 @@ fn main()
|
||||
{
|
||||
Ok(maybe_msg) =>
|
||||
{
|
||||
println!("---Successfully parsed '{}'---", args[2]);
|
||||
if let Some(msg) = maybe_msg
|
||||
{
|
||||
print!("---Output---\n\n{}", msg);
|
||||
@ -209,7 +210,7 @@ fn compile(file_content: &String, intrinsics: &HashMap<&str, (Vec<Datatype>, Vec
|
||||
let output = if interpret
|
||||
{
|
||||
println!("---Starting to interpret the program---");
|
||||
Some(interpret_program(&operations, &mut Vec::new(), &functions, &mut arrays, &intrinsics, debug)?)
|
||||
Some(interpret_program(&operations, &mut Vec::new(), &functions, &mut arrays, &intrinsics, debug))
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -218,7 +219,7 @@ fn compile(file_content: &String, intrinsics: &HashMap<&str, (Vec<Datatype>, Vec
|
||||
return Ok(output);
|
||||
}
|
||||
|
||||
fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, functions: &Vec<Function>, arrays: &mut Vec<Arr>, intrinsics: &HashMap<&str, (Vec<Datatype>, Vec<Datatype>)>, debug: bool) -> Result<String,String>
|
||||
fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, functions: &Vec<Function>, arrays: &mut Vec<Arr>, intrinsics: &HashMap<&str, (Vec<Datatype>, Vec<Datatype>)>, debug: bool) -> String
|
||||
{
|
||||
let mut output = String::new();
|
||||
for operation in operations
|
||||
@ -263,7 +264,7 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
||||
let val = queue.remove(0);
|
||||
function_context.push(val);
|
||||
}
|
||||
output += interpret_program(&function.content, function_context, functions, arrays, intrinsics, debug)?.as_str();
|
||||
output += interpret_program(&function.content, function_context, functions, arrays, intrinsics, debug).as_str();
|
||||
for val in function_context
|
||||
{
|
||||
queue.push(val.to_string());
|
||||
@ -274,11 +275,11 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
||||
let val = queue.remove(0);
|
||||
if val == "true"
|
||||
{
|
||||
output += interpret_program(if_block, queue, functions, arrays, intrinsics, debug)?.as_str();
|
||||
output += interpret_program(if_block, queue, functions, arrays, intrinsics, debug).as_str();
|
||||
}
|
||||
else if let Some(else_block) = maybe_else_block
|
||||
{
|
||||
output += interpret_program(else_block, queue, functions, arrays, intrinsics, debug)?.as_str();
|
||||
output += interpret_program(else_block, queue, functions, arrays, intrinsics, debug).as_str();
|
||||
}
|
||||
}
|
||||
Operation::Intrinsic(intrinsic_name, line, col) =>
|
||||
@ -336,7 +337,7 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
||||
}
|
||||
_ =>
|
||||
{
|
||||
return Err(format!("Unexpected intrinsic '{}' at {}:{}", intrinsic_name, line, col));
|
||||
panic!("Unexpected intrinsic '{}' at {}:{}", intrinsic_name, line, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -350,11 +351,7 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
||||
let position: i64 = queue.remove(0).parse::<i64>().unwrap();
|
||||
if position >= arr.length
|
||||
{
|
||||
return Err(format!("Attempted an out of bounds write for array {} ({} >= {}) at {}:{}", arr.name, position, arr.length, line, col));
|
||||
}
|
||||
if position < 0
|
||||
{
|
||||
return Err(format!("Attempted an out of bounds write for array {} ({} < 0) at {}:{}", arr.name, position, line, col));
|
||||
panic!("Attempted an out of bounds write for array {} ({} >= {}) at {}:{}", arr.name, position, arr.length, line, col);
|
||||
}
|
||||
arr.data[position as usize] = queue.remove(0);
|
||||
}
|
||||
@ -363,11 +360,7 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
||||
let position: i64 = queue.remove(0).parse::<i64>().unwrap();
|
||||
if position >= arr.length
|
||||
{
|
||||
return Err(format!("Attempted an out of bounds read for array {} ({} >= {}) at {}:{}", arr.name, position, arr.length, line, col));
|
||||
}
|
||||
if position < 0
|
||||
{
|
||||
return Err(format!("Attempted an out of bounds read for array {} ({} < 0) at {}:{}", arr.name, position, line, col));
|
||||
panic!("Attempted an out of bounds read for array {} ({} >= {}) at {}:{}", arr.name, position, arr.length, line, col);
|
||||
}
|
||||
queue.push(arr.data[position as usize].clone());
|
||||
}
|
||||
@ -375,7 +368,7 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
||||
{
|
||||
queue.push(arr.length.to_string());
|
||||
}
|
||||
_ => return Err(format!("Unexpected application '{}' at {}:{}", word, line, col))
|
||||
_ => panic!("Unexpected application '{}' at {}:{}", word, line, col)
|
||||
}
|
||||
}
|
||||
Operation::While(while_block, _, _) =>
|
||||
@ -387,7 +380,7 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
||||
{
|
||||
break;
|
||||
}
|
||||
output += interpret_program(while_block, queue, functions, arrays, intrinsics, debug)?.as_str();
|
||||
output += interpret_program(while_block, queue, functions, arrays, intrinsics, debug).as_str();
|
||||
}
|
||||
}
|
||||
Operation::Depth(_, _) =>
|
||||
@ -405,7 +398,7 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
||||
println!("after: {:?}: {:?}, '{}'", operation, queue, output);
|
||||
}
|
||||
}
|
||||
return Ok(output);
|
||||
return output;
|
||||
}
|
||||
|
||||
fn typecheck(operations: &Vec<Operation>, functions: &Vec<Function>, intrinsics: &HashMap<&str, (Vec<Datatype>, Vec<Datatype>)>, arrays: &Vec<Arr>, debug: bool) -> Result<(), String>
|
||||
@ -634,10 +627,6 @@ fn get_return_type(operations: &Vec<Operation>, ins: &Vec<Datatype>, functions:
|
||||
return Err(format!("Expected a position for a write application at {}:{}", line, col));
|
||||
}
|
||||
let expected_type = arrays.iter().find(|x| &x.name == name).unwrap().datatype;
|
||||
if type_queue.is_empty()
|
||||
{
|
||||
return Err(format!("Expected data for a write application at {}:{}", line, col));
|
||||
}
|
||||
let actual_type = type_queue.remove(0);
|
||||
if actual_type != expected_type
|
||||
{
|
||||
@ -1198,16 +1187,9 @@ fn tokenize(text: &str) -> Result<Vec<Token>, String>
|
||||
}
|
||||
TokenizerState::Whitespace | TokenizerState::Comment => {},
|
||||
TokenizerState::Keyword =>
|
||||
{
|
||||
if application_name.is_empty()
|
||||
{
|
||||
tokens.push(Token::Keyword(word.clone(), line, col));
|
||||
}
|
||||
else
|
||||
{
|
||||
tokens.push(Token::Apply(application_name.clone(), word.clone(), line, col));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(tokens)
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
//invalid,Attempted an out of bounds read for array test (5 >= 4) at 5:12:END:
|
||||
|
||||
arr test { bool 4 }
|
||||
|
||||
5 test.read deq
|
@ -1,5 +0,0 @@
|
||||
//invalid,Attempted an out of bounds write for array test (5 >= 4) at 5:19:END:
|
||||
|
||||
arr test { bool 4 }
|
||||
|
||||
5 false test.write
|
@ -1,5 +0,0 @@
|
||||
//invalid,Attempted an out of bounds read for array test (-1 < 0) at 5:13:END:
|
||||
|
||||
arr test { bool 4 }
|
||||
|
||||
-1 test.read deq
|
@ -1,5 +0,0 @@
|
||||
//invalid,Attempted an out of bounds write for array test (-1 < 0) at 5:19:END:
|
||||
|
||||
arr test { bool 4 }
|
||||
|
||||
-1 true test.write
|
@ -1,25 +0,0 @@
|
||||
//valid,0000
|
||||
//0100
|
||||
//2100
|
||||
//2103
|
||||
//:END:
|
||||
arr test { int 4 }
|
||||
|
||||
function => dump
|
||||
{
|
||||
true 0
|
||||
while
|
||||
{
|
||||
dup test.read req print
|
||||
1 + test.length dup < req
|
||||
}
|
||||
deq "" println
|
||||
}
|
||||
|
||||
dump
|
||||
1 1 test.write
|
||||
dump
|
||||
0 2 test.write
|
||||
dump
|
||||
3 3 test.write
|
||||
dump
|
@ -1,38 +1,14 @@
|
||||
//valid,---------------------------------#
|
||||
//--------------------------------##
|
||||
//-------------------------------###
|
||||
//------------------------------##-#
|
||||
//-----------------------------#####
|
||||
//----------------------------##---#
|
||||
//---------------------------###--##
|
||||
//--------------------------##-#-###
|
||||
//-------------------------#######-#
|
||||
//------------------------##-----###
|
||||
//-----------------------###----##-#
|
||||
//----------------------##-#---#####
|
||||
//---------------------#####--##---#
|
||||
//--------------------##---#-###--##
|
||||
//-------------------###--####-#-###
|
||||
//------------------##-#-##--#####-#
|
||||
//-----------------########-##---###
|
||||
//----------------##------####--##-#
|
||||
//---------------###-----##--#-#####
|
||||
//--------------##-#----###-####---#
|
||||
//-------------#####---##-###--#--##
|
||||
//------------##---#--#####-#-##-###
|
||||
//-----------###--##-##---########-#
|
||||
//----------##-#-######--##------###
|
||||
//---------#######----#-###-----##-#
|
||||
//--------##-----#---####-#----#####
|
||||
//-------###----##--##--###---##---#
|
||||
//------##-#---###-###-##-#--###--##
|
||||
//-----#####--##-###-######-##-#-###
|
||||
//----##---#-#####-###----########-#
|
||||
//---###--####---###-#---##------###
|
||||
//--##-#-##--#--##-###--###-----##-#
|
||||
//-########-##-#####-#-##-#----#####
|
||||
//##------######---########---##---#
|
||||
//##-----##----#--##------#--###--##
|
||||
//valid,00000000000000110000000000000000
|
||||
//00000000000001110000000000000000
|
||||
//00000000000011010000000000000000
|
||||
//00000000000111110000000000000000
|
||||
//00000000001100010000000000000000
|
||||
//00000000011100110000000000000000
|
||||
//00000000110101110000000000000000
|
||||
//00000001111111010000000000000000
|
||||
//00000011000001110000000000000000
|
||||
//00000111000011010000000000000000
|
||||
//00001101000111110000000000000000
|
||||
//:END:
|
||||
function bool bool bool => bool rule110
|
||||
{
|
||||
@ -59,10 +35,9 @@ function bool bool bool => bool rule110
|
||||
}
|
||||
}
|
||||
|
||||
arr val { bool 34 }
|
||||
arr val { bool 32 }
|
||||
|
||||
33 true val.write
|
||||
printArrays
|
||||
15 true val.write
|
||||
|
||||
function int => bool int check
|
||||
{
|
||||
@ -71,13 +46,7 @@ function int => bool int check
|
||||
|
||||
function => fullApply
|
||||
{
|
||||
// 0 b c
|
||||
0 1 false val.read val.read
|
||||
0 rule110 val2.write
|
||||
val.length 1 - 1 dup - req
|
||||
val.read val.read false
|
||||
rule110 val.length 1
|
||||
req - req val2.write
|
||||
0 false val2.write
|
||||
true 1
|
||||
while
|
||||
{
|
||||
@ -93,7 +62,7 @@ function => fullApply
|
||||
dup val2.write
|
||||
checkUp-1
|
||||
}
|
||||
deq
|
||||
1 - false val2.write
|
||||
}
|
||||
|
||||
function int => bool int checkUp
|
||||
@ -110,7 +79,7 @@ function int => bool int checkUp-1
|
||||
< req
|
||||
}
|
||||
|
||||
arr val2 { bool 34 }
|
||||
arr val2 { bool 32 }
|
||||
|
||||
function => copyArrays
|
||||
{
|
||||
@ -124,15 +93,15 @@ function => copyArrays
|
||||
deq
|
||||
}
|
||||
|
||||
function bool => str boolToSym
|
||||
function bool => int boolToInt
|
||||
{
|
||||
if
|
||||
{
|
||||
"#"
|
||||
1
|
||||
}
|
||||
else
|
||||
{
|
||||
"-"
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,14 +110,14 @@ function => printArrays
|
||||
true 0
|
||||
while
|
||||
{
|
||||
dup val.read req boolToSym req print
|
||||
dup val.read req boolToInt req print
|
||||
checkUp
|
||||
}
|
||||
deq
|
||||
"" println
|
||||
}
|
||||
|
||||
true 33
|
||||
true 10
|
||||
while
|
||||
{
|
||||
fullApply
|
||||
|
Reference in New Issue
Block a user