File: syntax.bnf

package info (click to toggle)
storm-lang 0.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 52,100 kB
  • sloc: ansic: 261,471; cpp: 140,438; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (99 lines) | stat: -rw-r--r-- 3,878 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Syntax for inline asm and freestanding asm.
// TODO: Try to remove depency on the lang.bs.Block class.
// TODO: Use custom colors!

use lang.bs;
use core.asm;
use core.asm.CondFlag;

delimiter = SDelimiter;

// Root rule for asm code.
AsmListing SAsmListing(Block block);
SAsmListing => AsmListing(pos) : (SAsmAtom(block) -> add, )*;

// Atom.
AsmAtom SAsmAtom(Block block);
SAsmAtom => v : SAsmInstruction(block) v, ";";
SAsmAtom => AsmLabel(pos, name) : ["[A-Za-z]+" name #fnName, ":"]-;

// All possible asm values.
AsmOperand SAsmOperand(lang.bs.Block block);
SAsmOperand => v : SAsmLiteral v;
SAsmOperand => v : SAsmWritable(block) v;

// All possible writable asm values.
AsmOperand SAsmWritable(lang.bs.Block block);
SAsmWritable => v : SAsmReg v;
SAsmWritable => v : SAsmPtr v;
SAsmWritable[-10] => v : SAsmVariableRef(block) v;

// Separate rule for each, so that they can be chosen individually as well.

// Registers: al, bl, cl, eax, ebx, ecx, rax, rcx, rdx as in x86-64. ptrA, ptrB, ptrC, ptrStack, ptrFrame as pointer-sized ones.
AsmOperand SAsmReg() #keyword;
SAsmReg => rAl() : "al";
SAsmReg => rBl() : "bl";
SAsmReg => rCl() : "cl";
SAsmReg => rEax() : "eax";
SAsmReg => rEbx() : "ebx";
SAsmReg => rEcx() : "ecx";
SAsmReg => rRax() : "rax";
SAsmReg => rRbx() : "rbx";
SAsmReg => rRcx() : "rcx";
SAsmReg => rPtrA() : "ptrA";
SAsmReg => rPtrB() : "ptrB";
SAsmReg => rPtrC() : "ptrC";

// Indirect references.
AsmOperand SAsmPtr() #keyword;
SAsmPtr => pointer(size, base, offset) : "[binlwp]" size #constant, "\[", SAsmReg base, ("\+", SPtrOffset offset,)? "\]";

AsmOperand SPtrOffset();
SPtrOffset => number(value) : "-?[0-9]+" value #constant;
SPtrOffset => ptrNumber(times) : "sPtr" #keyword - (, "\*", "-?[0-9]*" times #constant)?;

// Literals.
AsmOperand SAsmLiteral();
SAsmLiteral => number(size, value) : "[binlwp]" size #constant - "-?[0-9]+" value #constant; // Numeric literal with size before it.
SAsmLiteral => ptrNumber(times) : "sPtr" #keyword - (, "\*", "-?[0-9]*" times #constant)?;

// Reference to a variable in another language.
VarRef SAsmVariableRef(Block block);
SAsmVariableRef => VarRef(pos, block, name) : "[A-Za-z]+" name #varName;

// Reference to a label.
AsmLabelRef SAsmLabelRef();
SAsmLabelRef => AsmLabelRef(name) : "@" #fnName - "[A-Za-z]+" name #fnName;

// Conditional expression in asm.
CondFlag SAsmCond();
SAsmCond => ifEqual() : "ifEqual" #keyword;
SAsmCond => ifNotEqual() : "ifNotEqual" #keyword;

// Unsigned
SAsmCond => ifAbove() : "ifAbove" #keyword;
SAsmCond => ifAboveEqual() : "ifAboveEqual" #keyword;
SAsmCond => ifBelow() : "ifBelow" #keyword;
SAsmCond => ifBelowEqual() : "ifBelowEqual" #keyword;

// Signed
SAsmCond => ifGreater() : "ifGreater" #keyword;
SAsmCond => ifGreaterEqual() : "ifGreaterEqual" #keyword;
SAsmCond => ifLess() : "ifLess" #keyword;
SAsmCond => ifLessEqual() : "ifLessEqual" #keyword;


// All asm instructions.
AsmAtom SAsmInstruction(lang.bs.Block block);
SAsmInstruction => AddInstr(dest, src) : "add" #typeName, SAsmWritable(block) dest, ",", SAsmOperand(block) src;
SAsmInstruction => SubInstr(dest, src) : "sub" #typeName, SAsmWritable(block) dest, ",", SAsmOperand(block) src;
SAsmInstruction => MovInstr(dest, src) : "mov" #typeName, SAsmWritable(block) dest, ",", SAsmOperand(block) src;
SAsmInstruction => LeaInstr(dest, src) : "lea" #typeName, SAsmWritable(block) dest, ",", SAsmOperand(block) src;
SAsmInstruction => CmpInstr(a, b) : "cmp" #typeName, SAsmOperand(block) a, ",", SAsmOperand(block) b;
SAsmInstruction => JmpInstr(to) : "jmp" #typeName, SAsmLabelRef to;
SAsmInstruction => JmpInstr(to, c) : "jmp" #typeName, SAsmCond c, ",", SAsmLabelRef to;
SAsmInstruction => SetCondInstr(dest, c) : "setCond" #typeName, SAsmWritable(block) dest, ",", SAsmCond c;

// Integration into other languages.
lang.bs.SStmt => r : "asm" #keyword, "{" [, SAsmListing(block) r,]+ "}";