Adapting for Ethereym as a library style:

+ Serpent remove - should not be there
This commit is contained in:
romanman 2014-09-05 09:43:23 +03:00
parent 28012ac1c8
commit a7ef7d4f7e
3 changed files with 0 additions and 434 deletions

View File

@ -1,242 +0,0 @@
// www.ethereumj.com
// @author Roman Mandeleil
// Created on: 22/03/2014 19:22
grammar Serpent;
tokens {
INDENT, DEDENT }
@lexer::header {
import com.yuvalshavit.antlr4.DenterHelper;
}
@lexer::members {
private final DenterHelper denter = new DenterHelper(NL, SerpentParser.INDENT, SerpentParser.DEDENT) {
@Override
public Token pullToken() {
return SerpentLexer.super.nextToken(); // must be to super.nextToken, or we'll recurse forever!
}
};
@Override
public Token nextToken() {
return denter.nextToken();
}
}
parse: block EOF
;
parse_init_code_block : 'init' ':' INDENT block DEDENT 'code' ':' INDENT block DEDENT;
block: ( asm | array_assign | assign | contract_storage_assign | special_func | if_elif_else_stmt |
while_stmt | ret_func_1 | ret_func_2 | suicide_func | stop_func | single_send_func | msg_func |
single_create_func)* ;
asm: '[asm' asm_symbol 'asm]' NL;
asm_symbol: (ASM_SYMBOLS | INT | HEX_NUMBER)* ;
if_elif_else_stmt: 'if' condition ':' INDENT block DEDENT
('elif' condition ':' INDENT block DEDENT)*
('else:' INDENT block DEDENT)?
;
while_stmt: 'while' condition ':' INDENT block DEDENT;
/* special functions */
special_func :
msg_datasize |
msg_sender |
msg_value |
tx_gasprice |
tx_origin |
tx_gas |
contract_balance |
contract_address |
block_prevhash |
block_coinbase |
block_timestamp |
block_number |
block_difficulty |
block_gaslimit
;
msg_datasize
: 'msg.datasize' ;
msg_sender
: 'msg.sender' ;
msg_value
: 'msg.value' ;
tx_gasprice
: 'tx.gasprice' ;
tx_origin
: 'tx.origin' ;
tx_gas
: 'tx.gas' ;
contract_balance
: 'contract.balance' ;
contract_address
: 'contract.address' ;
block_prevhash
: 'block.prevhash' ;
block_coinbase
: 'block.coinbase' ;
block_timestamp
: 'block.timestamp' ;
block_number
: 'block.number' ;
block_difficulty
: 'block.difficulty' ;
block_gaslimit
: 'block.gaslimit' ;
msg_func: 'msg' '(' int_val ',' int_val ',' int_val ',' arr_def ',' int_val ',' int_val')' ;
send_func: 'send' '(' int_val ',' int_val ',' int_val ')';
single_send_func: send_func NL;
create_func: 'create' '(' int_val ',' int_val ',' int_val ')';
single_create_func: create_func NL;
msg_data: 'msg.data' '[' expression ']' ;
array_assign: VAR '[' int_val ']' EQ_OP expression NL;
array_retreive: VAR '[' int_val ']';
assign: VAR EQ_OP (expression | arr_def | msg_func) NL;
arr_def : '[' (int_val ','?)* ']';
contract_storage_assign: 'contract.storage' '[' expression ']' EQ_OP expression NL;
contract_storage_load: 'contract.storage' '[' expression ']';
mul_expr
: int_val
| mul_expr OP_MUL int_val
;
add_expr
: mul_expr
| add_expr OP_ADD mul_expr
;
rel_exp
: add_expr
| rel_exp OP_REL add_expr
;
eq_exp
: rel_exp
| eq_exp OP_EQ rel_exp
;
and_exp
: eq_exp
| and_exp OP_AND eq_exp
;
ex_or_exp
: and_exp
| ex_or_exp OP_EX_OR and_exp
;
in_or_exp
: ex_or_exp
| in_or_exp OP_IN_OR ex_or_exp
;
log_and_exp
: in_or_exp
| log_and_exp OP_LOG_AND in_or_exp
;
log_or_exp
: log_and_exp
| log_or_exp OP_LOG_OR log_and_exp
;
expression : log_or_exp ;
condition: expression ;
int_val : INT |
hex_num |
get_var |
special_func |
'(' expression ')' |
OP_NOT '(' expression ')' |
msg_data |
send_func |
contract_storage_load |
array_retreive
;
hex_num
: HEX_NUMBER
;
ret_func_1: 'return' '(' expression ')' NL;
ret_func_2: 'return' '(' expression ',' expression ')' NL;
suicide_func: 'suicide' '(' expression ')' NL;
stop_func: 'stop' NL;
get_var: VAR;
INT: [0-9]+;
ASM_SYMBOLS: 'STOP' | 'ADD' | 'MUL' | 'SUB' | 'DIV' | 'SDIV' | 'MOD' |'SMOD' | 'EXP' | 'NEG' | 'LT' | 'GT' | 'SLT' | 'SGT'| 'EQ' | 'NOT' | 'AND' | 'OR' | 'XOR' | 'BYTE' | 'SHA3' | 'ADDRESS' | 'BALANCE' | 'ORIGIN' | 'CALLER' | 'CALLVALUE' | 'CALLDATALOAD' | 'CALLDATASIZE' | 'CALLDATACOPY' | 'CODESIZE' | 'CODECOPY' | 'GASPRICE' | 'PREVHASH' | 'COINBASE' | 'TIMESTAMP' | 'NUMBER' | 'DIFFICULTY' | 'GASLIMIT' | 'POP' | 'DUP' | 'SWAP' | 'MLOAD' | 'MSTORE' | 'MSTORE8' | 'SLOAD' | 'SSTORE' | 'JUMP' | 'JUMPI' | 'PC' | 'MSIZE' | 'GAS' | 'PUSH1' | 'PUSH2' | 'PUSH3' | 'PUSH4' | 'PUSH5' | 'PUSH6' | 'PUSH7' | 'PUSH8' | 'PUSH9' | 'PUSH10' | 'PUSH11' | 'PUSH12' | 'PUSH13' | 'PUSH14' | 'PUSH15' | 'PUSH16' | 'PUSH17' | 'PUSH18' | 'PUSH19' | 'PUSH20' | 'PUSH21' | 'PUSH22' | 'PUSH23' | 'PUSH24' | 'PUSH25' | 'PUSH26' | 'PUSH27' | 'PUSH28' | 'PUSH29' | 'PUSH30' | 'PUSH31' | 'PUSH32' | 'CREATE' | 'CALL' | 'RETURN' | 'SUICIDE';
/* 'xor', 'and', 'or', 'not' operands should be defined
first among lexer rules because it
can be mismatched as a var lexa */
OP_EX_OR: 'xor';
OP_LOG_AND: '&&' | 'and';
OP_LOG_OR: '||' | 'or';
OP_NOT: '!' | 'not';
EQ_OP: '=' ;
NL: ('\r'? '\n' ' '*); // note the ' '*;
WS: [ \t]+ -> skip;
LINE_COMMENT: '//' ~[\r\n]* -> skip;
VAR: [a-zA-Z][a-zA-Z0-9]* ;
OP_ADD : '+' | '-';
OP_MUL : '*' | '/' | '^' | '%' | '#/' | '#%' ;
OP_REL : '<' | '>' | '<=' | '>=';
OP_EQ : '==' | '!=';
OP_AND: '&';
OP_IN_OR: '|';
HEX_DIGIT : [0-9a-fA-F];
HEX_NUMBER : ('0x' | '0X' )HEX_DIGIT+;

View File

@ -1,97 +0,0 @@
OP_IN_OR=53
T__29=7
EQ_OP=43
T__28=8
T__27=9
OP_AND=52
T__26=10
T__25=11
T__24=12
T__23=13
T__22=14
T__21=15
T__20=16
OP_MUL=49
DEDENT=57
T__9=27
T__8=28
T__7=29
INDENT=56
T__6=30
T__5=31
T__4=32
T__19=17
OP_EQ=51
T__16=20
T__15=21
T__18=18
T__17=19
T__12=24
T__11=25
T__14=22
T__13=23
T__10=26
OP_EX_OR=39
OP_NOT=42
VAR=47
NL=44
LINE_COMMENT=46
OP_LOG_OR=41
OP_ADD=48
HEX_DIGIT=54
INT=37
T__30=6
T__31=5
T__32=4
T__33=3
WS=45
T__34=2
T__35=1
T__1=35
T__0=36
T__3=33
T__2=34
ASM_SYMBOLS=38
HEX_NUMBER=55
OP_REL=50
OP_LOG_AND=40
'|'=53
'code'=36
'block.number'=35
'block.gaslimit'=34
'asm]'=33
'contract.balance'=32
'msg.sender'=31
'='=43
'return'=30
'elif'=29
'create'=28
'msg.data'=27
'tx.origin'=26
'else:'=25
'tx.gasprice'=24
')'=23
'xor'=39
'msg.datasize'=22
'block.difficulty'=21
'suicide'=20
'block.prevhash'=18
'contract.storage'=19
'init'=17
'msg.value'=16
'[asm'=15
'contract.address'=14
'block.timestamp'=13
'send'=12
'if'=11
'('=10
':'=9
'['=8
'while'=7
'tx.gas'=6
'msg'=5
','=4
'block.coinbase'=3
'&'=52
'stop'=2
']'=1

View File

@ -1,95 +0,0 @@
OP_IN_OR=53
T__29=7
EQ_OP=43
T__28=8
T__27=9
OP_AND=52
T__26=10
T__25=11
T__24=12
T__23=13
T__22=14
T__21=15
T__20=16
OP_MUL=49
T__9=27
T__8=28
T__7=29
T__6=30
T__5=31
T__4=32
T__19=17
OP_EQ=51
T__16=20
T__15=21
T__18=18
T__17=19
T__12=24
T__11=25
T__14=22
T__13=23
T__10=26
OP_EX_OR=39
OP_NOT=42
VAR=47
NL=44
LINE_COMMENT=46
OP_LOG_OR=41
OP_ADD=48
HEX_DIGIT=54
INT=37
T__30=6
T__31=5
T__32=4
T__33=3
WS=45
T__34=2
T__35=1
T__1=35
T__0=36
T__3=33
T__2=34
ASM_SYMBOLS=38
HEX_NUMBER=55
OP_REL=50
OP_LOG_AND=40
'|'=53
'code'=36
'block.number'=35
'block.gaslimit'=34
'asm]'=33
'contract.balance'=32
'msg.sender'=31
'='=43
'return'=30
'elif'=29
'create'=28
'msg.data'=27
'tx.origin'=26
'else:'=25
'tx.gasprice'=24
')'=23
'xor'=39
'msg.datasize'=22
'block.difficulty'=21
'suicide'=20
'block.prevhash'=18
'contract.storage'=19
'init'=17
'msg.value'=16
'[asm'=15
'contract.address'=14
'block.timestamp'=13
'send'=12
'if'=11
'('=10
':'=9
'['=8
'while'=7
'tx.gas'=6
'msg'=5
','=4
'block.coinbase'=3
'&'=52
'stop'=2
']'=1