Skip to content

Commit

Permalink
Update repo for releasing publicly
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lockyer committed Nov 23, 2017
1 parent 6297364 commit 5c844cd
Show file tree
Hide file tree
Showing 27 changed files with 30 additions and 69 deletions.
39 changes: 10 additions & 29 deletions README.md
@@ -1,30 +1,11 @@
# plc
# StreASM

| SYNTAX | DESC |
|---|---|
| NXT name, name | |
| MOV dest, src | |
| BS reg, bit, val | |
| INCR reg | |
| DECR reg | |
| ADD dest, src1, src2 | |
| SUB dest, src1, src2 | |
| MUL dest, src1, src2 | |
| DIV dest, src1, src2 | |
| AND dest, src1, src2 | |
| OR dest, src1, src2 | |
| NOR dest, src1, src2 | |
| XOR dest, src1, src2 | |
| NAND dest, src1, src2 | |
| COM dest, src1 | |
| CLR reg | |
| JMP label | |
| CALL label | |
| RET | |
| TSTZ reg, if0, ifn0 | |
| TSTE reg1, reg2, ifeq, ifneq | |
| TSTG reg1, reg2, ifg, ifng | |
| TSTGE reg1, reg2, ifge, ifnge | |
| TSTL reg1, reg2, ifl, ifnl | |
| TSTLE reg1, reg2, ifle, ifnle | |
| TSTB reg, bit, if1, if0 | |
> A stream processing language for the criminally insane
StreASM is a stream processing language styled after Assembly instructions. It operates on numerical inputs.

It was created by [Daniel Lockyer](https://github.com/NeoSilky) and [Jet Holt](https://github.com/Jetroid) as part of the Programming Language Concepts module at the University of Southampton.

The StreASM interpreter is written in OCaml using `ocamllex` and `ocamlyacc`.

Full documentation is in the [project report](https://github.com/neosilky/StreASM/blob/master/docs/StreASMDocumentation.pdf).
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion example/pr1.spl → example/pr1.asm
Expand Up @@ -9,7 +9,7 @@ main:
TSTZ i0, final, @NEXT
MOV o1, r1
NXT stdout, o
MOV r1, i1 ;Update the value in the buffer
MOV r1, i1 ;Update the value in the buffer
JMP main ;Loop

final:
Expand Down
2 changes: 1 addition & 1 deletion example/pr10.spl → example/pr10.asm 100644 → 100755
@@ -1,6 +1,6 @@
;Delayed Feedback
;Take a sequence a1 a2 a3 a4 a5 ... as an input
;and output
;and output
;a1
;a2
;a3 + (a1)
Expand Down
Empty file modified example/pr10input 100644 → 100755
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file modified example/pr6input 100644 → 100755
Empty file.
File renamed without changes.
Empty file modified example/pr7input 100644 → 100755
Empty file.
File renamed without changes.
Empty file modified example/pr8input 100644 → 100755
Empty file.
File renamed without changes.
Empty file modified example/pr9input 100644 → 100755
Empty file.
2 changes: 0 additions & 2 deletions group.txt

This file was deleted.

Binary file removed interpreter.zip
Binary file not shown.
10 changes: 0 additions & 10 deletions make.sh

This file was deleted.

7 changes: 0 additions & 7 deletions make2.sh

This file was deleted.

Binary file removed solutionsAndManual.zip
Binary file not shown.
24 changes: 12 additions & 12 deletions src/Streasm.ml
Expand Up @@ -18,7 +18,7 @@ exception Interpreter_error;;
let throw_error_aux error msg = (print_endline ("[ " ^ (Printexc.to_string error) ^ " - line " ^ (string_of_int !index) ^ " ] " ^ msg); raise error;);;
let throw_error msg = throw_error_aux Interpreter_error msg;;

let map_label (label: string) (line: int) =
let map_label (label: string) (line: int) =
if label <> "" then
if Hashtbl.mem labels label then
if Hashtbl.find labels label = line then ()
Expand All @@ -33,10 +33,10 @@ let rec find_label_aux (label: string) (index: int) =
else find_label_aux label (index + 1)
else throw_error ("Label " ^ label ^ " not defined")

let find_label (label: string) =
if Hashtbl.mem labels label then Hashtbl.find labels label
let find_label (label: string) =
if Hashtbl.mem labels label then Hashtbl.find labels label
else find_label_aux label !index

let get_name_binding (name: string) =
if Hashtbl.mem renamings name then Hashtbl.find renamings name
else throw_error ("The naming " ^ name ^ " is undefined at instruction " ^ (string_of_int !index))
Expand Down Expand Up @@ -78,8 +78,8 @@ let clean_regname (register: string) =
(ident ^ (string_of_int (lookup number)))
else
throw_error ("Expected a register, received '" ^ register ^ "'")
let bind_value (register: string) (value: int) =

let bind_value (register: string) (value: int) =
if ((Str.string_match (Str.regexp regex_reg) register 0) || (Str.string_match (Str.regexp regex_nreg) register 0)) then
Hashtbl.replace registers (clean_regname register) value
else if Str.string_match (Str.regexp regex_str) register 0 then
Expand All @@ -93,7 +93,7 @@ let rename (new_name: string) (register: string) =
else
throw_error ("Expected a register, received '" ^ register ^ "'")

let instr_jmp (label: string) =
let instr_jmp (label: string) =
if label = "@END" then running := false
else if label = "@NEXT" then ()
else index := find_label label
Expand All @@ -112,7 +112,7 @@ let instr_bs (register: string) (pos: int) (v: int) =
let instr_ret () = match !return_stack with
[] -> running := false
| head::rest -> (index := head; return_stack := rest)

let get_string (ident: string) =
try let line = read_line() in
let split = Str.split (Str.regexp " ") line in
Expand All @@ -131,12 +131,12 @@ let rec make_string (ident: string) (target: int) (found: int) (position: int) =
Hashtbl.remove registers register;
make_string ident target (found + 1) (position + 1))
else make_string ident target found (position + 1)
else ()
else ()
else if target <> 0 then
throw_error ("Did not find " ^ (string_of_int target) ^ " values within 1024 indexes of " ^ ident)
else ()
let instr_nxt (iden1: string) (iden2: string) =

let instr_nxt (iden1: string) (iden2: string) =
if iden2 = "stdin" then
if Str.string_match (Str.regexp regex_char) iden1 0 then
get_string iden1
Expand Down Expand Up @@ -195,4 +195,4 @@ let interpret (input: string array array) =
| "DEF" -> rename p1 p2
| _ -> throw_error ("Unknown Instruction: \"" ^ instruction ^ "\"")
with _ as e -> throw_error_aux e "An error occurred when interpreting the file");
done);;
done);;
4 changes: 2 additions & 2 deletions src/lexer.mll
Expand Up @@ -2,7 +2,7 @@
open Lexing
open Parser
exception Syntax_error of string

let instructionPointer = ref 1;;
let syntax_error lexbuf = raise (Syntax_error ("Couldn't identify the token on line " ^ (string_of_int !instructionPointer) ^ " with token \"" ^ (Lexing.lexeme lexbuf) ^ "\""));;
}
Expand All @@ -21,7 +21,7 @@ rule lexer_main = parse
| literal as d { LITERAL (d) }
| register as r { REGISTER (r) }
| comment { lexer_main lexbuf }
| alpha as a { IDENTIFIER (Char.escaped a) }
| alpha as a { IDENTIFIER (Char.escaped a) }
| "," { COMMA }
| ":" { COLON }
| "ADD" { INSTR_ADD }
Expand Down
4 changes: 2 additions & 2 deletions src/mysplinterpreter.ml
Expand Up @@ -4,9 +4,9 @@ open Parser
open Arg
open Printf

let parseProgram c =
let parseProgram c =
let lexbuf = Lexing.from_channel c in
try
try
let parsed = parser_main lexer_main lexbuf in
interpret parsed
with Parsing.Parse_error ->
Expand Down
5 changes: 2 additions & 3 deletions src/parser.mly
@@ -1,6 +1,5 @@
%{
%{
let instructions = ref [];;

let add_line (label: string) (instr: string list) = instructions := Array.of_list (label :: instr) :: !instructions;;
let add_instr instr p1 p2 p3 p4 = instr :: p1 :: p2 ::p3 :: p4 :: [];;
%}
Expand Down Expand Up @@ -48,7 +47,7 @@ eol
| EOL { }
;

tab
tab
: tab TAB { }
| TAB { }
;
Expand Down

0 comments on commit 5c844cd

Please sign in to comment.