mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-15 19:28:47 +00:00
Yep...
This commit is contained in:
parent
1a33860560
commit
f10cdcf2e8
2 changed files with 4 additions and 40 deletions
|
|
@ -77,26 +77,7 @@ module Expr =
|
||||||
|
|
||||||
*)
|
*)
|
||||||
ostap (
|
ostap (
|
||||||
parse:
|
parse: empty {failwith "Not yet implemented"}
|
||||||
!(Ostap.Util.expr
|
|
||||||
(fun x -> x)
|
|
||||||
(Array.map (fun (a, s) -> a,
|
|
||||||
List.map (fun s -> ostap(- $(s)), (fun x y -> Binop (s, x, y))) s
|
|
||||||
)
|
|
||||||
[|
|
|
||||||
`Lefta, ["!!"];
|
|
||||||
`Lefta, ["&&"];
|
|
||||||
`Nona , ["=="; "!="; "<="; "<"; ">="; ">"];
|
|
||||||
`Lefta, ["+" ; "-"];
|
|
||||||
`Lefta, ["*" ; "/"; "%"];
|
|
||||||
|]
|
|
||||||
)
|
|
||||||
primary);
|
|
||||||
|
|
||||||
primary:
|
|
||||||
n:DECIMAL {Const n}
|
|
||||||
| x:IDENT {Var x}
|
|
||||||
| -"(" parse -")"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -130,13 +111,7 @@ module Stmt =
|
||||||
|
|
||||||
(* Statement parser *)
|
(* Statement parser *)
|
||||||
ostap (
|
ostap (
|
||||||
parse:
|
parse: empty {failwith "Not yet implemented"}
|
||||||
s:stmt ";" ss:parse {Seq (s, ss)}
|
|
||||||
| stmt;
|
|
||||||
stmt:
|
|
||||||
"read" "(" x:IDENT ")" {Read x}
|
|
||||||
| "write" "(" e:!(Expr.parse) ")" {Write e}
|
|
||||||
| x:IDENT ":=" e:!(Expr.parse) {Assign (x, e)}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
15
src/SM.ml
15
src/SM.ml
|
|
@ -23,19 +23,8 @@ type config = int list * Stmt.config
|
||||||
val eval : config -> prg -> config
|
val eval : config -> prg -> config
|
||||||
|
|
||||||
Takes a configuration and a program, and returns a configuration as a result
|
Takes a configuration and a program, and returns a configuration as a result
|
||||||
*)
|
*)
|
||||||
let rec eval ((stack, ((st, i, o) as c)) as conf) = function
|
let rec eval conf prog = failwith "Not yet implemented"
|
||||||
| [] -> conf
|
|
||||||
| insn :: prg' ->
|
|
||||||
eval
|
|
||||||
(match insn with
|
|
||||||
| BINOP op -> let y::x::stack' = stack in (Expr.to_func op x y :: stack', c)
|
|
||||||
| READ -> let z::i' = i in (z::stack, (st, i', o))
|
|
||||||
| WRITE -> let z::stack' = stack in (stack', (st, i, o @ [z]))
|
|
||||||
| CONST i -> (i::stack, c)
|
|
||||||
| LD x -> (st x :: stack, c)
|
|
||||||
| ST x -> let z::stack' = stack in (stack', (Expr.update x z st, i, o))
|
|
||||||
) prg'
|
|
||||||
|
|
||||||
(* Top-level evaluation
|
(* Top-level evaluation
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue