├── .travis.yml ├── LICENSE ├── README.md ├── Solidity.g4 ├── run-tests.sh └── test.sol /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | script: ./run-tests.sh 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2018 Federico Bond 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # solidity-antlr4 2 | 3 | [![Build Status](https://travis-ci.org/solidityj/solidity-antlr4.svg?branch=master)](https://travis-ci.org/solidityj/solidity-antlr4) 4 | 5 | Solidity grammar for ANTLR4 6 | 7 | ## Author 8 | 9 | Federico Bond ([@federicobond](https://github.com/federicobond)) 10 | 11 | ## License 12 | 13 | MIT 14 | -------------------------------------------------------------------------------- /Solidity.g4: -------------------------------------------------------------------------------- 1 | // Copyright 2016-2019 Federico Bond 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. 3 | 4 | grammar Solidity; 5 | 6 | sourceUnit 7 | : (pragmaDirective | importDirective | contractDefinition)* EOF ; 8 | 9 | pragmaDirective 10 | : 'pragma' pragmaName pragmaValue ';' ; 11 | 12 | pragmaName 13 | : identifier ; 14 | 15 | pragmaValue 16 | : version | expression ; 17 | 18 | version 19 | : versionConstraint versionConstraint? ; 20 | 21 | versionOperator 22 | : '^' | '~' | '>=' | '>' | '<' | '<=' | '=' ; 23 | 24 | versionConstraint 25 | : versionOperator? VersionLiteral ; 26 | 27 | importDeclaration 28 | : identifier ('as' identifier)? ; 29 | 30 | importDirective 31 | : 'import' StringLiteral ('as' identifier)? ';' 32 | | 'import' ('*' | identifier) ('as' identifier)? 'from' StringLiteral ';' 33 | | 'import' '{' importDeclaration ( ',' importDeclaration )* '}' 'from' StringLiteral ';' ; 34 | 35 | NatSpecSingleLine 36 | : ('///' .*? [\r\n]) + ; 37 | 38 | NatSpecMultiLine 39 | : '/**' .*? '*/' ; 40 | 41 | natSpec 42 | : NatSpecSingleLine 43 | | NatSpecMultiLine ; 44 | 45 | contractDefinition 46 | : natSpec? ( 'contract' | 'interface' | 'library' ) identifier 47 | ( 'is' inheritanceSpecifier (',' inheritanceSpecifier )* )? 48 | '{' contractPart* '}' ; 49 | 50 | inheritanceSpecifier 51 | : userDefinedTypeName ( '(' expressionList? ')' )? ; 52 | 53 | contractPart 54 | : stateVariableDeclaration 55 | | usingForDeclaration 56 | | structDefinition 57 | | constructorDefinition 58 | | modifierDefinition 59 | | functionDefinition 60 | | eventDefinition 61 | | enumDefinition ; 62 | 63 | stateVariableDeclaration 64 | : typeName 65 | ( PublicKeyword | InternalKeyword | PrivateKeyword | ConstantKeyword )* 66 | identifier ('=' expression)? ';' ; 67 | 68 | usingForDeclaration 69 | : 'using' identifier 'for' ('*' | typeName) ';' ; 70 | 71 | structDefinition 72 | : 'struct' identifier 73 | '{' ( variableDeclaration ';' (variableDeclaration ';')* )? '}' ; 74 | 75 | constructorDefinition 76 | : 'constructor' parameterList modifierList block ; 77 | 78 | modifierDefinition 79 | : 'modifier' identifier parameterList? block ; 80 | 81 | modifierInvocation 82 | : identifier ( '(' expressionList? ')' )? ; 83 | 84 | functionDefinition 85 | : natSpec? 'function' identifier? parameterList modifierList returnParameters? ( ';' | block ) ; 86 | 87 | returnParameters 88 | : 'returns' parameterList ; 89 | 90 | modifierList 91 | : ( modifierInvocation | stateMutability | ExternalKeyword 92 | | PublicKeyword | InternalKeyword | PrivateKeyword )* ; 93 | 94 | eventDefinition 95 | : natSpec? 'event' identifier eventParameterList AnonymousKeyword? ';' ; 96 | 97 | enumValue 98 | : identifier ; 99 | 100 | enumDefinition 101 | : 'enum' identifier '{' enumValue? (',' enumValue)* '}' ; 102 | 103 | parameterList 104 | : '(' ( parameter (',' parameter)* )? ')' ; 105 | 106 | parameter 107 | : typeName storageLocation? identifier? ; 108 | 109 | eventParameterList 110 | : '(' ( eventParameter (',' eventParameter)* )? ')' ; 111 | 112 | eventParameter 113 | : typeName IndexedKeyword? identifier? ; 114 | 115 | functionTypeParameterList 116 | : '(' ( functionTypeParameter (',' functionTypeParameter)* )? ')' ; 117 | 118 | functionTypeParameter 119 | : typeName storageLocation? ; 120 | 121 | variableDeclaration 122 | : typeName storageLocation? identifier ; 123 | 124 | typeName 125 | : elementaryTypeName 126 | | userDefinedTypeName 127 | | mapping 128 | | typeName '[' expression? ']' 129 | | functionTypeName 130 | | 'address' 'payable' ; 131 | 132 | userDefinedTypeName 133 | : identifier ( '.' identifier )* ; 134 | 135 | mapping 136 | : 'mapping' '(' elementaryTypeName '=>' typeName ')' ; 137 | 138 | functionTypeName 139 | : 'function' functionTypeParameterList 140 | ( InternalKeyword | ExternalKeyword | stateMutability )* 141 | ( 'returns' functionTypeParameterList )? ; 142 | 143 | storageLocation 144 | : 'memory' | 'storage' | 'calldata'; 145 | 146 | stateMutability 147 | : PureKeyword | ConstantKeyword | ViewKeyword | PayableKeyword ; 148 | 149 | block 150 | : '{' statement* '}' ; 151 | 152 | statement 153 | : ifStatement 154 | | whileStatement 155 | | forStatement 156 | | block 157 | | inlineAssemblyStatement 158 | | doWhileStatement 159 | | continueStatement 160 | | breakStatement 161 | | returnStatement 162 | | throwStatement 163 | | emitStatement 164 | | simpleStatement ; 165 | 166 | expressionStatement 167 | : expression ';' ; 168 | 169 | ifStatement 170 | : 'if' '(' expression ')' statement ( 'else' statement )? ; 171 | 172 | whileStatement 173 | : 'while' '(' expression ')' statement ; 174 | 175 | simpleStatement 176 | : ( variableDeclarationStatement | expressionStatement ) ; 177 | 178 | forStatement 179 | : 'for' '(' ( simpleStatement | ';' ) ( expressionStatement | ';' ) expression? ')' statement ; 180 | 181 | inlineAssemblyStatement 182 | : 'assembly' StringLiteral? assemblyBlock ; 183 | 184 | doWhileStatement 185 | : 'do' statement 'while' '(' expression ')' ';' ; 186 | 187 | continueStatement 188 | : 'continue' ';' ; 189 | 190 | breakStatement 191 | : 'break' ';' ; 192 | 193 | returnStatement 194 | : 'return' expression? ';' ; 195 | 196 | throwStatement 197 | : 'throw' ';' ; 198 | 199 | emitStatement 200 | : 'emit' functionCall ';' ; 201 | 202 | variableDeclarationStatement 203 | : ( 'var' identifierList | variableDeclaration | '(' variableDeclarationList ')' ) ( '=' expression )? ';'; 204 | 205 | variableDeclarationList 206 | : variableDeclaration? (',' variableDeclaration? )* ; 207 | 208 | identifierList 209 | : '(' ( identifier? ',' )* identifier? ')' ; 210 | 211 | elementaryTypeName 212 | : 'address' | 'bool' | 'string' | 'var' | Int | Uint | 'byte' | Byte | Fixed | Ufixed ; 213 | 214 | Int 215 | : 'int' | 'int8' | 'int16' | 'int24' | 'int32' | 'int40' | 'int48' | 'int56' | 'int64' | 'int72' | 'int80' | 'int88' | 'int96' | 'int104' | 'int112' | 'int120' | 'int128' | 'int136' | 'int144' | 'int152' | 'int160' | 'int168' | 'int176' | 'int184' | 'int192' | 'int200' | 'int208' | 'int216' | 'int224' | 'int232' | 'int240' | 'int248' | 'int256' ; 216 | 217 | Uint 218 | : 'uint' | 'uint8' | 'uint16' | 'uint24' | 'uint32' | 'uint40' | 'uint48' | 'uint56' | 'uint64' | 'uint72' | 'uint80' | 'uint88' | 'uint96' | 'uint104' | 'uint112' | 'uint120' | 'uint128' | 'uint136' | 'uint144' | 'uint152' | 'uint160' | 'uint168' | 'uint176' | 'uint184' | 'uint192' | 'uint200' | 'uint208' | 'uint216' | 'uint224' | 'uint232' | 'uint240' | 'uint248' | 'uint256' ; 219 | 220 | Byte 221 | : 'bytes' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | 'bytes17' | 'bytes18' | 'bytes19' | 'bytes20' | 'bytes21' | 'bytes22' | 'bytes23' | 'bytes24' | 'bytes25' | 'bytes26' | 'bytes27' | 'bytes28' | 'bytes29' | 'bytes30' | 'bytes31' | 'bytes32' ; 222 | 223 | Fixed 224 | : 'fixed' | ( 'fixed' [0-9]+ 'x' [0-9]+ ) ; 225 | 226 | Ufixed 227 | : 'ufixed' | ( 'ufixed' [0-9]+ 'x' [0-9]+ ) ; 228 | 229 | expression 230 | : expression ('++' | '--') 231 | | 'new' typeName 232 | | expression '[' expression ']' 233 | | expression '(' functionCallArguments ')' 234 | | expression '.' identifier 235 | | '(' expression ')' 236 | | ('++' | '--') expression 237 | | ('+' | '-') expression 238 | | ('after' | 'delete') expression 239 | | '!' expression 240 | | '~' expression 241 | | expression '**' expression 242 | | expression ('*' | '/' | '%') expression 243 | | expression ('+' | '-') expression 244 | | expression ('<<' | '>>') expression 245 | | expression '&' expression 246 | | expression '^' expression 247 | | expression '|' expression 248 | | expression ('<' | '>' | '<=' | '>=') expression 249 | | expression ('==' | '!=') expression 250 | | expression '&&' expression 251 | | expression '||' expression 252 | | expression '?' expression ':' expression 253 | | expression ('=' | '|=' | '^=' | '&=' | '<<=' | '>>=' | '+=' | '-=' | '*=' | '/=' | '%=') expression 254 | | primaryExpression ; 255 | 256 | primaryExpression 257 | : BooleanLiteral 258 | | numberLiteral 259 | | HexLiteral 260 | | StringLiteral 261 | | identifier ('[' ']')? 262 | | TypeKeyword 263 | | tupleExpression 264 | | typeNameExpression ('[' ']')? ; 265 | 266 | expressionList 267 | : expression (',' expression)* ; 268 | 269 | nameValueList 270 | : nameValue (',' nameValue)* ','? ; 271 | 272 | nameValue 273 | : identifier ':' expression ; 274 | 275 | functionCallArguments 276 | : '{' nameValueList? '}' 277 | | expressionList? ; 278 | 279 | functionCall 280 | : expression '(' functionCallArguments ')' ; 281 | 282 | assemblyBlock 283 | : '{' assemblyItem* '}' ; 284 | 285 | assemblyItem 286 | : identifier 287 | | assemblyBlock 288 | | assemblyExpression 289 | | assemblyLocalDefinition 290 | | assemblyAssignment 291 | | assemblyStackAssignment 292 | | labelDefinition 293 | | assemblySwitch 294 | | assemblyFunctionDefinition 295 | | assemblyFor 296 | | assemblyIf 297 | | BreakKeyword 298 | | ContinueKeyword 299 | | subAssembly 300 | | numberLiteral 301 | | StringLiteral 302 | | HexLiteral ; 303 | 304 | assemblyExpression 305 | : assemblyCall | assemblyLiteral ; 306 | 307 | assemblyCall 308 | : ( 'return' | 'address' | 'byte' | identifier ) ( '(' assemblyExpression? ( ',' assemblyExpression )* ')' )? ; 309 | 310 | assemblyLocalDefinition 311 | : 'let' assemblyIdentifierOrList ( ':=' assemblyExpression )? ; 312 | 313 | assemblyAssignment 314 | : assemblyIdentifierOrList ':=' assemblyExpression ; 315 | 316 | assemblyIdentifierOrList 317 | : identifier | '(' assemblyIdentifierList ')' ; 318 | 319 | assemblyIdentifierList 320 | : identifier ( ',' identifier )* ; 321 | 322 | assemblyStackAssignment 323 | : '=:' identifier ; 324 | 325 | labelDefinition 326 | : identifier ':' ; 327 | 328 | assemblySwitch 329 | : 'switch' assemblyExpression assemblyCase* ; 330 | 331 | assemblyCase 332 | : 'case' assemblyLiteral assemblyBlock 333 | | 'default' assemblyBlock ; 334 | 335 | assemblyFunctionDefinition 336 | : 'function' identifier '(' assemblyIdentifierList? ')' 337 | assemblyFunctionReturns? assemblyBlock ; 338 | 339 | assemblyFunctionReturns 340 | : ( '->' assemblyIdentifierList ) ; 341 | 342 | assemblyFor 343 | : 'for' ( assemblyBlock | assemblyExpression ) 344 | assemblyExpression ( assemblyBlock | assemblyExpression ) assemblyBlock ; 345 | 346 | assemblyIf 347 | : 'if' assemblyExpression assemblyBlock ; 348 | 349 | assemblyLiteral 350 | : StringLiteral | DecimalNumber | HexNumber | HexLiteral ; 351 | 352 | subAssembly 353 | : 'assembly' identifier assemblyBlock ; 354 | 355 | tupleExpression 356 | : '(' ( expression? ( ',' expression? )* ) ')' 357 | | '[' ( expression ( ',' expression )* )? ']' ; 358 | 359 | typeNameExpression 360 | : elementaryTypeName 361 | | userDefinedTypeName ; 362 | 363 | numberLiteral 364 | : (DecimalNumber | HexNumber) NumberUnit? ; 365 | 366 | identifier 367 | : ('from' | 'calldata' | Identifier) ; 368 | 369 | VersionLiteral 370 | : [0-9]+ '.' [0-9]+ '.' [0-9]+ ; 371 | 372 | BooleanLiteral 373 | : 'true' | 'false' ; 374 | 375 | DecimalNumber 376 | : ( DecimalDigits | (DecimalDigits? '.' DecimalDigits) ) ( [eE] DecimalDigits )? ; 377 | 378 | fragment 379 | DecimalDigits 380 | : [0-9] ( '_'? [0-9] )* ; 381 | 382 | HexNumber 383 | : '0' [xX] HexDigits ; 384 | 385 | fragment 386 | HexDigits 387 | : HexCharacter ( '_'? HexCharacter )* ; 388 | 389 | NumberUnit 390 | : 'wei' | 'szabo' | 'finney' | 'ether' 391 | | 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'years' ; 392 | 393 | HexLiteral : 'hex' ('"' HexPair* '"' | '\'' HexPair* '\'') ; 394 | 395 | fragment 396 | HexPair 397 | : HexCharacter HexCharacter ; 398 | 399 | fragment 400 | HexCharacter 401 | : [0-9A-Fa-f] ; 402 | 403 | ReservedKeyword 404 | : 'abstract' 405 | | 'after' 406 | | 'case' 407 | | 'catch' 408 | | 'default' 409 | | 'final' 410 | | 'in' 411 | | 'inline' 412 | | 'let' 413 | | 'match' 414 | | 'null' 415 | | 'of' 416 | | 'relocatable' 417 | | 'static' 418 | | 'switch' 419 | | 'try' 420 | | 'typeof' ; 421 | 422 | AnonymousKeyword : 'anonymous' ; 423 | BreakKeyword : 'break' ; 424 | ConstantKeyword : 'constant' ; 425 | ContinueKeyword : 'continue' ; 426 | ExternalKeyword : 'external' ; 427 | IndexedKeyword : 'indexed' ; 428 | InternalKeyword : 'internal' ; 429 | PayableKeyword : 'payable' ; 430 | PrivateKeyword : 'private' ; 431 | PublicKeyword : 'public' ; 432 | PureKeyword : 'pure' ; 433 | TypeKeyword : 'type' ; 434 | ViewKeyword : 'view' ; 435 | 436 | Identifier 437 | : IdentifierStart IdentifierPart* ; 438 | 439 | fragment 440 | IdentifierStart 441 | : [a-zA-Z$_] ; 442 | 443 | fragment 444 | IdentifierPart 445 | : [a-zA-Z0-9$_] ; 446 | 447 | StringLiteral 448 | : '"' DoubleQuotedStringCharacter* '"' 449 | | '\'' SingleQuotedStringCharacter* '\'' ; 450 | 451 | fragment 452 | DoubleQuotedStringCharacter 453 | : ~["\r\n\\] | ('\\' .) ; 454 | 455 | fragment 456 | SingleQuotedStringCharacter 457 | : ~['\r\n\\] | ('\\' .) ; 458 | 459 | WS 460 | : [ \t\r\n\u000C]+ -> skip ; 461 | 462 | COMMENT 463 | : '/*' .*? '*/' -> channel(HIDDEN) ; 464 | 465 | LINE_COMMENT 466 | : '//' ~[\r\n]* -> channel(HIDDEN) ; 467 | -------------------------------------------------------------------------------- /run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ANTLR_JAR="antlr4.jar" 4 | 5 | GRAMMAR="Solidity" 6 | START_RULE="sourceUnit" 7 | TEST_FILE="test.sol" 8 | ERROR_PATTERN="mismatched|extraneous" 9 | 10 | if [ ! -e "$ANTLR_JAR" ]; then 11 | curl https://www.antlr.org/download/antlr-4.7.2-complete.jar -o "$ANTLR_JAR" 12 | fi 13 | 14 | mkdir -p target/ 15 | 16 | java -jar $ANTLR_JAR $GRAMMAR.g4 -o src/ 17 | javac -classpath $ANTLR_JAR src/*.java -d target/ 18 | 19 | java -classpath $ANTLR_JAR:target/ org.antlr.v4.gui.TestRig "$GRAMMAR" "$START_RULE" < "$TEST_FILE" 2>&1 | 20 | grep -qE "$ERROR_PATTERN" && echo "TESTS FAIL!" || echo "TESTS PASS!" 21 | -------------------------------------------------------------------------------- /test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.4; 2 | pragma solidity ^0.4.4; 3 | pragma solidity ~0.4.4; 4 | pragma solidity >0.4.4; 5 | pragma solidity >=0.4.4; 6 | pragma solidity <0.4.4; 7 | pragma solidity <=0.4.4; 8 | pragma solidity =0.4.4; 9 | 10 | library a {} 11 | library b {} 12 | library c {} 13 | library f {} 14 | contract test { 15 | function f(uint a, uint b); 16 | function g(uint c); 17 | } 18 | contract c { 19 | event e(uint[10] a, bytes7[8] indexed b, c[3] x); 20 | } 21 | contract c { 22 | function f() { 23 | uint8[10 * 2] x; 24 | } 25 | } 26 | contract c { 27 | uint[10] a; 28 | uint[] a2; 29 | struct x { uint[2**20] b; y[0] c; } 30 | struct y { uint d; mapping(uint=>x)[] e; } 31 | } 32 | contract test { 33 | function fun(uint256 a) { 34 | uint256 x = ([1, 2, 3 + 4][a/=9] - 3) ** 4; 35 | } 36 | } 37 | import "./abc.sol" as x; 38 | import * as y from "./abc.sol"; 39 | import {a as b, c as d, f} from "./abc.sol"; 40 | 41 | contract z {} 42 | contract A { 43 | function f() { 44 | uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6; 45 | } 46 | } 47 | contract A { 48 | function f() { 49 | uint x = true ? 1 : 0; 50 | uint y = false ? 0 : 1; 51 | } 52 | } 53 | contract A { 54 | function f() { 55 | uint y = 1; 56 | uint x = 3 < 0 ? x = 3 : 6; 57 | true ? x = 3 : 4; 58 | } 59 | } 60 | contract A { 61 | function f() { 62 | uint x = 3 > 0 ? 3 : 0; 63 | uint y = (3 > 0) ? 3 : 0; 64 | } 65 | } 66 | contract A { 67 | function f() { 68 | uint x = 3; 69 | uint y = 1; 70 | uint z = (x > y) ? x : y; 71 | uint w = x > y ? x : y; 72 | } 73 | } 74 | contract base { 75 | function fun() { 76 | uint64(2); 77 | } 78 | } 79 | 80 | contract derived is base() { 81 | function fun() { 82 | uint64(2); 83 | } 84 | } 85 | 86 | contract foo { 87 | function fun() { 88 | } 89 | } 90 | 91 | contract bar { 92 | function fun() { 93 | } 94 | } 95 | 96 | contract derived is foo, bar { 97 | function fun() { 98 | } 99 | } 100 | contract A { 101 | fixed40x40 storeMe; 102 | function f(ufixed x, fixed32x32 y) { 103 | ufixed8x8 a; 104 | fixed b; 105 | } 106 | } 107 | library d {} 108 | contract test { 109 | function fun(uint256 a) returns (address b) { 110 | if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78; 111 | } 112 | } 113 | // 114 | contract test 115 | {} 116 | contract c { 117 | enum foo { } 118 | } 119 | contract test { 120 | uint256 stateVar; 121 | function functionName(bytes20 arg1, address addr) constant 122 | returns (int id) 123 | { } 124 | } 125 | contract c { 126 | enum validEnum { Value1, Value2, Value3, Value4 } 127 | 128 | function c () { 129 | a = validEnum.Value3; 130 | } 131 | 132 | validEnum a; 133 | } 134 | contract c { 135 | event e(); 136 | } 137 | contract c { 138 | event e() anonymous; 139 | } 140 | contract c { 141 | event e(uint a, bytes32 s); 142 | } 143 | contract c { 144 | event e(uint a, bytes32 indexed s, bool indexed b); 145 | } 146 | contract test { 147 | function fun(uint256 a) { 148 | uint256 x = 3 ** a; 149 | } 150 | } 151 | contract c { 152 | function x() external {} 153 | } 154 | contract c { 155 | function() { } 156 | } 157 | contract test { 158 | function fun(uint256 a) { 159 | uint256 i = 0; 160 | for (i = 0; i < 10; i++) { 161 | uint256 x = i; 162 | break; 163 | continue; 164 | } 165 | } 166 | } 167 | contract test { 168 | function fun(uint256 a) { 169 | uint256 i = 0; 170 | for (;;) { 171 | uint256 x = i; 172 | break; 173 | continue; 174 | } 175 | } 176 | } 177 | contract test { 178 | function fun(uint256 a) { 179 | uint256 i =0; 180 | for (i = 0; i < 10; i++) 181 | continue; 182 | } 183 | } 184 | contract test { 185 | function fun(uint256 a) { 186 | for (uint256 i = 0; i < 10; i++) { 187 | uint256 x = i; 188 | break; 189 | continue; 190 | } 191 | } 192 | } 193 | // contract from { 194 | // } 195 | contract test { 196 | function functionName(bytes32 input) returns (bytes32 out); 197 | } 198 | contract test { 199 | string a = hex"00FF0000"; 200 | string b = hex'00AA0000'; 201 | } 202 | contract test { 203 | function fun(uint256 a) { 204 | if (a >= 8) { 205 | return; 206 | } else { 207 | var b = 7; 208 | } 209 | } 210 | } 211 | import './abc.sol' as my_abc; 212 | 213 | contract test {} 214 | import { a as my_a, b as my_b } from './abc.sol'; 215 | 216 | contract test {} 217 | import "./abc.sol"; 218 | 219 | contract test { 220 | function fun() { 221 | uint64(2); 222 | } 223 | } 224 | import * as abc from './abc.sol'; 225 | 226 | contract test {} 227 | contract c { 228 | uint[] a; 229 | function f() returns (uint, uint) { 230 | a = [1,2,3]; 231 | return (a[3], [2,3,4][0]); 232 | } 233 | } 234 | library Lib { 235 | function f() { } 236 | } 237 | contract test { 238 | function test() { 239 | a = 1 wei; 240 | a = 2 szabo; 241 | a = 3 finney; 242 | a = 4 ether; 243 | 244 | a = 1 seconds; 245 | a = 2 minutes; 246 | a = 3 hours; 247 | a = 4 days; 248 | a = 5 weeks; 249 | a = 6 years; 250 | } 251 | 252 | uint256 a; 253 | } 254 | contract c { 255 | function c () 256 | { 257 | a = 1 wei * 100 wei + 7 szabo - 3; 258 | } 259 | uint256 a; 260 | } 261 | contract Foo { 262 | function f() { 263 | uint[] storage x; 264 | uint[] memory y; 265 | } 266 | } 267 | // contract Foo { 268 | // function f(uint[] constant x, uint[] memory y) { } 269 | // } 270 | contract test { 271 | mapping(address => bytes32) names; 272 | } 273 | contract test { 274 | struct test_struct { 275 | address addr; 276 | uint256 count; 277 | mapping(bytes32 => test_struct) self_reference; 278 | } 279 | } 280 | contract test { 281 | struct test_struct { 282 | address addr; 283 | mapping (uint64 => mapping (bytes32 => uint)) complex_mapping; 284 | } 285 | } 286 | contract c { 287 | modifier mod { if (msg.sender == 0) _; } 288 | } 289 | contract c { 290 | modifier mod(address a) { if (msg.sender == a) _; } 291 | } 292 | contract c { 293 | modifier mod1(address a) { if (msg.sender == a) _; } 294 | modifier mod2 { if (msg.sender == 2) _; } 295 | function f() mod1(7) mod2 { } 296 | } 297 | contract c { 298 | mapping(uint => mapping(uint => int8)[8][][9])[] x; 299 | } 300 | contract C { 301 | function f() { 302 | var (a,b,c) = g(); 303 | var (d) = 2; 304 | var (,e) = 3; 305 | var (f,) = 4; 306 | var (x,,) = g(); 307 | var (,y,) = g(); 308 | var (,,) = g(); 309 | } 310 | function g() returns (uint, uint, uint) {} 311 | } 312 | contract test { 313 | function fun() { 314 | uint64(2); 315 | } 316 | } 317 | 318 | contract test2 { 319 | function fun() { 320 | uint64(2); 321 | } 322 | } 323 | import "./abc.sol"; 324 | 325 | contract test { 326 | function fun() { 327 | } 328 | } 329 | 330 | contract test2 { 331 | function fun() { 332 | } 333 | } 334 | 335 | import "./def.sol"; 336 | 337 | contract foo { 338 | function foo(uint a) { 339 | } 340 | } 341 | 342 | contract bar { 343 | function bar(string a, string b) { 344 | } 345 | } 346 | 347 | contract derived is foo(2), bar("abc", "def") { 348 | function fun() { 349 | } 350 | } 351 | contract test { 352 | function f() returns(bool succeeded) { 353 | return false; 354 | } 355 | } 356 | contract test { 357 | uint256 stateVar; 358 | function functionName() {} 359 | } 360 | contract test { 361 | function fun(int256 a) { 362 | int256 x = (1 + 4) * (a - 12) + -9; 363 | bool y = true && (a < 6) || false; 364 | } 365 | } 366 | contract test { 367 | function fun(uint a) returns(uint r) { return a; } 368 | function fun(uint a, uint b) returns(uint r) { return a + b; } 369 | } 370 | contract c { 371 | function fun() returns (uint r) { 372 | var _ = 8; 373 | return _ + 1; 374 | } 375 | } 376 | pragma solidity ^0.4.4; 377 | 378 | contract test {} 379 | contract test { 380 | uint256 stateVar; 381 | function functionName(bytes32 input) returns (bytes32 out) {} 382 | } 383 | contract test { 384 | uint256 stateVariable1; 385 | } 386 | contract test { 387 | function fun() { 388 | uint64(2); 389 | } 390 | } 391 | contract test { 392 | uint256 stateVar; 393 | struct MyStructName { 394 | address addr; 395 | uint256 count; 396 | } 397 | } 398 | contract C { 399 | function f() { 400 | uint a = (1); 401 | var (b,) = 1; 402 | var (c,d) = (1, 2 + a); 403 | var (e,) = (1, 2, b); 404 | (a) = 3; 405 | } 406 | } 407 | contract test { 408 | function fun() { 409 | var x = new uint64[](3); 410 | } 411 | } 412 | contract test { 413 | function f() { 414 | uint a = +10; 415 | a--; 416 | 417 | a = ~a; 418 | delete a; 419 | 420 | bool b = !true; 421 | } 422 | } 423 | library Lib { 424 | } 425 | 426 | contract C { 427 | struct s { uint a; } 428 | using Lib for uint; 429 | using Lib for *; 430 | using Lib for s; 431 | 432 | function f() { 433 | } 434 | } 435 | contract test { 436 | function fun(uint256 a) { 437 | var b = 5; 438 | uint256 c; 439 | mapping(address=>bytes32) d; 440 | } 441 | } 442 | contract test { 443 | function fun(uint256 a) { 444 | var b = 2; 445 | uint256 c = 0x87; 446 | uint256 d = 0X78; 447 | mapping(address=>bytes32) d; 448 | bytes32 name = "Solidity"; 449 | } 450 | } 451 | contract c { 452 | uint private a; 453 | uint internal b; 454 | uint public c; 455 | uint d; 456 | function f() {} 457 | function f_priv() private {} 458 | function f_public() public {} 459 | function f_internal() internal {} 460 | } 461 | contract test { 462 | function fun(uint256 a) { 463 | while (true) { uint256 x = 1; break; continue; } x = 9; 464 | } 465 | } 466 | 467 | contract test { 468 | function() { 469 | assembly { 470 | mstore(0x40, 0x60) // store the "free memory pointer" 471 | // function dispatcher 472 | switch div(calldataload(0), exp(2, 226)) 473 | case 0xb3de648b { 474 | let (r) := f(calldataload(4)) 475 | let ret := $allocate(0x20) 476 | mstore(ret, r) 477 | return(ret, 0x20) 478 | } 479 | default { revert(0, 0) } 480 | // memory allocator 481 | function $allocate(size) -> pos { 482 | pos := mload(0x40) 483 | mstore(0x40, add(pos, size)) 484 | } 485 | // the contract function 486 | function f(x) -> y { 487 | y := 1 488 | for { let i := 0 } lt(i, x) { i := add(i, 1) } { 489 | y := mul(2, y) 490 | } 491 | if gt(y, 2) { revert(0, 0) } 492 | } 493 | } 494 | } 495 | } 496 | 497 | contract test { 498 | function f() view { 499 | return 2; 500 | } 501 | function g() pure { 502 | return 2; 503 | } 504 | } 505 | 506 | contract test { 507 | function f() { 508 | uint256 a = 2.3e5; 509 | } 510 | } 511 | 512 | contract test { 513 | function f() { 514 | uint256 a; 515 | (a,) = g(); 516 | (,) = g(); 517 | () = (); 518 | } 519 | } 520 | 521 | contract test { 522 | function foo() public returns (byte b) { 523 | assembly { 524 | n := byte(0x0) 525 | } 526 | } 527 | } 528 | 529 | contract test { 530 | function() { 531 | emit EventCalled(1, 2, 3); 532 | } 533 | } 534 | 535 | contract test { 536 | constructor(uint a, uint b) withModifier {} 537 | } 538 | 539 | contract test { 540 | function () payable { 541 | (bytes32 a, uint b) = foo(); 542 | } 543 | } 544 | 545 | contract test { 546 | uint x = .1 ether; 547 | } 548 | 549 | contract test { 550 | function () { 551 | type(Proxy).creationCode; 552 | } 553 | } 554 | 555 | contract test { 556 | uint x = 1_000_000; 557 | uint y = 0x11_22_33; 558 | } 559 | 560 | contract test { 561 | function _finalization() internal { 562 | if (goalReached()) { 563 | _escrow.close(); 564 | _escrow.beneficiaryWithdraw(); 565 | } else { 566 | _escrow.enableRefunds(); 567 | } 568 | 569 | super._finalization(); 570 | } 571 | } 572 | --------------------------------------------------------------------------------