New page wikitext, after the edit (new_wikitext) | '== Flkl programming language ==
<br>
Flkl is a language made by Salmmanfred in about 3 hours
=== The spec <br> ===
|a = nothing<br>
f = load a string/int into the data<br>
p = print the data in the data<br>
q = quit<br>
m = minus (m10a)<br>
e = if the data is equall to 1 it moves to a new row (e1a)<br>
l = move to line <br>
n = new line<br>
=== Example code <br> ===
this counts down from 100 to 1 and says bruh at 90:<br>
f100|al1a
npm1ae0|2ae90|3al1a
nq
nfbruh|apf89|al1a
hello world: <br>
fhello world|ap
=== Interpreter ===
fn main() {
let x = lext(readFile("test.flkl"));
let p = parses(x);
exc(p.clone(), 0, "".to_string());
}
pub fn readFile(names: &str) -> String {
//reads the file from names
let s = "".to_string();
let fnm = s+&names;
let contents = std::fs::read_to_string(fnm).unwrap();
return contents;
}
#[allow(dead_code)]
#[derive(Debug, PartialEq, Clone)]
pub enum TT {
char(String),
}
#[derive(Clone)]
pub struct Coder {
pub lex: Vec<TT>,
}
impl Coder {
pub fn push(&mut self, tt: TT) {
self.lex.push(tt);
}
pub fn new() -> Coder {
Coder { lex: Vec::new() }
}
// finds the closesest TT after the current_line
pub fn next(&self, chr: &str, current_line: usize) -> usize {
let mut _retur = 0;
//what the fuck did i make here?
let x = self.lex[current_line..self.lex.len()]
.iter()
.position(|x| *x == TT::char(chr.to_string()));
let mut _pos = 0;
match x {
Some(x) => {
_pos = x + current_line;
_retur = _pos;
//println!("test {}", pos);
}
None => {
panic!("cannot find the stop for the if");
}
}
if _retur != 0 {
return _retur;
}
panic!("Next not found {},{}", chr, current_line)
}
}
//this is the lexer that makes everything into a long vector of garbage that the parser then makes into a parsed vector the inter can read
pub fn lext(code: String) -> Vec<Coder> {
let mut coders: Vec<Coder> = Vec::new();
let code: Vec<&str> = code.split("n").collect();
for code in code {
let code: Vec<String> = code.chars().map(|x| x.to_string()).collect();
let code: Vec<&str> = code.iter().map(|x| x.as_str()).collect();
let mut holder = Coder::new();
for char in code.into_iter() {
match char {
"\n" => {}
a => {
holder.push(TT::char(a.to_string()));
} //_=> holder.push(TT::Unknown)
}
}
coders.push(holder);
}
return coders;
}
#[allow(dead_code)]
#[derive(Debug, PartialEq, Clone)]
pub enum Command {
print,
minus(i64),
moveline(usize),
clear,
quit,
load(String),
If(String,usize),
}
#[derive(Clone)]
pub struct Parse {
pub parsed_data: Vec<Command>,
}
impl Parse {
pub fn new() -> Parse {
Parse {
parsed_data: Vec::new(),
}
}
pub fn push(&mut self, ty: Command) {
self.parsed_data.push(ty);
}
}
fn parses(code: Vec<Coder>) -> Vec<Parse> {
let mut pr: Vec<Parse> = Vec::new();
for code in code {
let mut prs = Parse::new();
let mut mof = 0;
for x in 0..code.lex.len() {
let x = x + mof;
if x >= code.lex.len() {
break;
}
let ln = code.lex[x].clone();
let mut s = "".to_string();
match ln {
TT::char(a) => s.push_str(a.as_str()),
}
match s.as_str().clone() {
"a" => {}
"f" => {
let op = code.next("|", x);
prs.push(Command::load(col([x + 1, op], code.clone())));
mof += op - x;
}
"l" => {
let op = code.next("a", x);
let line = col([x + 1, op], code.clone()).parse::<usize>().unwrap();
prs.push(Command::moveline(line));
mof += op - x;
}
"p" => prs.push(Command::print),
"e" => {
let op1 = code.next("|", x);
let arg1 = col([x + 1, op1], code.clone());
let op = code.next("a", x);
let arg2 = col([op1+1, op], code.clone()).parse::<usize>().unwrap();
//panic!("{}",arg2);
prs.push(Command::If(arg1,arg2));
mof += op - x;
}
"m" => {
let op = code.next("a", x);
let min = col([x + 1, op], code.clone()).parse::<i64>().unwrap();
prs.push(Command::minus(min));
mof += op - x;
}
"q"=>prs.push(Command::quit),
a => {
panic!("not implemented {},{},{}", a, mof, x)
}
}
}
pr.push(prs);
}
pr
}
fn col(x: [usize; 2], code: Coder) -> String {
let mut str = "".to_string();
for x in x[0]..x[1] {
match code.lex[x].clone() {
TT::char(a) => {
str.push_str(a.as_str());
}
}
}
str
}
fn exc(ps: Vec<Parse>, i: usize, data: String) {
let p = ps[i].clone();
let mut data = data;
for x in p.parsed_data.clone() {
match x {
Command::load(s) => {
data = s;
}
Command::print => {
println!("{}", data);
}
Command::moveline(a) => {
exc(ps.clone(), a, data.clone());
break;
}
Command::If(a,b) => {
if data == a {
exc(ps.clone(), b, data.clone());
break;
}
}
Command::minus(s) => {
if data.parse::<i64>().is_ok() {
let d = data.parse::<i64>().unwrap();
let d = d - s;
data = d.to_string();
}
}
Command::quit =>{
panic!("quit");
}
_ => {
panic!("idiot");
}
}
}
}
<br>
[[Category:Implemented]]
[[Category:Interpreted]]
[[Category:Languages]]
[[Category:2021]]' |
Unified diff of changes made by edit (edit_diff) | '@@ -1,0 +1,237 @@
+== Flkl programming language ==
+<br>
+Flkl is a language made by Salmmanfred in about 3 hours
+
+=== The spec <br> ===
+|a = nothing<br>
+f = load a string/int into the data<br>
+p = print the data in the data<br>
+q = quit<br>
+m = minus (m10a)<br>
+e = if the data is equall to 1 it moves to a new row (e1a)<br>
+l = move to line <br>
+n = new line<br>
+=== Example code <br> ===
+this counts down from 100 to 1 and says bruh at 90:<br>
+ f100|al1a
+ npm1ae0|2ae90|3al1a
+ nq
+ nfbruh|apf89|al1a
+
+hello world: <br>
+ fhello world|ap
+
+
+=== Interpreter ===
+ fn main() {
+ let x = lext(readFile("test.flkl"));
+ let p = parses(x);
+ exc(p.clone(), 0, "".to_string());
+ }
+ pub fn readFile(names: &str) -> String {
+ //reads the file from names
+ let s = "".to_string();
+ let fnm = s+&names;
+ let contents = std::fs::read_to_string(fnm).unwrap();
+ return contents;
+
+ }
+
+ #[allow(dead_code)]
+ #[derive(Debug, PartialEq, Clone)]
+ pub enum TT {
+ char(String),
+ }
+ #[derive(Clone)]
+ pub struct Coder {
+ pub lex: Vec<TT>,
+ }
+ impl Coder {
+ pub fn push(&mut self, tt: TT) {
+ self.lex.push(tt);
+ }
+ pub fn new() -> Coder {
+ Coder { lex: Vec::new() }
+ }
+ // finds the closesest TT after the current_line
+ pub fn next(&self, chr: &str, current_line: usize) -> usize {
+ let mut _retur = 0;
+ //what the fuck did i make here?
+ let x = self.lex[current_line..self.lex.len()]
+ .iter()
+ .position(|x| *x == TT::char(chr.to_string()));
+ let mut _pos = 0;
+ match x {
+ Some(x) => {
+ _pos = x + current_line;
+ _retur = _pos;
+ //println!("test {}", pos);
+ }
+ None => {
+ panic!("cannot find the stop for the if");
+ }
+ }
+ if _retur != 0 {
+ return _retur;
+ }
+ panic!("Next not found {},{}", chr, current_line)
+ }
+ }
+ //this is the lexer that makes everything into a long vector of garbage that the parser then makes into a parsed vector the inter can read
+ pub fn lext(code: String) -> Vec<Coder> {
+ let mut coders: Vec<Coder> = Vec::new();
+ let code: Vec<&str> = code.split("n").collect();
+ for code in code {
+ let code: Vec<String> = code.chars().map(|x| x.to_string()).collect();
+ let code: Vec<&str> = code.iter().map(|x| x.as_str()).collect();
+ let mut holder = Coder::new();
+ for char in code.into_iter() {
+ match char {
+ "\n" => {}
+ a => {
+ holder.push(TT::char(a.to_string()));
+ } //_=> holder.push(TT::Unknown)
+ }
+ }
+ coders.push(holder);
+ }
+ return coders;
+ }
+ #[allow(dead_code)]
+ #[derive(Debug, PartialEq, Clone)]
+ pub enum Command {
+ print,
+ minus(i64),
+ moveline(usize),
+ clear,
+ quit,
+ load(String),
+ If(String,usize),
+ }
+ #[derive(Clone)]
+ pub struct Parse {
+ pub parsed_data: Vec<Command>,
+ }
+ impl Parse {
+ pub fn new() -> Parse {
+ Parse {
+ parsed_data: Vec::new(),
+ }
+ }
+ pub fn push(&mut self, ty: Command) {
+ self.parsed_data.push(ty);
+ }
+ }
+
+ fn parses(code: Vec<Coder>) -> Vec<Parse> {
+ let mut pr: Vec<Parse> = Vec::new();
+ for code in code {
+ let mut prs = Parse::new();
+ let mut mof = 0;
+ for x in 0..code.lex.len() {
+ let x = x + mof;
+ if x >= code.lex.len() {
+ break;
+ }
+ let ln = code.lex[x].clone();
+ let mut s = "".to_string();
+
+ match ln {
+ TT::char(a) => s.push_str(a.as_str()),
+ }
+ match s.as_str().clone() {
+ "a" => {}
+ "f" => {
+ let op = code.next("|", x);
+ prs.push(Command::load(col([x + 1, op], code.clone())));
+ mof += op - x;
+ }
+ "l" => {
+ let op = code.next("a", x);
+ let line = col([x + 1, op], code.clone()).parse::<usize>().unwrap();
+ prs.push(Command::moveline(line));
+ mof += op - x;
+ }
+ "p" => prs.push(Command::print),
+ "e" => {
+ let op1 = code.next("|", x);
+ let arg1 = col([x + 1, op1], code.clone());
+ let op = code.next("a", x);
+ let arg2 = col([op1+1, op], code.clone()).parse::<usize>().unwrap();
+ //panic!("{}",arg2);
+ prs.push(Command::If(arg1,arg2));
+ mof += op - x;
+ }
+ "m" => {
+ let op = code.next("a", x);
+ let min = col([x + 1, op], code.clone()).parse::<i64>().unwrap();
+ prs.push(Command::minus(min));
+ mof += op - x;
+ }
+ "q"=>prs.push(Command::quit),
+
+ a => {
+ panic!("not implemented {},{},{}", a, mof, x)
+ }
+ }
+ }
+ pr.push(prs);
+ }
+ pr
+ }
+ fn col(x: [usize; 2], code: Coder) -> String {
+ let mut str = "".to_string();
+ for x in x[0]..x[1] {
+ match code.lex[x].clone() {
+ TT::char(a) => {
+ str.push_str(a.as_str());
+ }
+ }
+ }
+ str
+ }
+ fn exc(ps: Vec<Parse>, i: usize, data: String) {
+ let p = ps[i].clone();
+ let mut data = data;
+ for x in p.parsed_data.clone() {
+ match x {
+ Command::load(s) => {
+ data = s;
+ }
+ Command::print => {
+ println!("{}", data);
+ }
+ Command::moveline(a) => {
+ exc(ps.clone(), a, data.clone());
+ break;
+ }
+ Command::If(a,b) => {
+
+ if data == a {
+ exc(ps.clone(), b, data.clone());
+ break;
+ }
+
+ }
+ Command::minus(s) => {
+ if data.parse::<i64>().is_ok() {
+ let d = data.parse::<i64>().unwrap();
+ let d = d - s;
+ data = d.to_string();
+ }
+ }
+ Command::quit =>{
+ panic!("quit");
+ }
+
+ _ => {
+ panic!("idiot");
+ }
+ }
+ }
+ }
+<br>
+[[Category:Implemented]]
+[[Category:Interpreted]]
+[[Category:Languages]]
+[[Category:2021]]
' |
Lines added in edit (added_lines) | [
0 => '== Flkl programming language ==',
1 => '<br>',
2 => 'Flkl is a language made by Salmmanfred in about 3 hours ',
3 => '',
4 => '=== The spec <br> ===',
5 => '|a = nothing<br>',
6 => 'f = load a string/int into the data<br>',
7 => 'p = print the data in the data<br>',
8 => 'q = quit<br>',
9 => 'm = minus (m10a)<br>',
10 => 'e = if the data is equall to 1 it moves to a new row (e1a)<br>',
11 => 'l = move to line <br>',
12 => 'n = new line<br>',
13 => '=== Example code <br> ===',
14 => 'this counts down from 100 to 1 and says bruh at 90:<br>',
15 => ' f100|al1a',
16 => ' npm1ae0|2ae90|3al1a',
17 => ' nq',
18 => ' nfbruh|apf89|al1a',
19 => '',
20 => 'hello world: <br>',
21 => ' fhello world|ap',
22 => '',
23 => ' ',
24 => '=== Interpreter ===',
25 => ' fn main() {',
26 => ' let x = lext(readFile("test.flkl"));',
27 => ' let p = parses(x);',
28 => ' exc(p.clone(), 0, "".to_string());',
29 => ' }',
30 => ' pub fn readFile(names: &str) -> String {',
31 => ' //reads the file from names',
32 => ' let s = "".to_string();',
33 => ' let fnm = s+&names;',
34 => ' let contents = std::fs::read_to_string(fnm).unwrap();',
35 => ' return contents;',
36 => ' ',
37 => ' }',
38 => ' ',
39 => ' #[allow(dead_code)]',
40 => ' #[derive(Debug, PartialEq, Clone)]',
41 => ' pub enum TT {',
42 => ' char(String),',
43 => ' }',
44 => ' #[derive(Clone)]',
45 => ' pub struct Coder {',
46 => ' pub lex: Vec<TT>,',
47 => ' }',
48 => ' impl Coder {',
49 => ' pub fn push(&mut self, tt: TT) {',
50 => ' self.lex.push(tt);',
51 => ' }',
52 => ' pub fn new() -> Coder {',
53 => ' Coder { lex: Vec::new() }',
54 => ' }',
55 => ' // finds the closesest TT after the current_line',
56 => ' pub fn next(&self, chr: &str, current_line: usize) -> usize {',
57 => ' let mut _retur = 0;',
58 => ' //what the fuck did i make here? ',
59 => ' let x = self.lex[current_line..self.lex.len()]',
60 => ' .iter()',
61 => ' .position(|x| *x == TT::char(chr.to_string()));',
62 => ' let mut _pos = 0;',
63 => ' match x {',
64 => ' Some(x) => {',
65 => ' _pos = x + current_line;',
66 => ' _retur = _pos;',
67 => ' //println!("test {}", pos);',
68 => ' }',
69 => ' None => {',
70 => ' panic!("cannot find the stop for the if");',
71 => ' }',
72 => ' }',
73 => ' if _retur != 0 {',
74 => ' return _retur;',
75 => ' }',
76 => ' panic!("Next not found {},{}", chr, current_line)',
77 => ' }',
78 => ' }',
79 => ' //this is the lexer that makes everything into a long vector of garbage that the parser then makes into a parsed vector the inter can read',
80 => ' pub fn lext(code: String) -> Vec<Coder> {',
81 => ' let mut coders: Vec<Coder> = Vec::new();',
82 => ' let code: Vec<&str> = code.split("n").collect();',
83 => ' for code in code {',
84 => ' let code: Vec<String> = code.chars().map(|x| x.to_string()).collect();',
85 => ' let code: Vec<&str> = code.iter().map(|x| x.as_str()).collect();',
86 => ' let mut holder = Coder::new();',
87 => ' for char in code.into_iter() {',
88 => ' match char {',
89 => ' "\n" => {}',
90 => ' a => {',
91 => ' holder.push(TT::char(a.to_string()));',
92 => ' } //_=> holder.push(TT::Unknown)',
93 => ' }',
94 => ' }',
95 => ' coders.push(holder);',
96 => ' }',
97 => ' return coders;',
98 => ' }',
99 => ' #[allow(dead_code)]',
100 => ' #[derive(Debug, PartialEq, Clone)]',
101 => ' pub enum Command {',
102 => ' print,',
103 => ' minus(i64),',
104 => ' moveline(usize),',
105 => ' clear,',
106 => ' quit,',
107 => ' load(String),',
108 => ' If(String,usize),',
109 => ' }',
110 => ' #[derive(Clone)]',
111 => ' pub struct Parse {',
112 => ' pub parsed_data: Vec<Command>,',
113 => ' }',
114 => ' impl Parse {',
115 => ' pub fn new() -> Parse {',
116 => ' Parse {',
117 => ' parsed_data: Vec::new(),',
118 => ' }',
119 => ' }',
120 => ' pub fn push(&mut self, ty: Command) {',
121 => ' self.parsed_data.push(ty);',
122 => ' }',
123 => ' }',
124 => ' ',
125 => ' fn parses(code: Vec<Coder>) -> Vec<Parse> {',
126 => ' let mut pr: Vec<Parse> = Vec::new();',
127 => ' for code in code {',
128 => ' let mut prs = Parse::new();',
129 => ' let mut mof = 0;',
130 => ' for x in 0..code.lex.len() {',
131 => ' let x = x + mof;',
132 => ' if x >= code.lex.len() {',
133 => ' break;',
134 => ' }',
135 => ' let ln = code.lex[x].clone();',
136 => ' let mut s = "".to_string();',
137 => ' ',
138 => ' match ln {',
139 => ' TT::char(a) => s.push_str(a.as_str()),',
140 => ' }',
141 => ' match s.as_str().clone() {',
142 => ' "a" => {}',
143 => ' "f" => {',
144 => ' let op = code.next("|", x);',
145 => ' prs.push(Command::load(col([x + 1, op], code.clone())));',
146 => ' mof += op - x;',
147 => ' }',
148 => ' "l" => {',
149 => ' let op = code.next("a", x);',
150 => ' let line = col([x + 1, op], code.clone()).parse::<usize>().unwrap();',
151 => ' prs.push(Command::moveline(line));',
152 => ' mof += op - x;',
153 => ' }',
154 => ' "p" => prs.push(Command::print),',
155 => ' "e" => {',
156 => ' let op1 = code.next("|", x);',
157 => ' let arg1 = col([x + 1, op1], code.clone());',
158 => ' let op = code.next("a", x);',
159 => ' let arg2 = col([op1+1, op], code.clone()).parse::<usize>().unwrap();',
160 => ' //panic!("{}",arg2);',
161 => ' prs.push(Command::If(arg1,arg2));',
162 => ' mof += op - x;',
163 => ' }',
164 => ' "m" => {',
165 => ' let op = code.next("a", x);',
166 => ' let min = col([x + 1, op], code.clone()).parse::<i64>().unwrap();',
167 => ' prs.push(Command::minus(min));',
168 => ' mof += op - x;',
169 => ' }',
170 => ' "q"=>prs.push(Command::quit),',
171 => ' ',
172 => ' a => {',
173 => ' panic!("not implemented {},{},{}", a, mof, x)',
174 => ' }',
175 => ' }',
176 => ' }',
177 => ' pr.push(prs);',
178 => ' }',
179 => ' pr',
180 => ' }',
181 => ' fn col(x: [usize; 2], code: Coder) -> String {',
182 => ' let mut str = "".to_string();',
183 => ' for x in x[0]..x[1] {',
184 => ' match code.lex[x].clone() {',
185 => ' TT::char(a) => {',
186 => ' str.push_str(a.as_str());',
187 => ' }',
188 => ' }',
189 => ' }',
190 => ' str',
191 => ' }',
192 => ' fn exc(ps: Vec<Parse>, i: usize, data: String) {',
193 => ' let p = ps[i].clone();',
194 => ' let mut data = data;',
195 => ' for x in p.parsed_data.clone() {',
196 => ' match x {',
197 => ' Command::load(s) => {',
198 => ' data = s;',
199 => ' }',
200 => ' Command::print => {',
201 => ' println!("{}", data);',
202 => ' }',
203 => ' Command::moveline(a) => {',
204 => ' exc(ps.clone(), a, data.clone());',
205 => ' break;',
206 => ' }',
207 => ' Command::If(a,b) => {',
208 => ' ',
209 => ' if data == a {',
210 => ' exc(ps.clone(), b, data.clone());',
211 => ' break;',
212 => ' }',
213 => ' ',
214 => ' }',
215 => ' Command::minus(s) => {',
216 => ' if data.parse::<i64>().is_ok() {',
217 => ' let d = data.parse::<i64>().unwrap();',
218 => ' let d = d - s;',
219 => ' data = d.to_string();',
220 => ' }',
221 => ' }',
222 => ' Command::quit =>{',
223 => ' panic!("quit");',
224 => ' }',
225 => ' ',
226 => ' _ => {',
227 => ' panic!("idiot");',
228 => ' }',
229 => ' }',
230 => ' }',
231 => ' }',
232 => '<br>',
233 => '[[Category:Implemented]]',
234 => '[[Category:Interpreted]]',
235 => '[[Category:Languages]]',
236 => '[[Category:2021]]'
] |