Web-Ide mit aufgenommen

This commit is contained in:
Riwoldt
2026-04-09 14:14:56 +02:00
parent 64816c45cc
commit 15cfaf332d
489 changed files with 186891 additions and 0 deletions
@@ -0,0 +1 @@
.ohm.js
@@ -0,0 +1,21 @@
ASM <: Base {
Root := ASM
ASM = intermediateInstruction* instruction?
instruction = label|aInstruction|cInstruction
intermediateInstruction = instruction space+
identifier := (letter|underscore|dot|dollar|colon) (alnum|underscore|dot|dollar|colon)*
label = openParen identifier closeParen
aInstruction = at (identifier | decNumber)
cInstruction = assign? op jmp?
assignChar = "A" | "M" | "D"
opChar = assignChar | "0" | "1" | "!" | "-" | "+" | "|" | "&"
assign = assignChar+ equal
op = opChar+
jmp = semi ("JGT" | "JEQ" | "JGE" | "JLT" | "JNE" | "JLE" | "JMP")
}
@@ -0,0 +1,22 @@
const asm = `ASM <: Base {
Root := ASM
ASM = intermediateInstruction* instruction?
instruction = label|aInstruction|cInstruction
intermediateInstruction = instruction space+
identifier := (letter|underscore|dot|dollar|colon) (alnum|underscore|dot|dollar|colon)*
label = openParen identifier closeParen
aInstruction = at (identifier | decNumber)
cInstruction = assign? op jmp?
assignChar = "A" | "M" | "D"
opChar = assignChar | "0" | "1" | "!" | "-" | "+" | "|" | "&"
assign = assignChar+ equal
op = opChar+
jmp = semi ("JGT" | "JEQ" | "JGE" | "JLT" | "JNE" | "JLE" | "JMP")
}`;
export default asm;
@@ -0,0 +1,77 @@
Base {
Root = Value*
At = at
Bang = bang
Bar = bar
CloseAngle = closeAngle
CloseBrace = closeBrace
CloseParen = closeParen
CloseSquare = closeSquare
Comma = comma
Dollar = dollar
Dot = dot
DoubleQuote = doubleQuote
Equal = equal
OpenAngle = openAngle
OpenBrace = openBrace
OpenParen = openParen
OpenSquare = openSquare
Percent = percent
Semi = semi
Underscore = underscore
at = "@"
bang = "!"
bar = "|"
closeAngle = ">"
closeBrace = "}"
closeParen = ")"
closeSquare = "]"
comma = ","
dollar = "$"
dot = "."
doubleQuote = "\""
equal = "="
minus = "-"
newline = "\r"? "\n"
openAngle = "<"
openBrace = "{"
openParen = "("
openSquare = "["
percent = "%"
semi = ";"
underscore = "_"
colon = ":"
Value = identifier | number | boolean
boolean = true | false
True = true
False = false
true = "true"
false = "false"
Name = identifier
identifier = (letter|underscore|dot|dollar) (alnum|underscore|dot|dollar)*
Number = number
number = hexNumber | decNumber | binNumber
binNumber = ("%B") ("0"|"1")+
hexNumber = ("%X") hexDigit+
decNumber = ("%D")? (wholeDec | realDec)
wholeDec = minus? digit+
realDec = minus? digit* "." digit+
String = DoubleQuote (~doubleQuote any)* doubleQuote
spaces := (lineComment | comment | space)*
commentStart = "/*"
commentEnd = "*/"
comment = commentStart (~commentEnd any)* commentEnd
lineCommentStart = "//"
lineComment = lineCommentStart (~"\n" any)*
List<elem, sep> = NonemptyListOf<elem, sep> sep?
EmptyList<elem, sep> = EmptyList<elem, sep> sep?
}
@@ -0,0 +1,79 @@
const base = `
Base {
Root = Value*
At = at
Bang = bang
Bar = bar
CloseAngle = closeAngle
CloseBrace = closeBrace
CloseParen = closeParen
CloseSquare = closeSquare
Comma = comma
Dollar = dollar
Dot = dot
DoubleQuote = doubleQuote
Equal = equal
OpenAngle = openAngle
OpenBrace = openBrace
OpenParen = openParen
OpenSquare = openSquare
Percent = percent
Semi = semi
Underscore = underscore
at = "@"
bang = "!"
bar = "|"
closeAngle = ">"
closeBrace = "}"
closeParen = ")"
closeSquare = "]"
comma = ","
dollar = "$"
dot = "."
doubleQuote = "\\""
equal = "="
minus = "-"
newline = "\\r"? "\\n"
openAngle = "<"
openBrace = "{"
openParen = "("
openSquare = "["
percent = "%"
semi = ";"
underscore = "_"
colon = ":"
Value = identifier | number | boolean
boolean = true | false
True = true
False = false
true = "true"
false = "false"
Name = identifier
identifier = (letter|underscore|dot|dollar) (alnum|underscore|dot|dollar)*
Number = number
number = hexNumber | decNumber | binNumber
binNumber = ("%B") ("0"|"1")+
hexNumber = ("%X") hexDigit+
decNumber = ("%D")? (wholeDec | realDec)
wholeDec = minus? digit+
realDec = minus? digit* "." digit+
String = DoubleQuote (~doubleQuote any)* doubleQuote
spaces := (lineComment | comment | space)*
commentStart = "/*"
commentEnd = "*/"
comment = commentStart (~commentEnd any)* commentEnd
lineCommentStart = "//"
lineComment = lineCommentStart (~"\\n" any)*
List<elem, sep> = NonemptyListOf<elem, sep> sep?
EmptyList<elem, sep> = EmptyList<elem, sep> sep?
}`;
export default base;
@@ -0,0 +1,6 @@
Cmp <: Base {
Root := line*
line = bar cell+ newline?
cell = cellvalue bar
cellvalue = (~(bar|newline) any)*
}
@@ -0,0 +1,8 @@
const cmp = `
Cmp <: Base {
Root := line*
line = bar cell+ newline?
cell = cellvalue bar
cellvalue = (~(bar|newline) any)*
}`;
export default cmp;
@@ -0,0 +1,23 @@
Hdl <: Base{
Root := Chip
identifier := (letter) (alnum)*
Name := identifier
Chip = "CHIP" Name OpenBrace ChipBody CloseBrace
ChipBody = InList? OutList? PartList ClockedList?
InList = "IN" PinList Semi
OutList = "OUT" PinList Semi
PartList = BuiltinPart | Parts
PinList = List<PinDecl, Comma>
PinDecl = Name PinWidth?
PinWidth = OpenSquare decNumber CloseSquare
BuiltinPart = "BUILTIN" Semi
Parts = "PARTS:" Part*
Part = Name "(" Wires ")" Semi
Wires = List<Wire, Comma>
Wire = WireSide Equal (WireSide | True | False)
WireSide = Name SubBus?
SubBus = OpenSquare decNumber subBusRest? CloseSquare
subBusRest = ".." decNumber
ClockedList = "CLOCKED" SimplePinList Semi
SimplePinList = List<Name, Comma>
}
@@ -0,0 +1,25 @@
const hdl = `
Hdl <: Base{
Root := Chip
identifier := (letter) (alnum)*
Name := identifier
Chip = "CHIP" Name OpenBrace ChipBody CloseBrace
ChipBody = InList? OutList? PartList ClockedList?
InList = "IN" PinList Semi
OutList = "OUT" PinList Semi
PartList = BuiltinPart | Parts
PinList = List<PinDecl, Comma>
PinDecl = Name PinWidth?
PinWidth = OpenSquare decNumber CloseSquare
BuiltinPart = "BUILTIN" Semi
Parts = "PARTS:" Part*
Part = Name "(" Wires ")" Semi
Wires = List<Wire, Comma>
Wire = WireSide Equal (WireSide | True | False)
WireSide = Name SubBus?
SubBus = OpenSquare decNumber subBusRest? CloseSquare
subBusRest = ".." decNumber
ClockedList = "CLOCKED" SimplePinList Semi
SimplePinList = List<Name, Comma>
}`;
export default hdl;
@@ -0,0 +1,78 @@
Jack <: Base {
Root := Class
whitespace = (lineComment | comment | space)
class = "class" whitespace+
Class = class jackIdentifier OpenBrace ClassVarDec* SubroutineDec* CloseBrace
type = ("int" | "char" | "boolean" | jackIdentifier) whitespace+
classVarType = ("static" | "field") whitespace+
ClassVarDec = classVarType type jackIdentifier TrailingIdentifier* Semi
TrailingIdentifier = Comma jackIdentifier
void = "void" whitespace+
returnType = (type | void)
subroutineType = ("constructor" | "function" | "method") whitespace+
SubroutineDec = subroutineType returnType jackIdentifier OpenParen ParameterList CloseParen SubroutineBody
Parameter = type jackIdentifier
Parameters = Parameter TrailingParameter*
TrailingParameter = Comma Parameter
ParameterList = Parameters?
SubroutineBody = OpenBrace VarDec* Statement* CloseBrace
var = "var" whitespace+
VarDec = var type jackIdentifier TrailingIdentifier* Semi
Statement = LetStatement | IfStatement | WhileStatement | DoStatement | ReturnStatement
arrayAccessStart = jackIdentifier openSquare
ArrayAccess = arrayAccessStart Expression CloseSquare
let = "let" whitespace+
LetTarget = ArrayAccess | jackIdentifier
LetStatement = let LetTarget Equal Expression Semi
IfStatement = "if" OpenParen Expression CloseParen OpenBrace Statement* CloseBrace ElseBlock?
ElseBlock = "else" OpenBrace Statement* CloseBrace
WhileStatement = "while" OpenParen Expression CloseParen OpenBrace Statement* CloseBrace
do = "do" whitespace+
DoStatement = do SubroutineCall Semi
return = "return"
returnWithSpace = "return" whitespace+
ReturnStatement = EmptyReturn | ReturnValue
EmptyReturn = return Semi
ReturnValue = returnWithSpace Expression Semi
op = "+" | "-" | "*" | "/" | "&" | "|" | "<" | ">" | "="
ExpressionPart = op Term
Expression = Term ExpressionPart*
integerConstant = digit+
stringConstant = doubleQuote (~doubleQuote ~newline any)* doubleQuote
keywordConstant = "true" | "false" | "null" | "this"
GroupedExpression = OpenParen Expression CloseParen
unaryOp = "-" | "~"
UnaryExpression = unaryOp Term
Term = integerConstant | stringConstant | keywordConstant | SubroutineCall | ArrayAccess | jackIdentifier | GroupedExpression | UnaryExpression
compoundIdentifier = jackIdentifier dot jackIdentifier
SubroutineName = compoundIdentifier | jackIdentifier
SubroutineCall = SubroutineName OpenParen ExpressionList CloseParen
ExpressionList = Expressions?
Expressions = Expression TrailingExpression*
TrailingExpression = Comma Expression
jackIdentifier = letter (alnum | underscore)*
}
@@ -0,0 +1,80 @@
const jack = `Jack <: Base {
Root := Class
whitespace = (lineComment | comment | space)
class = "class" whitespace+
Class = class jackIdentifier OpenBrace ClassVarDec* SubroutineDec* CloseBrace
type = ("int" | "char" | "boolean" | jackIdentifier) whitespace+
classVarType = ("static" | "field") whitespace+
ClassVarDec = classVarType type jackIdentifier TrailingIdentifier* Semi
TrailingIdentifier = Comma jackIdentifier
void = "void" whitespace+
returnType = (type | void)
subroutineType = ("constructor" | "function" | "method") whitespace+
SubroutineDec = subroutineType returnType jackIdentifier OpenParen ParameterList CloseParen SubroutineBody
Parameter = type jackIdentifier
Parameters = Parameter TrailingParameter*
TrailingParameter = Comma Parameter
ParameterList = Parameters?
SubroutineBody = OpenBrace VarDec* Statement* CloseBrace
var = "var" whitespace+
VarDec = var type jackIdentifier TrailingIdentifier* Semi
Statement = LetStatement | IfStatement | WhileStatement | DoStatement | ReturnStatement
arrayAccessStart = jackIdentifier openSquare
ArrayAccess = arrayAccessStart Expression CloseSquare
let = "let" whitespace+
LetTarget = ArrayAccess | jackIdentifier
LetStatement = let LetTarget Equal Expression Semi
IfStatement = "if" OpenParen Expression CloseParen OpenBrace Statement* CloseBrace ElseBlock?
ElseBlock = "else" OpenBrace Statement* CloseBrace
WhileStatement = "while" OpenParen Expression CloseParen OpenBrace Statement* CloseBrace
do = "do" whitespace+
DoStatement = do SubroutineCall Semi
return = "return"
returnWithSpace = "return" whitespace+
ReturnStatement = EmptyReturn | ReturnValue
EmptyReturn = return Semi
ReturnValue = returnWithSpace Expression Semi
op = "+" | "-" | "*" | "/" | "&" | "|" | "<" | ">" | "="
ExpressionPart = op Term
Expression = Term ExpressionPart*
integerConstant = digit+
stringConstant = doubleQuote (~doubleQuote ~newline any)* doubleQuote
keywordConstant = "true" | "false" | "null" | "this"
GroupedExpression = OpenParen Expression CloseParen
unaryOp = "-" | "~"
UnaryExpression = unaryOp Term
Term = integerConstant | stringConstant | keywordConstant | SubroutineCall | ArrayAccess | jackIdentifier | GroupedExpression | UnaryExpression
compoundIdentifier = jackIdentifier dot jackIdentifier
SubroutineName = compoundIdentifier | jackIdentifier
SubroutineCall = SubroutineName OpenParen ExpressionList CloseParen
ExpressionList = Expressions?
Expressions = Expression TrailingExpression*
TrailingExpression = Comma Expression
jackIdentifier = letter (alnum | underscore)*
}`;
export default jack;
@@ -0,0 +1,10 @@
#!/bin/bash
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
for f in *.ohm ; do
echo "const ${f%.ohm} = \`" >| "${f}.js"
cat "$f" | sed 's!\\!\\\\!g' >> "${f}.js"
echo "\`;" >> "${f}.js"
echo "export default ${f%.ohm};" >> "${f}.js"
done
@@ -0,0 +1,59 @@
Tst <: Base {
Root := Tst
Tst = (TstStatement | TstRepeat | TstWhile)+
TstRepeat = Repeat Number? OpenBrace TstCommand+ CloseBrace
TstWhile = While Condition OpenBrace TstCommand+ CloseBrace
TstStatement = TstCommand
TstCommand = TstOperation Separator
Separator = (Semi | Bang | Comma)
TstOperation =
| TstFileOperation
| TstOutputListOperation
| TstEvalOperation
| TstSetOperation
| TstOutputOperation
| TstEchoOperation
| TstClearEchoOperation
| TstLoadROMOperation
| TstResetRAMOperation
TstLoadROMOperation = ROM32K Load FileName
TstFileOperation = FileOperation FileName?
TstOutputListOperation = "output-list" OutputFormat+
OutputFormat = Name Index? FormatSpec?
FormatSpec = percent FormatStyle wholeDec dot wholeDec dot wholeDec
TstSetOperation = Set Name Index? Number
Index = OpenSquare wholeDec? CloseSquare
Condition = Value CompareOp Value
TstEvalOperation = Eval | TickTock | Tick | Tock | VmStep
TstOutputOperation = Output
TstEchoOperation = Echo String
TstClearEchoOperation = ClearEcho
TstResetRAMOperation = ResetRAM
filename = (alnum|underscore|dot|dollar|minus)+
FileName = filename
FileOperation = "load" | "output-file" | "compare-to"
Set = "set"
Eval = "eval"
Tick = "tick"
Tock = "tock"
TickTock = "ticktock"
VmStep = "vmstep"
Echo = "echo"
Repeat = "repeat"
ClearEcho = "clear-echo"
Output = "output"
OutputList = "output-list"
FormatStyle = "B"|"D"|"S"|"X"
ROM32K = "ROM32K"
Load = "load"
While = "while"
ResetRAM = "resetRam"
CompareOp = "<>" | "<=" | ">=" | "=" | "<" | ">"
}
@@ -0,0 +1,61 @@
const tst = `
Tst <: Base {
Root := Tst
Tst = (TstStatement | TstRepeat | TstWhile)+
TstRepeat = Repeat Number? OpenBrace TstCommand+ CloseBrace
TstWhile = While Condition OpenBrace TstCommand+ CloseBrace
TstStatement = TstCommand
TstCommand = TstOperation Separator
Separator = (Semi | Bang | Comma)
TstOperation =
| TstFileOperation
| TstOutputListOperation
| TstEvalOperation
| TstSetOperation
| TstOutputOperation
| TstEchoOperation
| TstClearEchoOperation
| TstLoadROMOperation
| TstResetRAMOperation
TstLoadROMOperation = ROM32K Load FileName
TstFileOperation = FileOperation FileName?
TstOutputListOperation = "output-list" OutputFormat+
OutputFormat = Name Index? FormatSpec?
FormatSpec = percent FormatStyle wholeDec dot wholeDec dot wholeDec
TstSetOperation = Set Name Index? Number
Index = OpenSquare wholeDec? CloseSquare
Condition = Value CompareOp Value
TstEvalOperation = Eval | TickTock | Tick | Tock | VmStep
TstOutputOperation = Output
TstEchoOperation = Echo String
TstClearEchoOperation = ClearEcho
TstResetRAMOperation = ResetRAM
filename = (alnum|underscore|dot|dollar|minus)+
FileName = filename
FileOperation = "load" | "output-file" | "compare-to"
Set = "set"
Eval = "eval"
Tick = "tick"
Tock = "tock"
TickTock = "ticktock"
VmStep = "vmstep"
Echo = "echo"
Repeat = "repeat"
ClearEcho = "clear-echo"
Output = "output"
OutputList = "output-list"
FormatStyle = "B"|"D"|"S"|"X"
ROM32K = "ROM32K"
Load = "load"
While = "while"
ResetRAM = "resetRam"
CompareOp = "<>" | "<=" | ">=" | "=" | "<" | ">"
}`;
export default tst;
@@ -0,0 +1,56 @@
Vm <: Base {
Root := Vm
Vm = newline* VmInstructionLine* VmInstruction?
space := comment | " " | "\t"
whitespace = lineComment | comment | space
VmInstructionLine = VmInstruction newline+
VmInstruction =
| StackInstruction
| OpInstruction
| FunctionInstruction
| CallInstruction
| ReturnInstruction
| GotoInstruction
| LabelInstruction
StackInstruction = (push | pop) MemorySegment Number
OpInstruction = Add | Sub | Neg | Lt | Gt | Eq | And | Or | Not
FunctionInstruction = function Name Number
CallInstruction = call Name Number
ReturnInstruction = return
LabelInstruction = label Name
GotoInstruction = (goto | ifGoto) Name
MemorySegment = argument | local | static | constant | this | that | pointer | temp
push = "push" whitespace+
pop = "pop" whitespace+
function = "function" whitespace+
call = "call" whitespace+
return = "return"
goto = "goto" whitespace+
ifGoto = "if-goto" whitespace+
label = "label" whitespace+
argument = "argument" whitespace+
local = "local" whitespace+
static = "static" whitespace+
constant = "constant" whitespace+
this = "this" whitespace+
that = "that" whitespace+
pointer = "pointer" whitespace+
temp = "temp" whitespace+
Add = "add"
Sub = "sub"
Neg = "neg"
Eq = "eq"
Lt = "lt"
Gt = "gt"
And = "and"
Or = "or"
Not = "not"
}
@@ -0,0 +1,57 @@
const vm = `Vm <: Base {
Root := Vm
Vm = newline* VmInstructionLine* VmInstruction?
space := comment | " " | "\t"
whitespace = lineComment | comment | space
VmInstructionLine = VmInstruction newline+
VmInstruction =
| StackInstruction
| OpInstruction
| FunctionInstruction
| CallInstruction
| ReturnInstruction
| GotoInstruction
| LabelInstruction
StackInstruction = (push | pop) MemorySegment Number
OpInstruction = Add | Sub | Neg | Lt | Gt | Eq | And | Or | Not
FunctionInstruction = function Name Number
CallInstruction = call Name Number
ReturnInstruction = return
LabelInstruction = label Name
GotoInstruction = (goto | ifGoto) Name
MemorySegment = argument | local | static | constant | this | that | pointer | temp
push = "push" whitespace+
pop = "pop" whitespace+
function = "function" whitespace+
call = "call" whitespace+
return = "return"
goto = "goto" whitespace+
ifGoto = "if-goto" whitespace+
label = "label" whitespace+
argument = "argument" whitespace+
local = "local" whitespace+
static = "static" whitespace+
constant = "constant" whitespace+
this = "this" whitespace+
that = "that" whitespace+
pointer = "pointer" whitespace+
temp = "temp" whitespace+
Add = "add"
Sub = "sub"
Neg = "neg"
Eq = "eq"
Lt = "lt"
Gt = "gt"
And = "and"
Or = "or"
Not = "not"
}`;
export default vm;