Program = { SOI ~ (Instruction ~ Newline)* ~ Instruction? ~ EOI } Instruction = _{ Load | Store | Add | Sub | Mult | Div | Goto | CondGoto | End | CLoad | CAdd | CSub | CMult | CDiv | IndLoad | IndStore | IndAdd | IndSub | IndMult | IndDiv } Load = { ^"LOAD" ~ Integer } Store = { ^"STORE" ~ Integer } Add = { ^"ADD" ~ Integer } Sub = { ^"SUB" ~ Integer } Mult = { ^"MULT" ~ Integer } Div = { ^"DIV" ~ Integer } Goto = { ^"GOTO" ~ Integer } CondGoto = { ^"IF" ~ ^"c(0)" ~ (Eq | Ste | Gte | St | Gt) ~ Integer ~ ^"GOTO" ~ Integer } End = { ^"END" } CLoad = { ^"C" ~ Conjunction ~ ^"LOAD" ~ Integer } CAdd = { ^"C" ~ Conjunction ~ ^"ADD" ~ Integer } CSub = { ^"C" ~ Conjunction ~ ^"SUB" ~ Integer } CMult = { ^"C" ~ Conjunction ~ ^"MULT" ~ Integer } CDiv = { ^"C" ~ Conjunction ~ ^"DIV" ~ Integer } Conjunction = _{ "-" | "_" | "" } IndLoad = { ^"IND" ~ Conjunction ~ ^"LOAD" ~ Integer } IndStore = { ^"IND" ~ Conjunction ~ ^"STORE" ~ Integer } IndAdd = { ^"IND" ~ Conjunction ~ ^"ADD" ~ Integer } IndSub = { ^"IND" ~ Conjunction ~ ^"SUB" ~ Integer } IndMult = { ^"IND" ~ Conjunction ~ ^"MULT" ~ Integer } IndDiv = { ^"IND" ~ Conjunction ~ ^"DIV" ~ Integer } Integer = { ('0'..'9')* } Eq = { "=" } Ste = { "<=" | "≤" } Gte = { ">=" | "≥" } St = { "<" } Gt = { ">" } Newline = _{ "\n" | "\r\n" } WHITESPACE = _{ " " } COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!Newline ~ ANY)*) }