Skip to content

Instantly share code, notes, and snippets.

@jddurand
Created January 18, 2015 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jddurand/7b7074f8ebbf668c25d7 to your computer and use it in GitHub Desktop.
Save jddurand/7b7074f8ebbf668c25d7 to your computer and use it in GitHub Desktop.
unfinished grammar for java class - totally unusable you are warned
:default ::= action => [values] bless => ::lhs
lexeme default = action => [start,length,value,name]
:start ::= ClassFile
ClassFile ::=
magic
minor_version
major_version
constant_pool_count
constant_pools
access_flags
this_class
super_class
interfaces_count
interfaces
fields_count
fields
methods_count
methods
attributes_count
attributes
magic ::= U4
minor_version ::= U2
major_version ::= U2
constant_pool_count ::= U2
constant_pools ::= constant_pool
constant_pool ::= cp_info
cp_info ::= tag
infos
infos ::= info+
tag ::= U1
info ::= constantClassInfo
| constantFieldrefInfo
| constantMethodrefInfo
| constantInterfaceMethodrefInfo
| constantStringInfo
| constantIntegerInfo
| constantLongInfo
| constantDoubleInfo
| constantNameAndTypeInfo
| constantUtf8Info
| constantMethodHandleInfo
| constantMethodTypeInfo
| constantInvokeDynamicInfo
constantClassInfo ::= tag nameIndex
constantFieldrefInfo ::= tag classIndex nameAndTypeIndex
constantMethodrefInfo ::= tag classIndex nameAndTypeIndex
constantInterfaceMethodrefInfo ::= tag classIndex nameAndTypeIndex
constantStringInfo ::= tag stringIndex
constantIntegerInfo ::= tag bytes4
constantLongInfo ::= tag highBytes lowBytes
constantDoubleInfo ::= tag highBytes lowBytes
constantNameAndTypeInfo ::= tag nameIndex descriptorIndex
constantUtf8Info ::= tag length byte1s
constantMethodHandleInfo ::= tag referenceKind referenceIndex
constantMethodTypeInfo ::= tag descriptorIndex
constantInvokeDynamicInfo ::= tag bootstrapMethodAttrIndex nameAndTypeIndex
nameIndex ::= U2
classIndex ::= U2
nameAndTypeIndex ::= U2
stringIndex ::= U2
bytes4 ::= U4
highBytes ::= U4
lowBytes ::= U4
descriptorIndex ::= U2
length ::= U2
byte1s ::= byte*
byte ::= U1
referenceKind ::= U1
referenceIndex ::= U1
bootstrapMethodAttrIndex ::= U2
nameAndTypeIndex ::= U2
access_flags ::= U2
this_class ::= U2
super_class ::= U2
interfaces_count ::= U2
interfaces ::= interface*
interface ::= U2
fields_count ::= U2
fields ::= field
field ::= field_info
field_info ::= accessFlags
nameIndex
attributesCount
attributes
attributes ::= attribute*
attribute ::= attribute_info
attribute_info ::= attributeNameIndex
attributeLength
info1s
attributeNameIndex ::= U2
attributeLength ::= U4
info1s ::= info1*
info1 ::= U1
attributesCount ::= U2
accessFlags ::= U2
methods_count ::= U2
methods ::= method*
method ::= methodInfo
methodInfo ::= accessFlags
nameIndex
descriptorIndex
attributesCount
attributes
accessFlags ::= U2
attributes_count ::= U2
attributes ::= attribute*
attribute ::= attributeInfo
attributeInfo ::= ConstantValueAttribute
| CodeAttribute
| StackMapTableAttribute
ConstantValueAttribute ::= attributeNameIndex
attributeLength
constantValueIndex
attributeNameIindex ::= U2
attributeLength ::= U4
constantValueIndex ::= U2
CodeAttribute ::= attributeNameIndex
attributeLength
maxStack
maxLocals
codeLength
code1s
exceptionTableLength
exceptionTables
attributesCount
attributes
StackMapTableAttribute ::= attributeNameIndex
attributeLength
numberOfEntries
entries
maxStack ::= U2
maxLocals ::= U2
codeLength ::= U4
code1s ::= code1
code1 ::= U1
exceptionTableLength ::= U2
exceptionTables ::= exceptionTable*
exceptionTable ::= startPc
endPc
handlerPc
catchType
startPc ::= U2
endPc ::= U2
handlerPc ::= U2
catchType ::= U2
numberOfEntries ::= U2
entries ::= entry*
entry ::= entry*
_BYTE ~ [0..\x{FF}]
U1 ~ _BYTE
U2 ~ _BYTE _BYTE
U4 ~ _BYTE _BYTE _BYTE _BYTE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment