diff --git a/ethereumj-core/pom.xml b/ethereumj-core/pom.xml index 8cd499ea..537450fa 100644 --- a/ethereumj-core/pom.xml +++ b/ethereumj-core/pom.xml @@ -1,100 +1,63 @@ - - - 4.0.0 - - EthereumJ - EthereumJ - 0.0.1-SNAPSHOT - - - - repository.jboss.org - JBoss Releases Repository - http://repository.jboss.org/maven2 - - - - - repository.jboss.org - JBoss Releases Repository - http://repository.jboss.org/maven2 - - - - - - - - junit - junit - 4.10 - + + 4.0.0 + org.ethereum + EthereumJ + jar + 0.0.1-SNAPSHOT + EthereumJ + http://maven.apache.org + + UTF-8 + + 4.11 + 1.7.7 + 0.7 + 1.50.0.0 + gen + + io.netty netty-all 4.0.17.Final - - - org.bouncycastle - bcpg-jdk15on - 1.49 - sources - - - - - org.bouncycastle - bcprov-ext-jdk15on - 1.49 - sources - - - - - org.bouncycastle - bcprov-jdk15on - 1.49 - sources - - - + + junit + junit + ${junit.version} + test + + + + com.madgag.spongycastle + core + ${spongycastle.version} + com.fifesoft rsyntaxtextarea 2.5.0 - com.maxmind.geoip2 geoip2 0.6.0 - com.maxmind.geoip geoip-api 1.2.11 - - org.antlr antlr 3.1.3 + - org.antlr stringtemplate @@ -107,6 +70,20 @@ 2.5.3 + + + org.slf4j + slf4j-jdk14 + ${slf4j.version} + runtime + true + + + org.slf4j + slf4j-api + ${slf4j.version} + diff --git a/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java b/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java new file mode 100644 index 00000000..a44c0992 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java @@ -0,0 +1,661 @@ +package org.ethereum.crypto; +/** + * Copyright 2011 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.ethereum.util.ByteUtil.bigIntegerToBytes; + +import java.io.Serializable; +import java.math.BigInteger; +import java.nio.charset.Charset; +import java.security.SecureRandom; +import java.security.SignatureException; +import java.util.Arrays; + +import javax.annotation.Nullable; + +import org.ethereum.util.ByteUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spongycastle.asn1.sec.SECNamedCurves; +import org.spongycastle.asn1.x9.X9ECParameters; +import org.spongycastle.asn1.x9.X9IntegerConverter; +import org.spongycastle.crypto.AsymmetricCipherKeyPair; +import org.spongycastle.crypto.digests.SHA256Digest; +import org.spongycastle.crypto.generators.ECKeyPairGenerator; +import org.spongycastle.crypto.params.ECDomainParameters; +import org.spongycastle.crypto.params.ECKeyGenerationParameters; +import org.spongycastle.crypto.params.ECPrivateKeyParameters; +import org.spongycastle.crypto.params.ECPublicKeyParameters; +import org.spongycastle.crypto.signers.ECDSASigner; +import org.spongycastle.crypto.signers.HMacDSAKCalculator; +import org.spongycastle.math.ec.ECAlgorithms; +import org.spongycastle.math.ec.ECCurve; +import org.spongycastle.math.ec.ECPoint; +import org.spongycastle.util.encoders.Base64; +import org.spongycastle.util.encoders.Hex; + +import com.google.common.base.Preconditions; + +public class ECKey implements Serializable { + private static final Logger log = LoggerFactory.getLogger(ECKey.class); + + /** The parameters of the secp256k1 curve that Bitcoin uses. */ + public static final ECDomainParameters CURVE; + + /** + * Equal to CURVE.getN().shiftRight(1), used for canonicalising the S value of a signature. If you aren't + * sure what this is about, you can ignore it. + */ + public static final BigInteger HALF_CURVE_ORDER; + + private static final SecureRandom secureRandom; + private static final long serialVersionUID = -728224901792295832L; + + static { + // All clients must agree on the curve to use by agreement. Bitcoin uses secp256k1. + X9ECParameters params = SECNamedCurves.getByName("secp256k1"); + CURVE = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); + HALF_CURVE_ORDER = params.getN().shiftRight(1); + secureRandom = new SecureRandom(); + } + + // The two parts of the key. If "priv" is set, "pub" can always be calculated. If "pub" is set but not "priv", we + // can only verify signatures not make them. + // TODO: Redesign this class to use consistent internals and more efficient serialization. + private BigInteger priv; + protected final ECPoint pub; + + // Transient because it's calculated on demand. + transient private byte[] pubKeyHash; + + /** + * Generates an entirely new keypair. Point compression is used so the resulting public key will be 33 bytes + * (32 for the co-ordinate and 1 byte to represent the y bit). + */ + public ECKey() { + this(secureRandom); + } + + /** + * Generates an entirely new keypair with the given {@link SecureRandom} object. Point compression is used so the + * resulting public key will be 33 bytes (32 for the co-ordinate and 1 byte to represent the y bit). + */ + public ECKey(SecureRandom secureRandom) { + ECKeyPairGenerator generator = new ECKeyPairGenerator(); + ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, secureRandom); + generator.init(keygenParams); + AsymmetricCipherKeyPair keypair = generator.generateKeyPair(); + ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate(); + ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic(); + priv = privParams.getD(); + pub = CURVE.getCurve().decodePoint(pubParams.getQ().getEncoded(true)); + } + + protected ECKey(@Nullable BigInteger priv, ECPoint pub) { + this.priv = priv; + if(pub == null) + throw new IllegalArgumentException("Public key may not be null"); + this.pub = pub; + } + + /** + * Utility for compressing an elliptic curve point. Returns the same point if it's already compressed. + * See the ECKey class docs for a discussion of point compression. + */ + public static ECPoint compressPoint(ECPoint uncompressed) { + return CURVE.getCurve().decodePoint(uncompressed.getEncoded(true)); + } + + /** + * Utility for decompressing an elliptic curve point. Returns the same point if it's already compressed. + * See the ECKey class docs for a discussion of point compression. + */ + public static ECPoint decompressPoint(ECPoint compressed) { + return CURVE.getCurve().decodePoint(compressed.getEncoded(false)); + } + + /** + * Creates an ECKey given the private key only. The public key is calculated from it (this is slow). Note that + * the resulting public key is compressed. + */ + public static ECKey fromPrivate(BigInteger privKey) { + return new ECKey(privKey, compressPoint(CURVE.getG().multiply(privKey))); + } + + /** + * Creates an ECKey given the private key only. The public key is calculated from it (this is slow). The resulting + * public key is compressed. + */ + public static ECKey fromPrivate(byte[] privKeyBytes) { + return fromPrivate(new BigInteger(1, privKeyBytes)); + } + + /** + * Creates an ECKey that simply trusts the caller to ensure that point is really the result of multiplying the + * generator point by the private key. This is used to speed things up when you know you have the right values + * already. The compression state of pub will be preserved. + */ + public static ECKey fromPrivateAndPrecalculatedPublic(BigInteger priv, ECPoint pub) { + return new ECKey(priv, pub); + } + + /** + * Creates an ECKey that simply trusts the caller to ensure that point is really the result of multiplying the + * generator point by the private key. This is used to speed things up when you know you have the right values + * already. The compression state of the point will be preserved. + */ + public static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] pub) { + checkNotNull(priv); + checkNotNull(pub); + return new ECKey(new BigInteger(1, priv), CURVE.getCurve().decodePoint(pub)); + } + + /** + * Creates an ECKey that cannot be used for signing, only verifying signatures, from the given point. The + * compression state of pub will be preserved. + */ + public static ECKey fromPublicOnly(ECPoint pub) { + return new ECKey(null, pub); + } + + /** + * Creates an ECKey that cannot be used for signing, only verifying signatures, from the given encoded point. + * The compression state of pub will be preserved. + */ + public static ECKey fromPublicOnly(byte[] pub) { + return new ECKey(null, CURVE.getCurve().decodePoint(pub)); + } + + /** + * Returns a copy of this key, but with the public point represented in uncompressed form. Normally you would + * never need this: it's for specialised scenarios or when backwards compatibility in encoded form is necessary. + */ + public ECKey decompress() { + if (!pub.isCompressed()) + return this; + else + return new ECKey(priv, decompressPoint(pub)); + } + + /** + * Returns true if this key doesn't have access to private key bytes. This may be because it was never + * given any private key bytes to begin with (a watching key). + */ + public boolean isPubKeyOnly() { + return priv == null; + } + + /** + * Returns true if this key has access to private key bytes. Does the opposite of + * {@link #isPubKeyOnly()}. + */ + public boolean hasPrivKey() { + return priv != null; + } + + /** + * Returns public key bytes from the given private key. To convert a byte array into a BigInteger, use + * new BigInteger(1, bytes); + */ + public static byte[] publicKeyFromPrivate(BigInteger privKey, boolean compressed) { + ECPoint point = CURVE.getG().multiply(privKey); + return point.getEncoded(compressed); + } + + /** Gets the hash160 form of the public key (as seen in addresses). */ + public byte[] getAddress() { + if (pubKeyHash == null) { + byte[] pubBytes = this.pub.getEncoded(false); + pubKeyHash = HashUtil.sha3hash160(Arrays.copyOfRange(pubBytes, 1, pubBytes.length)); + } + return pubKeyHash; + } + + /** + * Gets the raw public key value. This appears in transaction scriptSigs. Note that this is not the same + * as the pubKeyHash/address. + */ + public byte[] getPubKey() { + return pub.getEncoded(); + } + + /** Gets the public key in the form of an elliptic curve point object from Bouncy Castle. */ + public ECPoint getPubKeyPoint() { + return pub; + } + + /** + * Gets the private key in the form of an integer field element. The public key is derived by performing EC + * point addition this number of times (i.e. point multiplying). + * + * @throws java.lang.IllegalStateException if the private key bytes are not available. + */ + public BigInteger getPrivKey() { + if (priv == null) + throw new MissingPrivateKeyException(); + return priv; + } + + /** + * Returns whether this key is using the compressed form or not. Compressed pubkeys are only 33 bytes, not 64. + */ + public boolean isCompressed() { + return pub.isCompressed(); + } + + public String toString() { + StringBuilder b = new StringBuilder(); + b.append("pub:").append(Hex.toHexString(pub.getEncoded(false))); + return b.toString(); + } + + /** + * Produce a string rendering of the ECKey INCLUDING the private key. + * Unless you absolutely need the private key it is better for security reasons to just use toString(). + */ + public String toStringWithPrivate() { + StringBuilder b = new StringBuilder(); + b.append(toString()); + if (priv != null) { + b.append(" priv:").append(Hex.toHexString(priv.toByteArray())); + } + return b.toString(); + } + + /** + * Groups the two components that make up a signature, and provides a way to encode to DER form, which is + * how ECDSA signatures are represented when embedded in other data structures in the Bitcoin protocol. The raw + * components can be useful for doing further EC maths on them. + */ + public static class ECDSASignature { + /** The two components of the signature. */ + public final BigInteger r, s; + public byte v; + + /** + * Constructs a signature with the given components. Does NOT automatically canonicalise the signature. + */ + public ECDSASignature(BigInteger r, BigInteger s) { + this.r = r; + this.s = s; + } + + public static ECDSASignature fromComponents(byte[] r, byte[] s) { + return new ECDSASignature(new BigInteger(r), new BigInteger(s)); + } + + /** + * Will automatically adjust the S component to be less than or equal to half the curve order, if necessary. + * This is required because for every signature (r,s) the signature (r, -s (mod N)) is a valid signature of + * the same message. However, we dislike the ability to modify the bits of a Bitcoin transaction after it's + * been signed, as that violates various assumed invariants. Thus in future only one of those forms will be + * considered legal and the other will be banned. + */ + public ECDSASignature toCanonicalised() { + if (s.compareTo(HALF_CURVE_ORDER) > 0) { + // The order of the curve is the number of valid points that exist on that curve. If S is in the upper + // half of the number of valid points, then bring it back to the lower half. Otherwise, imagine that + // N = 10 + // s = 8, so (-8 % 10 == 2) thus both (r, 8) and (r, 2) are valid solutions. + // 10 - 8 == 2, giving us always the latter solution, which is canonical. + return new ECDSASignature(r, CURVE.getN().subtract(s)); + } else { + return this; + } + } + + public String toBase64() { + byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S + sigData[0] = v; + System.arraycopy(bigIntegerToBytes(this.r, 32), 0, sigData, 1, 32); + System.arraycopy(bigIntegerToBytes(this.s, 32), 0, sigData, 33, 32); + return new String(Base64.encode(sigData), Charset.forName("UTF-8")); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ECDSASignature signature = (ECDSASignature) o; + + if (!r.equals(signature.r)) return false; + if (!s.equals(signature.s)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = r.hashCode(); + result = 31 * result + s.hashCode(); + return result; + } + } + + /** + * Signs the given hash and returns the R and S components as BigIntegers + * and put them in ECDSASignature + * + * @param data to sign + * @return ECDSASignature signature that contains the R and S components + */ + public ECDSASignature doSign(byte[] input) { + // No decryption of private key required. + if (priv == null) + throw new MissingPrivateKeyException(); + checkNotNull(priv); + ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest())); + ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, CURVE); + signer.init(true, privKey); + BigInteger[] components = signer.generateSignature(input); + return new ECDSASignature(components[0], components[1]).toCanonicalised(); + } + + /** + * Signs a text message using the standard Bitcoin messaging signing format and returns the signature as a base64 + * encoded string. + * + * @throws IllegalStateException if this ECKey does not have the private part. + */ + public String signBitcoinMessage(String message) { + byte[] data = ByteUtil.formatForBitcoinSigning(message); + byte[] hash = HashUtil.doubleDigest(data); + return sign(hash).toBase64(); + } + + /** + * Takes the sha3 hash (32 bytes) of data and returns the ECDSA signature + * + * @throws IllegalStateException if this ECKey does not have the private part. + */ + public ECDSASignature sign(byte[] messageHash) { + if (priv == null) + throw new MissingPrivateKeyException(); + ECDSASignature sig = doSign(messageHash); + // Now we have to work backwards to figure out the recId needed to recover the signature. + int recId = -1; + for (int i = 0; i < 4; i++) { + ECKey k = ECKey.recoverFromSignature(i, sig, messageHash, isCompressed()); + if (k != null && k.pub.equals(pub)) { + recId = i; + break; + } + } + if (recId == -1) + throw new RuntimeException("Could not construct a recoverable key. This should never happen."); + sig.v = (byte) (recId + 27 + (isCompressed() ? 4 : 0)); + return sig; + } + + /** + * Given a piece of text and a message signature encoded in base64, returns an ECKey + * containing the public key that was used to sign it. This can then be compared to the expected public key to + * determine if the signature was correct. + * + * @param message a piece of human readable text that was signed + * @param signatureBase64 The Bitcoin-format message signature in base64 + * @throws SignatureException If the public key could not be recovered or if there was a signature format error. + */ + public static ECKey signedBitcoinMessageToKey(String message, String signatureBase64) throws SignatureException { + byte[] messageBytes = ByteUtil.formatForBitcoinSigning(message); + // Note that the C++ code doesn't actually seem to specify any character encoding. Presumably it's whatever + // JSON-SPIRIT hands back. Assume UTF-8 for now. + byte[] messageHash = HashUtil.doubleDigest(messageBytes); + return signatureToKey(messageHash, signatureBase64); + } + + /** + * Given a piece of text and a message signature encoded in base64, returns an ECKey + * containing the public key that was used to sign it. This can then be compared to the expected public key to + * determine if the signature was correct. + * + * @param message a piece of human readable text that was signed + * @param signatureBase64 The Bitcoin-format message signature in base64 + * @throws SignatureException If the public key could not be recovered or if there was a signature format error. + */ + public static ECKey signatureToKey(byte[] messageHash, String signatureBase64) throws SignatureException { + byte[] signatureEncoded; + try { + signatureEncoded = Base64.decode(signatureBase64); + } catch (RuntimeException e) { + // This is what you get back from Bouncy Castle if base64 doesn't decode :( + throw new SignatureException("Could not decode base64", e); + } + // Parse the signature bytes into r/s and the selector value. + if (signatureEncoded.length < 65) + throw new SignatureException("Signature truncated, expected 65 bytes and got " + signatureEncoded.length); + int header = signatureEncoded[0] & 0xFF; + // The header byte: 0x1B = first key with even y, 0x1C = first key with odd y, + // 0x1D = second key with even y, 0x1E = second key with odd y + if (header < 27 || header > 34) + throw new SignatureException("Header byte out of range: " + header); + BigInteger r = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 1, 33)); + BigInteger s = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 33, 65)); + ECDSASignature sig = new ECDSASignature(r, s); + boolean compressed = false; + if (header >= 31) { + compressed = true; + header -= 4; + } + int recId = header - 27; + ECKey key = ECKey.recoverFromSignature(recId, sig, messageHash, compressed); + if (key == null) + throw new SignatureException("Could not recover public key from signature"); + return key; + } + + /** + *

Verifies the given ECDSA signature against the message bytes using the public key bytes.

+ * + *

When using native ECDSA verification, data must be 32 bytes, and no element may be + * larger than 520 bytes.

+ * + * @param data Hash of the data to verify. + * @param signature signature. + * @param pub The public key bytes to use. + */ + public static boolean verify(byte[] data, ECDSASignature signature, byte[] pub) { + ECDSASigner signer = new ECDSASigner(); + ECPublicKeyParameters params = new ECPublicKeyParameters(CURVE.getCurve().decodePoint(pub), CURVE); + signer.init(false, params); + try { + return signer.verifySignature(data, signature.r, signature.s); + } catch (NullPointerException e) { + // Bouncy Castle contains a bug that can cause NPEs given specially crafted signatures. Those signatures + // are inherently invalid/attack sigs so we just fail them here rather than crash the thread. + log.error("Caught NPE inside bouncy castle"); + e.printStackTrace(); + return false; + } + } + + /** + * Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key. + * + * @param data Hash of the data to verify. + * @param signature signature. + * @param pub The public key bytes to use. + */ + public static boolean verify(byte[] data, byte[] signature, byte[] pub) { + return verify(data, signature, pub); + } + + /** + * Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key. + * + * @param data Hash of the data to verify. + * @param signature signature. + */ + public boolean verify(byte[] data, byte[] signature) { + return ECKey.verify(data, signature, getPubKey()); + } + + /** + * Verifies the given R/S pair (signature) against a hash using the public key. + */ + public boolean verify(byte[] sigHash, ECDSASignature signature) { + return ECKey.verify(sigHash, signature, getPubKey()); + } + + /** + * Returns true if this pubkey is canonical, i.e. the correct length taking into account compression. + */ + public boolean isPubKeyCanonical() { + return isPubKeyCanonical(pub.getEncoded()); + } + + /** + * Returns true if the given pubkey is canonical, i.e. the correct length taking into account compression. + */ + public static boolean isPubKeyCanonical(byte[] pubkey) { + if (pubkey[0] == 0x04) { + // Uncompressed pubkey + if (pubkey.length != 65) + return false; + } else if (pubkey[0] == 0x02 || pubkey[0] == 0x03) { + // Compressed pubkey + if (pubkey.length != 33) + return false; + } else + return false; + return true; + } + + /** + * Convenience wrapper around {@link ECKey#signedBitcoinMessageToKey(String, String)}. If the key derived from the + * signature is not the same as this one, throws a SignatureException. + */ + public void verifyBitcoinMessage(String message, String signatureBase64) throws SignatureException { + ECKey key = ECKey.signedBitcoinMessageToKey(message, signatureBase64); + if (!key.pub.equals(pub)) + throw new SignatureException("Signature did not match for message"); + } + + /** + *

Given the components of a signature and a selector value, recover and return the public key + * that generated the signature according to the algorithm in SEC1v2 section 4.1.6.

+ * + *

The recId is an index from 0 to 3 which indicates which of the 4 possible keys is the correct one. Because + * the key recovery operation yields multiple potential keys, the correct key must either be stored alongside the + * signature, or you must be willing to try each recId in turn until you find one that outputs the key you are + * expecting.

+ * + *

If this method returns null it means recovery was not possible and recId should be iterated.

+ * + *

Given the above two points, a correct usage of this method is inside a for loop from 0 to 3, and if the + * output is null OR a key that is not the one you expect, you try again with the next recId.

+ * + * @param recId Which possible key to recover. + * @param sig the R and S components of the signature, wrapped. + * @param messageHash Hash of the data that was signed. + * @param compressed Whether or not the original pubkey was compressed. + * @return An ECKey containing only the public part, or null if recovery wasn't possible. + */ + @Nullable + public static ECKey recoverFromSignature(int recId, ECDSASignature sig, byte[] messageHash, boolean compressed) { + Preconditions.checkArgument(recId >= 0, "recId must be positive"); + Preconditions.checkArgument(sig.r.signum() >= 0, "r must be positive"); + Preconditions.checkArgument(sig.s.signum() >= 0, "s must be positive"); + Preconditions.checkNotNull(messageHash); + // 1.0 For j from 0 to h (h == recId here and the loop is outside this function) + // 1.1 Let x = r + jn + BigInteger n = CURVE.getN(); // Curve order. + BigInteger i = BigInteger.valueOf((long) recId / 2); + BigInteger x = sig.r.add(i.multiply(n)); + // 1.2. Convert the integer x to an octet string X of length mlen using the conversion routine + // specified in Section 2.3.7, where mlen = ⌈(log2 p)/8⌉ or mlen = ⌈m/8⌉. + // 1.3. Convert the octet string (16 set binary digits)||X to an elliptic curve point R using the + // conversion routine specified in Section 2.3.4. If this conversion routine outputs “invalid”, then + // do another iteration of Step 1. + // + // More concisely, what these points mean is to use X as a compressed public key. + ECCurve.Fp curve = (ECCurve.Fp) CURVE.getCurve(); + BigInteger prime = curve.getQ(); // Bouncy Castle is not consistent about the letter it uses for the prime. + if (x.compareTo(prime) >= 0) { + // Cannot have point co-ordinates larger than this as everything takes place modulo Q. + return null; + } + // Compressed keys require you to know an extra bit of data about the y-coord as there are two possibilities. + // So it's encoded in the recId. + ECPoint R = decompressKey(x, (recId & 1) == 1); + // 1.4. If nR != point at infinity, then do another iteration of Step 1 (callers responsibility). + if (!R.multiply(n).isInfinity()) + return null; + // 1.5. Compute e from M using Steps 2 and 3 of ECDSA signature verification. + BigInteger e = new BigInteger(1, messageHash); + // 1.6. For k from 1 to 2 do the following. (loop is outside this function via iterating recId) + // 1.6.1. Compute a candidate public key as: + // Q = mi(r) * (sR - eG) + // + // Where mi(x) is the modular multiplicative inverse. We transform this into the following: + // Q = (mi(r) * s ** R) + (mi(r) * -e ** G) + // Where -e is the modular additive inverse of e, that is z such that z + e = 0 (mod n). In the above equation + // ** is point multiplication and + is point addition (the EC group operator). + // + // We can find the additive inverse by subtracting e from zero then taking the mod. For example the additive + // inverse of 3 modulo 11 is 8 because 3 + 8 mod 11 = 0, and -3 mod 11 = 8. + BigInteger eInv = BigInteger.ZERO.subtract(e).mod(n); + BigInteger rInv = sig.r.modInverse(n); + BigInteger srInv = rInv.multiply(sig.s).mod(n); + BigInteger eInvrInv = rInv.multiply(eInv).mod(n); + ECPoint.Fp q = (ECPoint.Fp) ECAlgorithms.sumOfTwoMultiplies(CURVE.getG(), eInvrInv, R, srInv); + return ECKey.fromPublicOnly(q.getEncoded(compressed)); + } + + /** Decompress a compressed public key (x co-ord and low-bit of y-coord). */ + private static ECPoint decompressKey(BigInteger xBN, boolean yBit) { + X9IntegerConverter x9 = new X9IntegerConverter(); + byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve())); + compEnc[0] = (byte)(yBit ? 0x03 : 0x02); + return CURVE.getCurve().decodePoint(compEnc); + } + + /** + * Returns a 32 byte array containing the private key, or null if the key is encrypted or public only + */ + @Nullable + public byte[] getPrivKeyBytes() { + return bigIntegerToBytes(priv, 32); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || !(o instanceof ECKey)) return false; + + ECKey ecKey = (ECKey) o; + + if (priv != null && !priv.equals(ecKey.priv)) return false; + if (pub != null && !pub.equals(ecKey.pub)) return false; + + return true; + } + + @Override + public int hashCode() { + // Public keys are random already so we can just use a part of them as the hashcode. Read from the start to + // avoid picking up the type code (compressed vs uncompressed) which is tacked on the end. + byte[] bits = getPubKey(); + return (bits[0] & 0xFF) | ((bits[1] & 0xFF) << 8) | ((bits[2] & 0xFF) << 16) | ((bits[3] & 0xFF) << 24); + } + + @SuppressWarnings("serial") + public static class MissingPrivateKeyException extends RuntimeException { + } + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/crypto/HashUtil.java b/ethereumj-core/src/main/java/org/ethereum/crypto/HashUtil.java new file mode 100644 index 00000000..58e6597c --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/crypto/HashUtil.java @@ -0,0 +1,61 @@ +package org.ethereum.crypto; + +import static java.util.Arrays.copyOfRange; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.ethereum.util.ByteUtil; + +public class HashUtil { + + private static final MessageDigest sha256digest; + + static { + try { + sha256digest = MessageDigest.getInstance("SHA-256"); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); // Can't happen. + } + } + + public static byte[] sha256(byte[] input) { + return sha256digest.digest(input); + } + + public static byte[] sha3(byte[] input) { + return SHA3Helper.sha3(input); + } + + public static String sha3String(String input) { + return SHA3Helper.sha3String(input); + } + + /** + * Calculates RIGTMOST160(SHA3(input)). This is used in address calculations. + */ + public static byte[] sha3hash160(byte[] input) { + byte[] hash = sha3(input); + return copyOfRange(hash, 12, hash.length); + } + + /** + * See {@link ByteUtil#doubleDigest(byte[], int, int)}. + */ + public static byte[] doubleDigest(byte[] input) { + return doubleDigest(input, 0, input.length); + } + + /** + * Calculates the SHA-256 hash of the given byte range, and then hashes the resulting hash again. This is + * standard procedure in Bitcoin. The resulting hash is in big endian form. + */ + public static byte[] doubleDigest(byte[] input, int offset, int length) { + synchronized (sha256digest) { + sha256digest.reset(); + sha256digest.update(input, offset, length); + byte[] first = sha256digest.digest(); + return sha256digest.digest(first); + } + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/crypto/KeyCrypterException.java b/ethereumj-core/src/main/java/org/ethereum/crypto/KeyCrypterException.java new file mode 100644 index 00000000..a2ed9927 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/crypto/KeyCrypterException.java @@ -0,0 +1,21 @@ +package org.ethereum.crypto; +/** + *

Exception to provide the following to {@link EncrypterDecrypterOpenSSL}:

+ *
    + *
  • Provision of encryption / decryption exception
  • + *
+ *

This base exception acts as a general failure mode not attributable to a specific cause (other than + * that reported in the exception message). Since this is in English, it may not be worth reporting directly + * to the user other than as part of a "general failure to parse" response.

+ */ +public class KeyCrypterException extends RuntimeException { + private static final long serialVersionUID = -4441989608332681377L; + + public KeyCrypterException(String s) { + super(s); + } + + public KeyCrypterException(String s, Throwable throwable) { + super(s, throwable); + } +} \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/crypto/SHA3Helper.java b/ethereumj-core/src/main/java/org/ethereum/crypto/SHA3Helper.java new file mode 100644 index 00000000..c6e78162 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/crypto/SHA3Helper.java @@ -0,0 +1,96 @@ +package org.ethereum.crypto; + +import java.math.BigInteger; + +import org.spongycastle.crypto.digests.SHA3Digest; +import org.spongycastle.util.encoders.Hex; + +public class SHA3Helper { + + private static SHA3Digest DEFAULT_DIGEST_256 = new SHA3Digest(256); + + public static String sha3String(String message) { + return sha3String(message, DEFAULT_DIGEST_256, true); + } + + public static String sha3String(byte[] message) { + return sha3String(message, DEFAULT_DIGEST_256, true); + } + + public static byte[] sha3(String message) { + return sha3(Hex.decode(message), DEFAULT_DIGEST_256, true); + } + + public static byte[] sha3(byte[] message) { + return sha3(message, DEFAULT_DIGEST_256, true); + } + + protected static String sha3String(String message, Size bitSize) { + SHA3Digest digest = new SHA3Digest(bitSize.bits); + return sha3String(message, digest, true); + } + + protected static String sha3String(byte[] message, Size bitSize) { + SHA3Digest digest = new SHA3Digest(bitSize.bits); + return sha3String(message, digest, true); + } + + protected static String sha3String(String message, Size bitSize, boolean bouncyencoder) { + SHA3Digest digest = new SHA3Digest(bitSize.bits); + return sha3String(message, digest, bouncyencoder); + } + + protected static String sha3string(byte[] message, Size bitSize, boolean bouncyencoder) { + SHA3Digest digest = new SHA3Digest(bitSize.bits); + return sha3String(message, digest, bouncyencoder); + } + + private static String sha3String(String message, SHA3Digest digest, boolean bouncyencoder) { + if (message != null) { + return sha3String(Hex.decode(message), digest, bouncyencoder); + } + throw new NullPointerException("Can't hash a NULL value"); + } + + private static String sha3String(byte[] message, SHA3Digest digest, boolean bouncyencoder) { + byte[] hash = doSha3(message, digest, bouncyencoder); + if (bouncyencoder) { + return Hex.toHexString(hash); + } else { + BigInteger bigInt = new BigInteger(1, hash); + return bigInt.toString(16); + } + } + + private static byte[] sha3(byte[] message, SHA3Digest digest, boolean bouncyencoder) { + return doSha3(message, digest, bouncyencoder); + } + + private static byte[] doSha3(byte[] message, SHA3Digest digest, boolean bouncyencoder) { + byte[] hash = new byte[digest.getDigestSize()]; + + if (message.length != 0) { + digest.update(message, 0, message.length); + } + digest.doFinal(hash, 0); + return hash; + } + + public enum Size { + + S224(224), + S256(256), + S384(384), + S512(512); + + int bits = 0; + + Size(int bits) { + this.bits = bits; + } + + public int getValue() { + return this.bits; + } + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/PeersTableMain.java b/ethereumj-core/src/main/java/org/ethereum/gui/PeersTableMain.java new file mode 100644 index 00000000..5efee7f4 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/gui/PeersTableMain.java @@ -0,0 +1,73 @@ +package org.ethereum.gui; + +import javax.swing.*; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellRenderer; + +import java.awt.*; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 25/04/14 07:11 + */ +public class PeersTableMain extends JFrame{ + + // Instance attributes used in this example + private JPanel topPanel; + private JTable table; + private JScrollPane scrollPane; + + // Constructor of main frame + public PeersTableMain() { + // Set the frame characteristics + setTitle("Ethereum Peers"); + setSize(355, 300); + setLocation(815, 80); + setBackground(Color.gray); + + java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png"); + Toolkit kit = Toolkit.getDefaultToolkit(); + Image img = kit.createImage(url); + this.setIconImage(img); + + // Create a panel to hold all other components + topPanel = new JPanel(); + topPanel.setLayout(new BorderLayout()); + getContentPane().add(topPanel); + + // Create a new table instance + table = new JTable(); + table.setModel(new PeersTableModel()); + + table.setFont(new Font("Courier New", Font.PLAIN, 18)); + table.setForeground(Color.GRAY); + table.setTableHeader(null); + + TableCellRenderer tcr = table.getDefaultRenderer(String.class); + DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) tcr; + renderer.setHorizontalAlignment(SwingConstants.CENTER); + + table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + table.setCellSelectionEnabled(true); + + table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + table.getColumnModel().getColumn(0).setPreferredWidth(60); + table.getColumnModel().getColumn(1).setPreferredWidth(200); + table.getColumnModel().getColumn(2).setPreferredWidth(60); + + table.setRowMargin(3); + table.setRowHeight(50); + + // Add the table to a scrolling pane + scrollPane = new JScrollPane(table); + topPanel.add(scrollPane, BorderLayout.CENTER); + } + + public static void main(String args[]) { + + PeersTableMain mainFrame = new PeersTableMain(); + mainFrame.setVisible(true); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java b/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java index 66c068d7..17075d66 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java @@ -1,8 +1,7 @@ package org.ethereum.gui; -import samples.PeersTableMain; - import javax.swing.*; + import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java index 2effc204..1e5cb09a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java @@ -6,7 +6,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelOption; import io.netty.channel.FixedRecvByteBufAllocator; -import org.bouncycastle.util.encoders.Hex; +import org.spongycastle.util.encoders.Hex; import org.ethereum.gui.PeerListener; import org.ethereum.manager.MainData; import org.ethereum.net.RLP; @@ -83,8 +83,6 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { System.out.println("No ping answer for [30 sec]"); throw new Error("No ping return for 30 [sec]"); - - // TODO: shutdown the handler } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java index 77cb55a3..b60d3090 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java @@ -1,6 +1,6 @@ package org.ethereum.net.message; -import org.bouncycastle.util.encoders.Hex; +import org.spongycastle.util.encoders.Hex; import org.ethereum.net.RLP; import org.ethereum.net.rlp.RLPItem; import org.ethereum.net.rlp.RLPList; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/vo/BlockData.java b/ethereumj-core/src/main/java/org/ethereum/net/vo/BlockData.java index 22d9f237..a91ad7e6 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/vo/BlockData.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/vo/BlockData.java @@ -1,5 +1,6 @@ package org.ethereum.net.vo; +import org.ethereum.crypto.HashUtil; import org.ethereum.net.rlp.RLPElement; import org.ethereum.net.rlp.RLPItem; import org.ethereum.net.rlp.RLPList; @@ -56,11 +57,10 @@ public class BlockData { } - // [parent_hash, uncles_hash, coinbase, state_root, tx_list_hash, difficulty, timestamp, extradata, nonce] private void parseRLP(){ - this.hash = Utils.sha3(rawData.getRLPData()); + this.hash = HashUtil.sha3(rawData.getRLPData()); List params = ((RLPList) rawData.getElement(0)).getList(); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/vo/PeerData.java b/ethereumj-core/src/main/java/org/ethereum/net/vo/PeerData.java index 9203f3cd..d98a81ca 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/vo/PeerData.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/vo/PeerData.java @@ -1,11 +1,10 @@ package org.ethereum.net.vo; -import org.bouncycastle.util.encoders.Hex; +import org.spongycastle.util.encoders.Hex; import org.ethereum.net.rlp.RLPList; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.Arrays; /** * www.ethereumJ.com diff --git a/ethereumj-core/src/main/java/org/ethereum/net/vo/TransactionData.java b/ethereumj-core/src/main/java/org/ethereum/net/vo/TransactionData.java index 7205a485..e910f884 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/vo/TransactionData.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/vo/TransactionData.java @@ -1,5 +1,6 @@ package org.ethereum.net.vo; +import org.ethereum.crypto.HashUtil; import org.ethereum.net.rlp.RLPItem; import org.ethereum.net.rlp.RLPList; import org.ethereum.util.Utils; @@ -64,7 +65,7 @@ public class TransactionData { if (rawData.size() == 9){ // Simple transaction - this.hash = Utils.sha3(rawData.getRLPData()); + this.hash = HashUtil.sha3(rawData.getRLPData()); this.nonce = ((RLPItem) rawData.getElement(0)).getData(); this.value = ((RLPItem) rawData.getElement(1)).getData(); this.receiveAddress = ((RLPItem) rawData.getElement(2)).getData(); @@ -77,7 +78,7 @@ public class TransactionData { } else if (rawData.size() == 10){ // Contract creation transaction - this.hash = Utils.sha3(rawData.getRLPData()); + this.hash = HashUtil.sha3(rawData.getRLPData()); this.nonce = ((RLPItem) rawData.getElement(0)).getData(); this.value = ((RLPItem) rawData.getElement(1)).getData(); this.receiveAddress = ((RLPItem) rawData.getElement(2)).getData(); diff --git a/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java b/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java new file mode 100644 index 00000000..9d5ef905 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java @@ -0,0 +1,127 @@ +package org.ethereum.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.nio.charset.Charset; +import java.util.Arrays; + +import com.google.common.primitives.UnsignedInteger; +import com.google.common.primitives.UnsignedLongs; + +public class ByteUtil { + + /** The string that prefixes all text messages signed using Bitcoin keys. */ + public static final String BITCOIN_SIGNED_MESSAGE_HEADER = "Bitcoin Signed Message:\n"; + public static final byte[] BITCOIN_SIGNED_MESSAGE_HEADER_BYTES = BITCOIN_SIGNED_MESSAGE_HEADER.getBytes(); + + /** + * Creates a copy of bytes and appends b to the end of it + */ + public static byte[] appendByte(byte[] bytes, byte b) { + byte[] result = Arrays.copyOf(bytes, bytes.length + 1); + result[result.length - 1] = b; + return result; + } + +// /** +// * Returns the given byte array hex encoded. +// */ +// public static String bytesToHexString(byte[] bytes) { +// StringBuffer buf = new StringBuffer(bytes.length * 2); +// for (byte b : bytes) { +// String s = Integer.toString(0xFF & b, 16); +// if (s.length() < 2) +// buf.append('0'); +// buf.append(s); +// } +// return buf.toString(); +// } + + /** + * The regular {@link java.math.BigInteger#toByteArray()} method isn't quite what we often need: it appends a + * leading zero to indicate that the number is positive and may need padding. + * + * @param b the integer to format into a byte array + * @param numBytes the desired size of the resulting byte array + * @return numBytes byte long array. + */ + public static byte[] bigIntegerToBytes(BigInteger b, int numBytes) { + if (b == null) { + return null; + } + byte[] bytes = new byte[numBytes]; + byte[] biBytes = b.toByteArray(); + int start = (biBytes.length == numBytes + 1) ? 1 : 0; + int length = Math.min(biBytes.length, numBytes); + System.arraycopy(biBytes, start, bytes, numBytes - length, length); + return bytes; + } + + /** + *

Given a textual message, returns a byte buffer formatted as follows:

+ * + *

[24] "Bitcoin Signed Message:\n" [message.length as a varint] message

+ */ + public static byte[] formatForBitcoinSigning(String message) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES.length); + bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES); + byte[] messageBytes = message.getBytes(Charset.forName("UTF-8")); + bos.write(encodeInt(messageBytes.length)); + bos.write(messageBytes); + return bos.toByteArray(); + } catch (IOException e) { + throw new RuntimeException(e); // Cannot happen. + } + } + + /** + *

Given a textual message, returns a byte buffer formatted as follows:

+ */ + public static byte[] formatForEthereumSigning(byte[] message) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + bos.write(encodeInt(message.length)); + bos.write(message); + return bos.toByteArray(); + } catch (IOException e) { + throw new RuntimeException(e); // Cannot happen. + } + } + + public static byte[] encodeInt(int value) { + if (isLessThanUnsigned(value, 253)) { + return new byte[]{(byte) value}; + } else if (isLessThanUnsigned(value, 65536)) { + return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)}; + } else if (isLessThanUnsigned(value, UnsignedInteger.MAX_VALUE.longValue())) { + byte[] bytes = new byte[5]; + bytes[0] = (byte) 254; + uint32ToByteArrayLE(value, bytes, 1); + return bytes; + } else { + byte[] bytes = new byte[9]; + bytes[0] = (byte) 255; + uint32ToByteArrayLE(value, bytes, 1); + uint32ToByteArrayLE(value >>> 32, bytes, 5); + return bytes; + } + } + + /** + * Work around lack of unsigned types in Java. + */ + public static boolean isLessThanUnsigned(long n1, long n2) { + return UnsignedLongs.compare(n1, n2) < 0; + } + + public static void uint32ToByteArrayLE(long val, byte[] out, int offset) { + out[offset + 0] = (byte) (0xFF & (val >> 0)); + out[offset + 1] = (byte) (0xFF & (val >> 8)); + out[offset + 2] = (byte) (0xFF & (val >> 16)); + out[offset + 3] = (byte) (0xFF & (val >> 24)); + } + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/util/Utils.java b/ethereumj-core/src/main/java/org/ethereum/util/Utils.java index dd91bf8d..223da3d3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/util/Utils.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/Utils.java @@ -1,20 +1,12 @@ package org.ethereum.util; -import org.bouncycastle.asn1.sec.SECNamedCurves; -import org.bouncycastle.asn1.x9.X9ECParameters; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.math.ec.ECPoint; -import org.bouncycastle.util.encoders.Hex; - -import javax.swing.*; import java.math.BigInteger; import java.net.URL; -import java.security.MessageDigest; -import java.security.Security; -import java.util.Arrays; import java.util.regex.Pattern; -import static java.lang.System.exit; +import javax.swing.ImageIcon; + +import org.spongycastle.util.encoders.Hex; /** * www.ethereumj.com @@ -31,19 +23,14 @@ public class Utils { byte[] result = new byte[arrSize]; for (int i = 0; i < arrSize; ++i){ - int digit1 = hexSymbols.indexOf( hexString.charAt(i * 3) ); int digit2 = hexSymbols.indexOf( hexString.charAt(i * 3 + 1) ); - result[i] = (byte) (digit1 * 16 + digit2); } - return result; } - public static String toHexString(byte[] data){ - if (data == null) return "null"; else return Hex.toHexString(data); } @@ -61,7 +48,6 @@ public class Utils { return (new BigInteger(1, numberBytes)).toString(); } - public static void printHexStringForByte(byte data){ System.out.print("["); @@ -70,16 +56,11 @@ public class Utils { if (((int) data & 0xFF) < 16) { hexNum = "0" + hexNum; } - System.out.print( hexNum ); - System.out.print("]"); - System.out.println(); } - - public static void printHexStringForByteArray(byte[] data){ System.out.print("["); @@ -89,80 +70,17 @@ public class Utils { if (((int) data[i] & 0xFF) < 16) { hexNum = "0" + hexNum; } - System.out.print( hexNum ); System.out.print(" "); } System.out.print("]"); - System.out.println(); } - private static MessageDigest sha3Digest = null; - private static MessageDigest ripemd160Digest = null; - static { - - try{ - Security.addProvider(new BouncyCastleProvider()); - ripemd160Digest = MessageDigest.getInstance("RIPEMD160", "BC"); - sha3Digest = MessageDigest.getInstance("SHA3-256", "BC"); - } catch (Throwable th){ - - th.printStackTrace(); - exit(0); - } - } - - public static byte[] sha3(byte[] token){ - return sha3Digest.digest(token); - } - - - - public static byte[] ripemd160(byte[] token){ - - return ripemd160Digest.digest(token); - } - - - static X9ECParameters curvParams = SECNamedCurves.getByName("secp256k1"); - - public static byte[] privToAddress(byte[] priv){ - - /* address create howto - - token = "cow" - step1 = sha3(token) // generate 256 bit privkey - step2 = privtopub(step1)[1:] // generate 512 bit pubkey with secp256k1 - step3 = sha3(step2)[12:] - */ - - // TODO: validity checks - BigInteger privKey = new BigInteger(1, priv); - - - ECPoint Q = curvParams.getG().multiply(privKey); - byte[] pubKey = Q.getEncoded(); - - // TODO: find a performance improvement here - how to omit creation of new byte[] - byte[] _pubKey = Arrays.copyOfRange(pubKey, 1, pubKey.length); - - byte[] _addr = Utils.sha3(_pubKey); - - // TODO: find a performance improvement here - how to omit creation of new byte[] - byte[] addr = Arrays.copyOfRange(_addr, 12, _addr.length); - - return addr; - } - - public static ImageIcon getImageIcon(String resource){ URL imageURL = ClassLoader.getSystemResource(resource); ImageIcon image = new ImageIcon(imageURL); - return image; } - - } diff --git a/ethereumj-core/src/main/java/samples/DeterministicDSA.java b/ethereumj-core/src/main/java/samples/DeterministicDSA.java deleted file mode 100644 index 7c78b85f..00000000 --- a/ethereumj-core/src/main/java/samples/DeterministicDSA.java +++ /dev/null @@ -1,439 +0,0 @@ -package samples; -// ================================================================== - -import java.math.BigInteger; -import java.security.InvalidKeyException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -/** - * Deterministic DSA signature generation. This is a sample - * implementation designed to illustrate how deterministic DSA - * chooses the pseudorandom value k when signing a given message. - * This implementation was NOT optimized or hardened against - * side-channel leaks. - * - * An instance is created with a hash function name, which must be - * supported by the underlying Java virtual machine ("SHA-1" and - * "SHA-256" should work everywhere). The data to sign is input - * through the {@code update()} methods. The private key is set with - * {@link #setPrivateKey}. The signature is obtained by calling - * {@link #sign}; alternatively, {@link #signHash} can be used to - * sign some data that has been externally hashed. The private key - * MUST be set before generating the signature itself, but message - * data can be input before setting the key. - * - * Instances are NOT thread-safe. However, once a signature has - * been generated, the same instance can be used again for another - * signature; {@link #setPrivateKey} need not be called again if the - * private key has not changed. {@link #reset} can also be called to - * cancel previously input data. Generating a signature with {@link - * #sign} (not {@link #signHash}) also implicitly causes a - * reset. - * - * ------------------------------------------------------------------ - * Copyright (c) 2013 IETF Trust and the persons identified as - * authors of the code. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, is permitted pursuant to, and subject to the license - * terms contained in, the Simplified BSD License set forth in Section - * 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents - * (http://trustee.ietf.org/license-info). - * - * Technical remarks and questions can be addressed to: - * pornin@bolet.org - * ------------------------------------------------------------------ - */ - -public class DeterministicDSA { - - private String macName; - private MessageDigest dig; - private Mac hmac; - private BigInteger p, q, g, x; - private int qlen, rlen, rolen, holen; - private byte[] bx; - - /** - * Create an instance, using the specified hash function. - * The name is used to obtain from the JVM an implementation - * of the hash function and an implementation of HMAC. - * - * @param hashName the hash function name - * @throws IllegalArgumentException on unsupported name - */ - public DeterministicDSA(String hashName) - { - try { - dig = MessageDigest.getInstance(hashName); - } catch (NoSuchAlgorithmException nsae) { - throw new IllegalArgumentException(nsae); - } - if (hashName.indexOf('-') < 0) { - macName = "Hmac" + hashName; - } else { - StringBuilder sb = new StringBuilder(); - sb.append("Hmac"); - int n = hashName.length(); - for (int i = 0; i < n; i ++) { - char c = hashName.charAt(i); - if (c != '-') { - sb.append(c); - } - } - macName = sb.toString(); - - } - try { - hmac = Mac.getInstance(macName); - } catch (NoSuchAlgorithmException nsae) { - throw new IllegalArgumentException(nsae); - } - holen = hmac.getMacLength(); - } - - /** - * Set the private key. - * - * @param p key parameter: field modulus - * @param q key parameter: subgroup order - * @param g key parameter: generator - * @param x private key - */ - public void setPrivateKey(BigInteger p, BigInteger q, - BigInteger g, BigInteger x) - { - /* - * Perform some basic sanity checks. We do not - * check primality of p or q because that would - * be too expensive. - * - * We reject keys where q is longer than 999 bits, - * because it would complicate signature encoding. - * Normal DSA keys do not have a q longer than 256 - * bits anyway. - */ - if (p == null || q == null || g == null || x == null - || p.signum() <= 0 || q.signum() <= 0 - || g.signum() <= 0 || x.signum() <= 0 - || x.compareTo(q) >= 0 || q.compareTo(p) >= 0 - || q.bitLength() > 999 - || g.compareTo(p) >= 0 || g.bitLength() == 1 - || g.modPow(q, p).bitLength() != 1) { - throw new IllegalArgumentException( - "invalid DSA private key"); - } - this.p = p; - this.q = q; - this.g = g; - this.x = x; - qlen = q.bitLength(); - if (q.signum() <= 0 || qlen < 8) { - throw new IllegalArgumentException( - "bad group order: " + q); - - - } - rolen = (qlen + 7) >>> 3; - rlen = rolen * 8; - - /* - * Convert the private exponent (x) into a sequence - * of octets. - */ - bx = int2octets(x); - } - - private BigInteger bits2int(byte[] in) - { - BigInteger v = new BigInteger(1, in); - int vlen = in.length * 8; - if (vlen > qlen) { - v = v.shiftRight(vlen - qlen); - } - return v; - } - - private byte[] int2octets(BigInteger v) - { - byte[] out = v.toByteArray(); - if (out.length < rolen) { - byte[] out2 = new byte[rolen]; - System.arraycopy(out, 0, - out2, rolen - out.length, - out.length); - return out2; - } else if (out.length > rolen) { - byte[] out2 = new byte[rolen]; - System.arraycopy(out, out.length - rolen, - out2, 0, rolen); - return out2; - } else { - return out; - } - } - - private byte[] bits2octets(byte[] in) - { - BigInteger z1 = bits2int(in); - BigInteger z2 = z1.subtract(q); - return int2octets(z2.signum() < 0 ? z1 : z2); - } - - /** - - - - Pornin Informational [Page 73] - - RFC 6979 Deterministic DSA and ECDSA August 2013 - - - * Set (or reset) the secret key used for HMAC. - * - * @param K the new secret key - */ - private void setHmacKey(byte[] K) - { - try { - hmac.init(new SecretKeySpec(K, macName)); - } catch (InvalidKeyException ike) { - throw new IllegalArgumentException(ike); - } - } - - /** - * Compute the pseudorandom k for signature generation, - * using the process specified for deterministic DSA. - * - * @param h1 the hashed message - * @return the pseudorandom k to use - */ - private BigInteger computek(byte[] h1) - { - /* - * Convert hash value into an appropriately truncated - * and/or expanded sequence of octets. The private - * key was already processed (into field bx[]). - */ - byte[] bh = bits2octets(h1); - - /* - * HMAC is always used with K as key. - * Whenever K is updated, we reset the - * current HMAC key. - */ - - /* step b. */ - byte[] V = new byte[holen]; - for (int i = 0; i < holen; i ++) { - V[i] = 0x01; - } - - /* step c. */ - byte[] K = new byte[holen]; - setHmacKey(K); - - /* step d. */ - hmac.update(V); - hmac.update((byte)0x00); - hmac.update(bx); - hmac.update(bh); - K = hmac.doFinal(); - setHmacKey(K); - - /* step e. */ - hmac.update(V); - V = hmac.doFinal(); - - /* step f. */ - hmac.update(V); - hmac.update((byte)0x01); - hmac.update(bx); - hmac.update(bh); - K = hmac.doFinal(); - setHmacKey(K); - - /* step g. */ - hmac.update(V); - V = hmac.doFinal(); - - /* step h. */ - byte[] T = new byte[rolen]; - for (;;) { - /* - * We want qlen bits, but we support only - * hash functions with an output length - * multiple of 8;acd hence, we will gather - * rlen bits, i.e., rolen octets. - */ - int toff = 0; - while (toff < rolen) { - hmac.update(V); - V = hmac.doFinal(); - int cc = Math.min(V.length, - T.length - toff); - System.arraycopy(V, 0, T, toff, cc); - toff += cc; - } - BigInteger k = bits2int(T); - if (k.signum() > 0 && k.compareTo(q) < 0) { - return k; - } - - /* - * k is not in the proper range; update - * K and V, and loop. - */ - - hmac.update(V); - hmac.update((byte)0x00); - K = hmac.doFinal(); - setHmacKey(K); - hmac.update(V); - V = hmac.doFinal(); - } - } - - /** - * Process one more byte of input data (message to sign). - * - * @param in the extra input byte - */ - public void update(byte in) - { - dig.update(in); - } - - /** - * Process some extra bytes of input data (message to sign). - * - * @param in the extra input bytes - */ - public void update(byte[] in) - { - dig.update(in, 0, in.length); - } - - /** - * Process some extra bytes of input data (message to sign). - * - * @param in the extra input buffer - * @param off the extra input offset - * @param len the extra input length (in bytes) - */ - public void update(byte[] in, int off, int len) - { - dig.update(in, off, len); - } - - /** - * Produce the signature. {@link #setPrivateKey} MUST have - * been called. The signature is computed over the data - * that was input through the {@code update*()} methods. - * This engine is then reset (made ready for a new - * signature generation). - * - - - - Pornin Informational [Page 76] - - RFC 6979 Deterministic DSA and ECDSA August 2013 - - - * @return the signature - */ - public byte[] sign() - { - return signHash(dig.digest()); - } - - /** - * Produce the signature. {@link #setPrivateKey} MUST - * have been called. The signature is computed over the - * provided hash value (data is assumed to have been hashed - * externally). The data that was input through the - * {@code update*()} methods is ignored, but kept. - * - * If the hash output is longer than the subgroup order - * (the length of q, in bits, denoted 'qlen'), then the - * provided value {@code h1} can be truncated, provided that - * at least qlen leading bits are preserved. In other words, - * bit values in {@code h1} beyond the first qlen bits are - * ignored. - * - * @param h1 the hash value - * @return the signature - */ - public byte[] signHash(byte[] h1) - { - if (p == null) { - throw new IllegalStateException( - "no private key set"); - } - try { - BigInteger k = computek(h1); - BigInteger r = g.modPow(k, p).mod(q); - BigInteger s = k.modInverse(q).multiply( - bits2int(h1).add(x.multiply(r))) - .mod(q); - - /* - * Signature encoding: ASN.1 SEQUENCE of - * two INTEGERs. The conditions on q - * imply that the encoded version of r and - * s is no longer than 127 bytes for each, - * including DER tag and length. - */ - byte[] br = r.toByteArray(); - byte[] bs = s.toByteArray(); - int ulen = br.length + bs.length + 4; - int slen = ulen + (ulen >= 128 ? 3 : 2); - - byte[] sig = new byte[slen]; - int i = 0; - sig[i ++] = 0x30; - if (ulen >= 128) { - sig[i ++] = (byte)0x81; - sig[i ++] = (byte)ulen; - } else { - sig[i ++] = (byte)ulen; - } - sig[i ++] = 0x02; - sig[i ++] = (byte)br.length; - System.arraycopy(br, 0, sig, i, br.length); - i += br.length; - sig[i ++] = 0x02; - sig[i ++] = (byte)bs.length; - System.arraycopy(bs, 0, sig, i, bs.length); - return sig; - - } catch (ArithmeticException ae) { - throw new IllegalArgumentException( - "DSA error (bad key ?)", ae); - } - } - - /** - * Reset this engine. Data input through the {@code - * update*()} methods is discarded. The current private key, - * if one was set, is kept unchanged. - */ - public void reset() - { - dig.reset(); - } -} - -// ================================================================== - - - - - - - diff --git a/ethereumj-core/src/main/java/samples/Main1.java b/ethereumj-core/src/main/java/samples/Main1.java deleted file mode 100644 index 83543bd8..00000000 --- a/ethereumj-core/src/main/java/samples/Main1.java +++ /dev/null @@ -1,191 +0,0 @@ -package samples; - -import com.maxmind.geoip.LookupService; -import com.maxmind.geoip.Region; -import com.maxmind.geoip.regionName; -import com.maxmind.geoip2.exception.GeoIp2Exception; -import org.ethereum.net.RLP; -import org.ethereum.util.Utils; - -import java.io.File; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; -import java.util.LinkedList; -import java.util.Queue; - -/** - * www.openchain.info - * User: Roman Mandeleil - * Created on: 31/03/14 21:06 - */ -public class Main1 { - - public static void main(String args[]) throws IOException, GeoIp2Exception, URISyntaxException { - - - try { - - URL flagURL = ClassLoader.getSystemResource("GeoLiteCity.dat"); - File file = new File(flagURL.toURI()); - LookupService cl = new LookupService(file); - System.out.println(cl.getLocation("110.77.217.185")); - - - } catch (IOException e) { - System.out.println("IO Exception"); - } - - - } - - - public static void main1(String args[]) throws IOException { - - //22400891000000088400000043414243 - - String helloPacket = "22400891000000088400000043414243"; - String pingPacket = "224008910000000102"; - - System.out.println(helloPacket); - - SocketChannel socketChannel = SocketChannel.open(); - socketChannel.connect(new InetSocketAddress("localhost", 20202)); - socketChannel.configureBlocking(false); - - String helloString = "22 40 08 91 00 00 00 79 F8 77 80 0A 80 AD 45 74 " + - "68 65 72 65 75 6D 28 2B 2B 29 2F 5A 65 72 6F 47 " + - "6F 78 2F 76 30 2E 34 2E 31 2F 6E 63 75 72 73 65 " + - "73 2F 4C 69 6E 75 78 2F 67 2B 2B 07 82 76 5F B8 " + - "40 D8 D6 0C 25 80 FA 79 5C FC 03 13 EF DE BA 86 " + - "9D 21 94 E7 9E 7C B2 B5 22 F7 82 FF A0 39 2C BB " + - "AB 8D 1B AC 30 12 08 B1 37 E0 DE 49 98 33 4F 3B " + - "CF 73 FA 11 7E F2 13 F8 74 17 08 9F EA F8 4C 21 " + - "B0 22 40 08 91 00 00 00 02 C1 02 22 40 08 91 00 " + - "00 00 26 E5 14 A0 AB 6B 9A 56 13 97 0F AA 77 1B " + - "12 D4 49 B2 E9 BB 92 5A B7 A3 69 F0 A4 B8 6B 28 " + - "6E 9D 54 00 99 CF 82 01 00 22 40 08 91 00 00 00 " + - "02 C1 16 22 40 08 91 00 00 00 02 C1 01 "; - - String getPeersString = "22 40 08 91 00 00 00 02 C1 10 "; - - - byte[] helloBytes = hexStringToByteArr(helloString); - - // Sending - ByteBuffer outBuffer = ByteBuffer.allocate(helloBytes.length); - - outBuffer.clear(); - outBuffer.put(helloBytes); - outBuffer.flip(); - - while (outBuffer.hasRemaining()) { - socketChannel.write(outBuffer); - } - - - outBuffer.clear(); - byte[] getPeersBytes = hexStringToByteArr(getPeersString); - - // Sending - outBuffer = ByteBuffer.allocate(getPeersBytes.length); - - outBuffer.clear(); - outBuffer.put(getPeersBytes); - outBuffer.flip(); - - while (outBuffer.hasRemaining()) { - socketChannel.write(outBuffer); - } - - - ByteBuffer inBuffer = ByteBuffer.allocate(1); - - int bytesRead = socketChannel.read(inBuffer); //read into buffer. - while (bytesRead != -1) { - - inBuffer.flip(); //make buffer ready for read - - while (inBuffer.hasRemaining()) { - - byte oneByte = inBuffer.get(); - - System.out.print(Integer.toHexString((int) oneByte & 0x00FF)); // read 1 byte at a time - System.out.print(" "); - } - - - inBuffer.clear(); //make buffer ready for writing - bytesRead = socketChannel.read(inBuffer); - } - - - // read 4 bytes sync token 0x22400891 - // read 4 bytes packet size token, translate to size - - // read packet according the size - - - } - - - public static byte[] hexStringToByteArr(String hexString) { - - String hexSymbols = "0123456789ABCDEF"; - - int arrSize = (int) (hexString.length() / 3); - byte[] result = new byte[arrSize]; - - for (int i = 0; i < arrSize; ++i) { - - int digit1 = hexSymbols.indexOf(hexString.charAt(i * 3)); - int digit2 = hexSymbols.indexOf(hexString.charAt(i * 3 + 1)); - - result[i] = (byte) (digit1 * 16 + digit2); - } - - - return result; - } - - - public static void main2(String args[]) { - - String helloPacket = - "F8 77 80 0B 80 AD 45 74 68 65 72 65 75 6D 28 2B 2B 29 " + - "2F 5A 65 72 6F 47 6F 78 2F 76 30 2E 34 2E 32 2F " + - "6E 63 75 72 73 65 73 2F 4C 69 6E 75 78 2F 67 2B " + - "2B 07 82 76 5F B8 40 80 7D 3E D5 E7 7C BA 05 8D " + - "C0 55 4A E0 90 98 9E FE EA 55 33 52 B3 1A DF DB " + - "80 5E 2A 1A 7D F7 9D 14 FE 8D 9D 2C CE AA D8 E9 " + - "4B 09 37 47 F1 33 C3 EE F3 98 83 96 20 1D 24 17 " + - "93 83 5D 38 70 FF D4"; - - - String peersPacket = "F8 4E 11 F8 4B C5 36 81 " + - "CC 0A 29 82 76 5F B8 40 D8 D6 0C 25 80 FA 79 5C " + - "FC 03 13 EF DE BA 86 9D 21 94 E7 9E 7C B2 B5 22 " + - "F7 82 FF A0 39 2C BB AB 8D 1B AC 30 12 08 B1 37 " + - "E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " + - "17 08 9F EA F8 4C 21 B0"; - - - byte[] payload = Utils.hexStringToByteArr(peersPacket); - - Utils.printHexStringForByteArray(payload); - - Queue index = new LinkedList(); - RLP.fullTraverse(payload, 0, 0, payload.length, 1, index); - -// for (Integer item : index) System.out.println("ind --> " + item); - - -// Message newMessage = MessageFactory.createMessage(payload, index); -// System.out.println(newMessage.toString()); - - - } -} diff --git a/ethereumj-core/src/main/java/samples/Main2.java b/ethereumj-core/src/main/java/samples/Main2.java deleted file mode 100644 index 738100fb..00000000 --- a/ethereumj-core/src/main/java/samples/Main2.java +++ /dev/null @@ -1,84 +0,0 @@ -package samples; - -import org.ethereum.net.client.ClientPeer; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 10/04/14 12:50 - */ -public class Main2 { - - - public static void main(String args[]){ - -// 66.49.191.123 -// 54.204.10.41 -// 130.88.0.226 -// 85.65.126.45 -// 54.72.31.55 - -// new ClientPeer().connect("66.49.191.123", 30303); -// new ClientPeer().connect("66.49.191.123", 30303); - -// new ClientPeer().connect("54.72.31.55", 30303); - - String ip_1 = "131.104.252.4"; - String ip_2 = "107.170.57.247"; - String ip_3 = "68.48.173.163"; - String ip_4 = "86.183.231.205"; - String ip_5 = "68.185.234.64"; - String ip_6 = "207.219.69.154"; - - - - -// new ClientPeer().connect("192.168.1.102", 30303); - - -// new ClientPeer().connect("83.172.226.79", 30303); -// new ClientPeer().connect("68.48.173.163", 31313); -// new ClientPeer().connect("86.150.41.127", 30303); - -// new ClientPeer().connect("82.217.72.169", 30303); nicksavers -// new ClientPeer().connect("94.197.120.80", 30303); stephan (ursium) - - -// new ClientPeer().connect("54.72.31.55", 30303); // peer discovery: capability = 4 - - new ClientPeer().connect("54.201.28.117", 30303); // poc-5 -// new ClientPeer().connect("94.210.200.192", 30303); // poc-5 -// new ClientPeer().connect("62.78.198.208", 30303); // poc-5 not stable - - - - } -} - -/* POC - 5 - - Hello: [/206.223.168.190] Canada - Hello: [/94.210.200.192] Netherlands - Hello: [/88.69.198.198] Germany - Hello: [/24.157.83.122] Canada - Hello: [/71.202.162.40] United States - Hello: [/64.231.10.208] Canada - Hello: [/85.65.126.45] Israel - Hello: [/62.78.198.208] Finland - Hello: [/50.133.12.228] United States - Hello: [/77.166.77.107] Netherlands - Hello: [/110.77.217.185] Thailand - Hello: [/64.231.9.30] Canada - Hello: [/213.100.250.57] Sweden - Hello: [/162.243.203.121] United States - Hello: [/82.217.72.169] Netherlands - Hello: [/99.231.80.166] Canada - Hello: [/131.104.252.4] Canada - Hello: [/54.204.10.41] United States - Hello: [/54.201.28.117] United States - Hello: [/67.204.1.162] Canada - Hello: [/82.240.16.5] France - Hello: [/74.79.23.119] United States -*/ - - diff --git a/ethereumj-core/src/main/java/samples/Main3.java b/ethereumj-core/src/main/java/samples/Main3.java deleted file mode 100644 index ddb6c017..00000000 --- a/ethereumj-core/src/main/java/samples/Main3.java +++ /dev/null @@ -1,48 +0,0 @@ -package samples; - - - -import org.bouncycastle.jce.ECPointUtil; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.jce.spec.ECParameterSpec; -import org.bouncycastle.jce.spec.ECPrivateKeySpec; -import org.bouncycastle.jce.spec.ECPublicKeySpec; -import org.bouncycastle.util.encoders.Hex; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.*; -import java.security.spec.ECFieldF2m; -import java.security.spec.EllipticCurve; -import java.util.Arrays; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 17/04/14 09:37 - */ -public class Main3 { - - static private byte[] shortMsg = Hex.decode("54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F67"); - - public static void main(String args[]) throws NoSuchProviderException, NoSuchAlgorithmException, IOException { - - Security.addProvider(new BouncyCastleProvider()); - - MessageDigest digest = MessageDigest.getInstance("SHA3-256", "BC"); - byte[] result = digest.digest(shortMsg); - - byte[] expected = Hex.decode("4D741B6F1EB29CB2A9B9911C82F56FA8D73B04959D3D9D222895DF6C0B28AA15"); - - if (Arrays.equals(expected, result)){ - - System.out.println("equal !!!"); - } else { - - Hex.encode(result, System.out); - System.out.flush(); - } - - - } -} diff --git a/ethereumj-core/src/main/java/samples/Main4.java b/ethereumj-core/src/main/java/samples/Main4.java deleted file mode 100644 index 8fff06fb..00000000 --- a/ethereumj-core/src/main/java/samples/Main4.java +++ /dev/null @@ -1,64 +0,0 @@ -package samples; - - -import org.bouncycastle.jce.ECPointUtil; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.util.encoders.Hex; -import org.ethereum.util.Utils; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.*; -import java.security.spec.*; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 17/04/14 09:37 - */ -public class Main4 { - - static private byte[] shortMsg = Hex.decode("54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F67"); - - public static void main(String args[]) throws NoSuchProviderException, NoSuchAlgorithmException, IOException, InvalidKeySpecException { - - Security.addProvider(new BouncyCastleProvider()); - - - EllipticCurve curve = new EllipticCurve( - new ECFieldF2m(239, // m - new int[] { 36 }), // k - new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16), // a - new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16)); // b - - ECParameterSpec params = new ECParameterSpec( - curve, - ECPointUtil.decodePoint(curve, - Hex.decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G - new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"), // n - 4); // h - - ECPrivateKeySpec priKeySpec = new ECPrivateKeySpec( - new BigInteger("145642755521911534651321230007534120304391871461646461466464667494947990"), // d - params); - - ECPublicKeySpec pubKeySpec = new ECPublicKeySpec( - ECPointUtil.decodePoint(curve, Hex.decode("045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5")), // Q - params); - - Signature sgr = Signature.getInstance("ECDSA", "BC"); - KeyFactory f = KeyFactory.getInstance("ECDSA", "BC"); - PrivateKey sKey = f.generatePrivate(priKeySpec); - PublicKey vKey = f.generatePublic(pubKeySpec); - -// System.out.println(vKey); - - - - System.out.println(Hex.toHexString(Utils.sha3("coinbase".getBytes()))); - -// toAddress(sha3("coinbase")); -// toAddress(76ec948a9207fdea26dcba91086bcdd181920ff52a539b0d1eb28e73b4cd92af); - - } -} diff --git a/ethereumj-core/src/main/java/samples/PeersTableMain.java b/ethereumj-core/src/main/java/samples/PeersTableMain.java deleted file mode 100644 index bdf67680..00000000 --- a/ethereumj-core/src/main/java/samples/PeersTableMain.java +++ /dev/null @@ -1,81 +0,0 @@ -package samples; - -import org.ethereum.gui.PeersTableModel; - -import javax.swing.*; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellRenderer; -import java.awt.*; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 25/04/14 07:11 - */ -public class PeersTableMain extends JFrame{ - - - - // Instance attributes used in this example - private JPanel topPanel; - private JTable table; - private JScrollPane scrollPane; - - // Constructor of main frame - public PeersTableMain() - { - // Set the frame characteristics - setTitle( "Ethereum Peers" ); - setSize( 355, 300 ); - setLocation(815, 80); - setBackground( Color.gray ); - - java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png"); - Toolkit kit = Toolkit.getDefaultToolkit(); - Image img = kit.createImage(url); - this.setIconImage(img); - - - // Create a panel to hold all other components - topPanel = new JPanel(); - topPanel.setLayout( new BorderLayout() ); - getContentPane().add( topPanel ); - - - // Create a new table instance - table = new JTable( ); - table.setModel(new PeersTableModel()); - - table.setFont(new Font("Courier New", Font.PLAIN, 18)); - table.setForeground(Color.GRAY); - table.setTableHeader(null); - - - TableCellRenderer tcr = table.getDefaultRenderer(String.class); - DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)tcr; - renderer.setHorizontalAlignment(SwingConstants.CENTER); - - table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - table.setCellSelectionEnabled(true); - - table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - table.getColumnModel().getColumn(0).setPreferredWidth(60); - table.getColumnModel().getColumn(1).setPreferredWidth(200); - table.getColumnModel().getColumn(2).setPreferredWidth(60); - - table.setRowMargin(3); - table.setRowHeight(50); - - // Add the table to a scrolling pane - scrollPane = new JScrollPane( table ); - topPanel.add( scrollPane, BorderLayout.CENTER ); - } - - public static void main(String args[]){ - - PeersTableMain mainFrame = new PeersTableMain(); - mainFrame.setVisible( true ); - mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - } -} diff --git a/ethereumj-core/src/main/java/samples/antlr/GenParser.java b/ethereumj-core/src/main/java/samples/antlr/GenParser.java deleted file mode 100644 index 66119b2d..00000000 --- a/ethereumj-core/src/main/java/samples/antlr/GenParser.java +++ /dev/null @@ -1,17 +0,0 @@ -package samples.antlr; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 25/04/14 17:06 - */ -public class GenParser { - - - public static void main(String args[]){ - - String userDir = System.getProperty("user.dir"); - String grammarFile = userDir + "\\src\\main\\java\\samples\\antlr\\Sample.g"; - org.antlr.Tool.main(new String[]{grammarFile}); - } -} diff --git a/ethereumj-core/src/main/java/samples/antlr/PyEsque.g b/ethereumj-core/src/main/java/samples/antlr/PyEsque.g deleted file mode 100644 index 3b29b727..00000000 --- a/ethereumj-core/src/main/java/samples/antlr/PyEsque.g +++ /dev/null @@ -1,105 +0,0 @@ -grammar PyEsque; - -options { - language = Java; - output = AST; - //output=template; -} - -tokens { - BLOCK; -} - -@header { - package samples.antlr; -} - -@lexer::header { - package samples.antlr; -} - - - -@lexer::members { - - private int previousIndents = -1; - private int indentLevel = 0; - java.util.Queue tokens = new java.util.LinkedList(); - - @Override - public void emit(Token t) { - state.token = t; - tokens.offer(t); - } - - @Override - public Token nextToken() { - super.nextToken(); - return tokens.isEmpty() ? getEOFToken() : tokens.poll(); - } - - private void jump(int ttype) { - indentLevel += (ttype == Dedent ? -1 : 1); - emit(new CommonToken(ttype, "level=" + indentLevel)); - } -} - - -parse - : block EOF -> block - ; - -block - : Indent block_atoms Dedent -> ^(BLOCK block_atoms) - ; - -block_atoms - : (Id | block)+ - ; - -NewLine - : NL SP? - { - int n = $SP.text == null ? 0 : $SP.text.length(); - if(n > previousIndents) { - jump(Indent); - previousIndents = n; - } - else if(n < previousIndents) { - jump(Dedent); - previousIndents = n; - } - else if(input.LA(1) == EOF) { - while(indentLevel > 0) { - jump(Dedent); - } - } - else { - skip(); - } - } - ; - - -Id - : ('a'..'z' | 'A'..'Z')+ - ; - -SpaceChars - : SP {skip();} - ; - -fragment NL : '\r'? '\n' | '\r'; -fragment SP : (' ' | '\t')+; -fragment Indent : ; -fragment Dedent : ; - - -expression - : INTEGER* - ; - - - -fragment DIGIT : '0'..'9'; -INTEGER : DIGIT+ ; diff --git a/ethereumj-core/src/main/java/samples/antlr/PyEsqueLexer.java b/ethereumj-core/src/main/java/samples/antlr/PyEsqueLexer.java deleted file mode 100644 index 1341f220..00000000 --- a/ethereumj-core/src/main/java/samples/antlr/PyEsqueLexer.java +++ /dev/null @@ -1,547 +0,0 @@ -// $ANTLR 3.5.2 E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g 2014-05-01 16:36:17 - - package samples.antlr; - - -import org.antlr.runtime.*; -import java.util.Stack; -import java.util.List; -import java.util.ArrayList; - -@SuppressWarnings("all") -public class PyEsqueLexer extends Lexer { - public static final int EOF=-1; - public static final int BLOCK=4; - public static final int DIGIT=5; - public static final int Dedent=6; - public static final int INTEGER=7; - public static final int Id=8; - public static final int Indent=9; - public static final int NL=10; - public static final int NewLine=11; - public static final int SP=12; - public static final int SpaceChars=13; - - - private int previousIndents = -1; - private int indentLevel = 0; - java.util.Queue tokens = new java.util.LinkedList(); - - @Override - public void emit(Token t) { - state.token = t; - tokens.offer(t); - } - - @Override - public Token nextToken() { - super.nextToken(); - return tokens.isEmpty() ? getEOFToken() : tokens.poll(); - } - - private void jump(int ttype) { - indentLevel += (ttype == Dedent ? -1 : 1); - emit(new CommonToken(ttype, "level=" + indentLevel)); - } - - - // delegates - // delegators - public Lexer[] getDelegates() { - return new Lexer[] {}; - } - - public PyEsqueLexer() {} - public PyEsqueLexer(CharStream input) { - this(input, new RecognizerSharedState()); - } - public PyEsqueLexer(CharStream input, RecognizerSharedState state) { - super(input,state); - } - @Override public String getGrammarFileName() { return "E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g"; } - - // $ANTLR start "NewLine" - public final void mNewLine() throws RecognitionException { - try { - int _type = NewLine; - int _channel = DEFAULT_TOKEN_CHANNEL; - CommonToken SP1=null; - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:61:2: ( NL ( SP )? ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:61:4: NL ( SP )? - { - mNL(); - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:61:7: ( SP )? - int alt1=2; - int LA1_0 = input.LA(1); - if ( (LA1_0=='\t'||LA1_0==' ') ) { - alt1=1; - } - switch (alt1) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:61:7: SP - { - int SP1Start39 = getCharIndex(); - int SP1StartLine39 = getLine(); - int SP1StartCharPos39 = getCharPositionInLine(); - mSP(); - SP1 = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, SP1Start39, getCharIndex()-1); - SP1.setLine(SP1StartLine39); - SP1.setCharPositionInLine(SP1StartCharPos39); - - } - break; - - } - - - int n = (SP1!=null?SP1.getText():null) == null ? 0 : (SP1!=null?SP1.getText():null).length(); - if(n > previousIndents) { - jump(Indent); - previousIndents = n; - } - else if(n < previousIndents) { - jump(Dedent); - previousIndents = n; - } - else if(input.LA(1) == EOF) { - while(indentLevel > 0) { - jump(Dedent); - } - } - else { - skip(); - } - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "NewLine" - - // $ANTLR start "Id" - public final void mId() throws RecognitionException { - try { - int _type = Id; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:85:2: ( ( 'a' .. 'z' | 'A' .. 'Z' )+ ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:85:4: ( 'a' .. 'z' | 'A' .. 'Z' )+ - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:85:4: ( 'a' .. 'z' | 'A' .. 'Z' )+ - int cnt2=0; - loop2: - while (true) { - int alt2=2; - int LA2_0 = input.LA(1); - if ( ((LA2_0 >= 'A' && LA2_0 <= 'Z')||(LA2_0 >= 'a' && LA2_0 <= 'z')) ) { - alt2=1; - } - - switch (alt2) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g: - { - if ( (input.LA(1) >= 'A' && input.LA(1) <= 'Z')||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - break; - - default : - if ( cnt2 >= 1 ) break loop2; - EarlyExitException eee = new EarlyExitException(2, input); - throw eee; - } - cnt2++; - } - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "Id" - - // $ANTLR start "SpaceChars" - public final void mSpaceChars() throws RecognitionException { - try { - int _type = SpaceChars; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:89:2: ( SP ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:89:4: SP - { - mSP(); - - skip(); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "SpaceChars" - - // $ANTLR start "NL" - public final void mNL() throws RecognitionException { - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:92:17: ( ( '\\r' )? '\\n' | '\\r' ) - int alt4=2; - int LA4_0 = input.LA(1); - if ( (LA4_0=='\r') ) { - int LA4_1 = input.LA(2); - if ( (LA4_1=='\n') ) { - alt4=1; - } - - else { - alt4=2; - } - - } - else if ( (LA4_0=='\n') ) { - alt4=1; - } - - else { - NoViableAltException nvae = - new NoViableAltException("", 4, 0, input); - throw nvae; - } - - switch (alt4) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:92:19: ( '\\r' )? '\\n' - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:92:19: ( '\\r' )? - int alt3=2; - int LA3_0 = input.LA(1); - if ( (LA3_0=='\r') ) { - alt3=1; - } - switch (alt3) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:92:19: '\\r' - { - match('\r'); - } - break; - - } - - match('\n'); - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:92:32: '\\r' - { - match('\r'); - } - break; - - } - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "NL" - - // $ANTLR start "SP" - public final void mSP() throws RecognitionException { - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:93:17: ( ( ' ' | '\\t' )+ ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:93:19: ( ' ' | '\\t' )+ - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:93:19: ( ' ' | '\\t' )+ - int cnt5=0; - loop5: - while (true) { - int alt5=2; - int LA5_0 = input.LA(1); - if ( (LA5_0=='\t'||LA5_0==' ') ) { - alt5=1; - } - - switch (alt5) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g: - { - if ( input.LA(1)=='\t'||input.LA(1)==' ' ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - break; - - default : - if ( cnt5 >= 1 ) break loop5; - EarlyExitException eee = new EarlyExitException(5, input); - throw eee; - } - cnt5++; - } - - } - - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "SP" - - // $ANTLR start "Indent" - public final void mIndent() throws RecognitionException { - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:94:17: () - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:94:19: - { - } - - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "Indent" - - // $ANTLR start "Dedent" - public final void mDedent() throws RecognitionException { - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:95:17: () - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:95:19: - { - } - - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "Dedent" - - // $ANTLR start "DIGIT" - public final void mDIGIT() throws RecognitionException { - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:104:16: ( '0' .. '9' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g: - { - if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "DIGIT" - - // $ANTLR start "INTEGER" - public final void mINTEGER() throws RecognitionException { - try { - int _type = INTEGER; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:105:9: ( ( DIGIT )+ ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:105:11: ( DIGIT )+ - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:105:11: ( DIGIT )+ - int cnt6=0; - loop6: - while (true) { - int alt6=2; - int LA6_0 = input.LA(1); - if ( ((LA6_0 >= '0' && LA6_0 <= '9')) ) { - alt6=1; - } - - switch (alt6) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g: - { - if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - break; - - default : - if ( cnt6 >= 1 ) break loop6; - EarlyExitException eee = new EarlyExitException(6, input); - throw eee; - } - cnt6++; - } - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "INTEGER" - - @Override - public void mTokens() throws RecognitionException { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:1:8: ( NewLine | Id | SpaceChars | INTEGER ) - int alt7=4; - switch ( input.LA(1) ) { - case '\n': - case '\r': - { - alt7=1; - } - break; - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': - { - alt7=2; - } - break; - case '\t': - case ' ': - { - alt7=3; - } - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - { - alt7=4; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 7, 0, input); - throw nvae; - } - switch (alt7) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:1:10: NewLine - { - mNewLine(); - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:1:18: Id - { - mId(); - - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:1:21: SpaceChars - { - mSpaceChars(); - - } - break; - case 4 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:1:32: INTEGER - { - mINTEGER(); - - } - break; - - } - } - - - -} diff --git a/ethereumj-core/src/main/java/samples/antlr/PyEsqueParser.java b/ethereumj-core/src/main/java/samples/antlr/PyEsqueParser.java deleted file mode 100644 index 387a6159..00000000 --- a/ethereumj-core/src/main/java/samples/antlr/PyEsqueParser.java +++ /dev/null @@ -1,394 +0,0 @@ -// $ANTLR 3.5.2 E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g 2014-05-01 16:36:17 - - package samples.antlr; - - -import org.antlr.runtime.*; -import java.util.Stack; -import java.util.List; -import java.util.ArrayList; - -import org.antlr.runtime.tree.*; - - -@SuppressWarnings("all") -public class PyEsqueParser extends Parser { - public static final String[] tokenNames = new String[] { - "", "", "", "", "BLOCK", "DIGIT", "Dedent", "INTEGER", - "Id", "Indent", "NL", "NewLine", "SP", "SpaceChars" - }; - public static final int EOF=-1; - public static final int BLOCK=4; - public static final int DIGIT=5; - public static final int Dedent=6; - public static final int INTEGER=7; - public static final int Id=8; - public static final int Indent=9; - public static final int NL=10; - public static final int NewLine=11; - public static final int SP=12; - public static final int SpaceChars=13; - - // delegates - public Parser[] getDelegates() { - return new Parser[] {}; - } - - // delegators - - - public PyEsqueParser(TokenStream input) { - this(input, new RecognizerSharedState()); - } - public PyEsqueParser(TokenStream input, RecognizerSharedState state) { - super(input, state); - } - - protected TreeAdaptor adaptor = new CommonTreeAdaptor(); - - public void setTreeAdaptor(TreeAdaptor adaptor) { - this.adaptor = adaptor; - } - public TreeAdaptor getTreeAdaptor() { - return adaptor; - } - @Override public String[] getTokenNames() { return PyEsqueParser.tokenNames; } - @Override public String getGrammarFileName() { return "E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g"; } - - - public static class parse_return extends ParserRuleReturnScope { - Object tree; - @Override - public Object getTree() { return tree; } - }; - - - // $ANTLR start "parse" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:48:1: parse : block EOF -> block ; - public final parse_return parse() throws RecognitionException { - parse_return retval = new parse_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token EOF2=null; - ParserRuleReturnScope block1 =null; - - Object EOF2_tree=null; - RewriteRuleTokenStream stream_EOF=new RewriteRuleTokenStream(adaptor,"token EOF"); - RewriteRuleSubtreeStream stream_block=new RewriteRuleSubtreeStream(adaptor,"rule block"); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:49:2: ( block EOF -> block ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:49:4: block EOF - { - pushFollow(FOLLOW_block_in_parse74); - block1=block(); - state._fsp--; - - stream_block.add(block1.getTree()); - EOF2=(Token)match(input,EOF,FOLLOW_EOF_in_parse76); - stream_EOF.add(EOF2); - - // AST REWRITE - // elements: block - // token labels: - // rule labels: retval - // token list labels: - // rule list labels: - // wildcard labels: - retval.tree = root_0; - RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.getTree():null); - - root_0 = (Object)adaptor.nil(); - // 49:14: -> block - { - adaptor.addChild(root_0, stream_block.nextTree()); - } - - - retval.tree = root_0; - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "parse" - - - public static class block_return extends ParserRuleReturnScope { - Object tree; - @Override - public Object getTree() { return tree; } - }; - - - // $ANTLR start "block" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:52:1: block : Indent block_atoms Dedent -> ^( BLOCK block_atoms ) ; - public final block_return block() throws RecognitionException { - block_return retval = new block_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token Indent3=null; - Token Dedent5=null; - ParserRuleReturnScope block_atoms4 =null; - - Object Indent3_tree=null; - Object Dedent5_tree=null; - RewriteRuleTokenStream stream_Indent=new RewriteRuleTokenStream(adaptor,"token Indent"); - RewriteRuleTokenStream stream_Dedent=new RewriteRuleTokenStream(adaptor,"token Dedent"); - RewriteRuleSubtreeStream stream_block_atoms=new RewriteRuleSubtreeStream(adaptor,"rule block_atoms"); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:53:2: ( Indent block_atoms Dedent -> ^( BLOCK block_atoms ) ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:53:4: Indent block_atoms Dedent - { - Indent3=(Token)match(input,Indent,FOLLOW_Indent_in_block91); - stream_Indent.add(Indent3); - - pushFollow(FOLLOW_block_atoms_in_block93); - block_atoms4=block_atoms(); - state._fsp--; - - stream_block_atoms.add(block_atoms4.getTree()); - Dedent5=(Token)match(input,Dedent,FOLLOW_Dedent_in_block95); - stream_Dedent.add(Dedent5); - - // AST REWRITE - // elements: block_atoms - // token labels: - // rule labels: retval - // token list labels: - // rule list labels: - // wildcard labels: - retval.tree = root_0; - RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.getTree():null); - - root_0 = (Object)adaptor.nil(); - // 53:30: -> ^( BLOCK block_atoms ) - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:53:33: ^( BLOCK block_atoms ) - { - Object root_1 = (Object)adaptor.nil(); - root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(BLOCK, "BLOCK"), root_1); - adaptor.addChild(root_1, stream_block_atoms.nextTree()); - adaptor.addChild(root_0, root_1); - } - - } - - - retval.tree = root_0; - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "block" - - - public static class block_atoms_return extends ParserRuleReturnScope { - Object tree; - @Override - public Object getTree() { return tree; } - }; - - - // $ANTLR start "block_atoms" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:56:1: block_atoms : ( Id | block )+ ; - public final block_atoms_return block_atoms() throws RecognitionException { - block_atoms_return retval = new block_atoms_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token Id6=null; - ParserRuleReturnScope block7 =null; - - Object Id6_tree=null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:57:2: ( ( Id | block )+ ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:57:5: ( Id | block )+ - { - root_0 = (Object)adaptor.nil(); - - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:57:5: ( Id | block )+ - int cnt1=0; - loop1: - while (true) { - int alt1=3; - int LA1_0 = input.LA(1); - if ( (LA1_0==Id) ) { - alt1=1; - } - else if ( (LA1_0==Indent) ) { - alt1=2; - } - - switch (alt1) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:57:6: Id - { - Id6=(Token)match(input,Id,FOLLOW_Id_in_block_atoms116); - Id6_tree = (Object)adaptor.create(Id6); - adaptor.addChild(root_0, Id6_tree); - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:57:11: block - { - pushFollow(FOLLOW_block_in_block_atoms120); - block7=block(); - state._fsp--; - - adaptor.addChild(root_0, block7.getTree()); - - } - break; - - default : - if ( cnt1 >= 1 ) break loop1; - EarlyExitException eee = new EarlyExitException(1, input); - throw eee; - } - cnt1++; - } - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "block_atoms" - - - public static class expression_return extends ParserRuleReturnScope { - Object tree; - @Override - public Object getTree() { return tree; } - }; - - - // $ANTLR start "expression" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:98:1: expression : ( INTEGER )* ; - public final expression_return expression() throws RecognitionException { - expression_return retval = new expression_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token INTEGER8=null; - - Object INTEGER8_tree=null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:99:2: ( ( INTEGER )* ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:99:4: ( INTEGER )* - { - root_0 = (Object)adaptor.nil(); - - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:99:4: ( INTEGER )* - loop2: - while (true) { - int alt2=2; - int LA2_0 = input.LA(1); - if ( (LA2_0==INTEGER) ) { - alt2=1; - } - - switch (alt2) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\PyEsque.g:99:4: INTEGER - { - INTEGER8=(Token)match(input,INTEGER,FOLLOW_INTEGER_in_expression246); - INTEGER8_tree = (Object)adaptor.create(INTEGER8); - adaptor.addChild(root_0, INTEGER8_tree); - - } - break; - - default : - break loop2; - } - } - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "expression" - - // Delegated rules - - - - public static final BitSet FOLLOW_block_in_parse74 = new BitSet(new long[]{0x0000000000000000L}); - public static final BitSet FOLLOW_EOF_in_parse76 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_Indent_in_block91 = new BitSet(new long[]{0x0000000000000300L}); - public static final BitSet FOLLOW_block_atoms_in_block93 = new BitSet(new long[]{0x0000000000000040L}); - public static final BitSet FOLLOW_Dedent_in_block95 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_Id_in_block_atoms116 = new BitSet(new long[]{0x0000000000000302L}); - public static final BitSet FOLLOW_block_in_block_atoms120 = new BitSet(new long[]{0x0000000000000302L}); - public static final BitSet FOLLOW_INTEGER_in_expression246 = new BitSet(new long[]{0x0000000000000082L}); -} diff --git a/ethereumj-core/src/main/java/samples/antlr/Python.g b/ethereumj-core/src/main/java/samples/antlr/Python.g deleted file mode 100644 index ddf5d060..00000000 --- a/ethereumj-core/src/main/java/samples/antlr/Python.g +++ /dev/null @@ -1,611 +0,0 @@ -/* - [The 'BSD licence'] - Copyright (c) 2004 Terence Parr and Loring Craymer - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** Python 2.3.3 Grammar - * - * Terence Parr and Loring Craymer - * February 2004 - * - * Converted to ANTLR v3 November 2005 by Terence Parr. - * - * This grammar was derived automatically from the Python 2.3.3 - * parser grammar to get a syntactically correct ANTLR grammar - * for Python. Then Terence hand tweaked it to be semantically - * correct; i.e., removed lookahead issues etc... It is LL(1) - * except for the (sometimes optional) trailing commas and semi-colons. - * It needs two symbols of lookahead in this case. - * - * Starting with Loring's preliminary lexer for Python, I modified it - * to do my version of the whole nasty INDENT/DEDENT issue just so I - * could understand the problem better. This grammar requires - * PythonTokenStream.java to work. Also I used some rules from the - * semi-formal grammar on the web for Python (automatically - * translated to ANTLR format by an ANTLR grammar, naturally ). - * The lexical rules for python are particularly nasty and it took me - * a long time to get it 'right'; i.e., think about it in the proper - * way. Resist changing the lexer unless you've used ANTLR a lot. ;) - * - * I (Terence) tested this by running it on the jython-2.1/Lib - * directory of 40k lines of Python. - * - * REQUIRES ANTLR v3 - */ -grammar Python; - - -tokens { - INDENT; - DEDENT; -} - -@lexer::members { - /** Handles context-sensitive lexing of implicit line joining such as - * the case where newline is ignored in cases like this: - * a = [3, - * 4] - */ - int implicitLineJoiningLevel = 0; - int startPos=-1; -} - -@header { - package org.ethereum.serpent; -} - -@lexer::header { - package org.ethereum.serpent; -} - - - -single_input - : NEWLINE - | simple_stmt - | compound_stmt NEWLINE - ; - -file_input - : (NEWLINE | stmt)* - ; - -eval_input - : (NEWLINE)* testlist (NEWLINE)* - ; - -funcdef - : 'def' NAME parameters COLON suite - {System.out.println("found method def "+$NAME.text);} - ; - -parameters - : LPAREN (varargslist)? RPAREN - ; - -varargslist - : defparameter (options {greedy=true;}:COMMA defparameter)* - (COMMA - ( STAR NAME (COMMA DOUBLESTAR NAME)? - | DOUBLESTAR NAME - )? - )? - | STAR NAME (COMMA DOUBLESTAR NAME)? - | DOUBLESTAR NAME - ; - -defparameter - : fpdef (ASSIGN test)? - ; - -fpdef - : NAME - | LPAREN fplist RPAREN - ; - -fplist - : fpdef (options {greedy=true;}:COMMA fpdef)* (COMMA)? - ; - - -stmt: simple_stmt - | compound_stmt - ; - -simple_stmt - : small_stmt (options {greedy=true;}:SEMI small_stmt)* (SEMI)? NEWLINE - ; - -small_stmt: expr_stmt - | print_stmt - | del_stmt - | pass_stmt - | flow_stmt - | import_stmt - | global_stmt - | exec_stmt - | assert_stmt - ; - -expr_stmt - : testlist - ( augassign testlist - | (ASSIGN testlist)+ - )? - ; - -augassign - : PLUSEQUAL - | MINUSEQUAL - | STAREQUAL - | SLASHEQUAL - | PERCENTEQUAL - | AMPEREQUAL - | VBAREQUAL - | CIRCUMFLEXEQUAL - | LEFTSHIFTEQUAL - | RIGHTSHIFTEQUAL - | DOUBLESTAREQUAL - | DOUBLESLASHEQUAL - ; - -print_stmt: - 'print' - ( testlist - | RIGHTSHIFT testlist - )? - ; - -del_stmt: 'del' exprlist - ; - -pass_stmt: 'pass' - ; - -flow_stmt: break_stmt - | continue_stmt - | return_stmt - | raise_stmt - | yield_stmt - ; - -break_stmt: 'break' - ; - -continue_stmt: 'continue' - ; - -return_stmt: 'return' (testlist)? - ; - -yield_stmt: 'yield' testlist - ; - -raise_stmt: 'raise' (test (COMMA test (COMMA test)?)?)? - ; - -import_stmt - : 'import' dotted_as_name (COMMA dotted_as_name)* - | 'from' dotted_name 'import' - (STAR | import_as_name (COMMA import_as_name)*) - ; - -import_as_name - : NAME (NAME NAME)? - ; - -dotted_as_name: dotted_name (NAME NAME)? - ; - -dotted_name: NAME (DOT NAME)* - ; - -global_stmt: 'global' NAME (COMMA NAME)* - ; - -exec_stmt: 'exec' expr ('in' test (COMMA test)?)? - ; - -assert_stmt: 'assert' test (COMMA test)? - ; - - -compound_stmt: if_stmt - | while_stmt - | for_stmt - | try_stmt - | funcdef - | classdef - ; - -if_stmt: 'if' test COLON suite ('elif' test COLON suite)* ('else' COLON suite)? - ; - -while_stmt: 'while' test COLON suite ('else' COLON suite)? - ; - -for_stmt: 'for' exprlist 'in' testlist COLON suite ('else' COLON suite)? - ; - -try_stmt - : 'try' COLON suite - ( (except_clause COLON suite)+ ('else' COLON suite)? - | 'finally' COLON suite - ) - ; - -except_clause: 'except' (test (COMMA test)?)? - ; - -suite: simple_stmt - | NEWLINE INDENT (stmt)+ DEDENT - ; - - -test: and_test ('or' and_test)* - | lambdef - ; - -and_test - : not_test ('and' not_test)* - ; - -not_test - : 'not' not_test - | comparison - ; - -comparison: expr (comp_op expr)* - ; - -comp_op: LESS - |GREATER - |EQUAL - |GREATEREQUAL - |LESSEQUAL - |ALT_NOTEQUAL - |NOTEQUAL - |'in' - |'not' 'in' - |'is' - |'is' 'not' - ; - -expr: xor_expr (VBAR xor_expr)* - ; - -xor_expr: and_expr (CIRCUMFLEX and_expr)* - ; - -and_expr: shift_expr (AMPER shift_expr)* - ; - -shift_expr: arith_expr ((LEFTSHIFT|RIGHTSHIFT) arith_expr)* - ; - -arith_expr: term ((PLUS|MINUS) term)* - ; - -term: factor ((STAR | SLASH | PERCENT | DOUBLESLASH ) factor)* - ; - -factor - : (PLUS|MINUS|TILDE) factor - | power - ; - -power - : atom (trailer)* (options {greedy=true;}:DOUBLESTAR factor)? - ; - -atom: LPAREN (testlist)? RPAREN - | LBRACK (listmaker)? RBRACK - | LCURLY (dictmaker)? RCURLY - | BACKQUOTE testlist BACKQUOTE - | NAME - | INT - | LONGINT - | FLOAT - | COMPLEX - | (STRING)+ - ; - -listmaker: test ( list_for | (options {greedy=true;}:COMMA test)* ) (COMMA)? - ; - -lambdef: 'lambda' (varargslist)? COLON test - ; - -trailer: LPAREN (arglist)? RPAREN - | LBRACK subscriptlist RBRACK - | DOT NAME - ; - -subscriptlist - : subscript (options {greedy=true;}:COMMA subscript)* (COMMA)? - ; - -subscript - : DOT DOT DOT - | test (COLON (test)? (sliceop)?)? - | COLON (test)? (sliceop)? - ; - -sliceop: COLON (test)? - ; - -exprlist - : expr (options {k=2;}:COMMA expr)* (COMMA)? - ; - -testlist - : test (options {k=2;}: COMMA test)* (COMMA)? - ; - -dictmaker - : test COLON test - (options {k=2;}:COMMA test COLON test)* (COMMA)? - ; - -classdef: 'class' NAME (LPAREN testlist RPAREN)? COLON suite - {System.out.println("found class def "+$NAME.text);} - ; - -arglist: argument (COMMA argument)* - ( COMMA - ( STAR test (COMMA DOUBLESTAR test)? - | DOUBLESTAR test - )? - )? - | STAR test (COMMA DOUBLESTAR test)? - | DOUBLESTAR test - ; - -argument : test (ASSIGN test)? - ; - -list_iter: list_for - | list_if - ; - -list_for: 'for' exprlist 'in' testlist (list_iter)? - ; - -list_if: 'if' test (list_iter)? - ; - -LPAREN : '(' {implicitLineJoiningLevel++;} ; - -RPAREN : ')' {implicitLineJoiningLevel--;} ; - -LBRACK : '[' {implicitLineJoiningLevel++;} ; - -RBRACK : ']' {implicitLineJoiningLevel--;} ; - -COLON : ':' ; - -COMMA : ',' ; - -SEMI : ';' ; - -PLUS : '+' ; - -MINUS : '-' ; - -STAR : '*' ; - -SLASH : '/' ; - -VBAR : '|' ; - -AMPER : '&' ; - -LESS : '<' ; - -GREATER : '>' ; - -ASSIGN : '=' ; - -PERCENT : '%' ; - -BACKQUOTE : '`' ; - -LCURLY : '{' {implicitLineJoiningLevel++;} ; - -RCURLY : '}' {implicitLineJoiningLevel--;} ; - -CIRCUMFLEX : '^' ; - -TILDE : '~' ; - -EQUAL : '==' ; - -NOTEQUAL : '!=' ; - -ALT_NOTEQUAL: '<>' ; - -LESSEQUAL : '<=' ; - -LEFTSHIFT : '<<' ; - -GREATEREQUAL : '>=' ; - -RIGHTSHIFT : '>>' ; - -PLUSEQUAL : '+=' ; - -MINUSEQUAL : '-=' ; - -DOUBLESTAR : '**' ; - -STAREQUAL : '*=' ; - -DOUBLESLASH : '//' ; - -SLASHEQUAL : '/=' ; - -VBAREQUAL : '|=' ; - -PERCENTEQUAL : '%=' ; - -AMPEREQUAL : '&=' ; - -CIRCUMFLEXEQUAL : '^=' ; - -LEFTSHIFTEQUAL : '<<=' ; - -RIGHTSHIFTEQUAL : '>>=' ; - -DOUBLESTAREQUAL : '**=' ; - -DOUBLESLASHEQUAL : '//=' ; - -DOT : '.' ; - -FLOAT - : '.' DIGITS (Exponent)? - | DIGITS ('.' (DIGITS (Exponent)?)? | Exponent) - ; - -LONGINT - : INT ('l'|'L') - ; - -fragment -Exponent - : ('e' | 'E') ( '+' | '-' )? DIGITS - ; - -INT : // Hex - '0' ('x' | 'X') ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' )+ - ('l' | 'L')? - | // Octal - '0' DIGITS* - | '1'..'9' DIGITS* - ; - -COMPLEX - : INT ('j'|'J') - | FLOAT ('j'|'J') - ; - -fragment -DIGITS : ( '0' .. '9' )+ ; - -NAME: ( 'a' .. 'z' | 'A' .. 'Z' | '_') - ( 'a' .. 'z' | 'A' .. 'Z' | '_' | '0' .. '9' )* - ; - -/** Match various string types. Note that greedy=false implies ''' - * should make us exit loop not continue. - */ -STRING - : ('r'|'u'|'ur')? - ( '\'\'\'' (options {greedy=false;}:.)* '\'\'\'' - | '"""' (options {greedy=false;}:.)* '"""' - | '"' (ESC|~('\\'|'\n'|'"'))* '"' - | '\'' (ESC|~('\\'|'\n'|'\''))* '\'' - ) - ; - -fragment -ESC - : '\\' . - ; - -/** Consume a newline and any whitespace at start of next line */ -CONTINUED_LINE - : '\\' ('\r')? '\n' (' '|'\t')* { $channel=HIDDEN; } - ; - -/** Treat a sequence of blank lines as a single blank line. If - * nested within a (..), {..}, or [..], then ignore newlines. - * If the first newline starts in column one, they are to be ignored. - */ -NEWLINE - : (('\r')? '\n' )+ - {if ( startPos==0 || implicitLineJoiningLevel>0 ) - $channel=HIDDEN; - } - ; - -WS : {startPos>0}?=> (' '|'\t')+ {$channel=HIDDEN;} - ; - -/** Grab everything before a real symbol. Then if newline, kill it - * as this is a blank line. If whitespace followed by comment, kill it - * as it's a comment on a line by itself. - * - * Ignore leading whitespace when nested in [..], (..), {..}. - */ -LEADING_WS -@init { - int spaces = 0; -} - : {startPos==0}?=> - ( {implicitLineJoiningLevel>0}? ( ' ' | '\t' )+ {$channel=HIDDEN;} - | ( ' ' { spaces++; } - | '\t' { spaces += 8; spaces -= (spaces \% 8); } - )+ - { - // make a string of n spaces where n is column number - 1 - char[] indentation = new char[spaces]; - for (int i=0; i (' '|'\t')* '#' (~'\n')* '\n'+ - | {startPos>0}?=> '#' (~'\n')* // let NEWLINE handle \n unless char pos==0 for '#' - ; \ No newline at end of file diff --git a/ethereumj-core/src/main/java/samples/antlr/Sample.g b/ethereumj-core/src/main/java/samples/antlr/Sample.g deleted file mode 100644 index 96fd5b69..00000000 --- a/ethereumj-core/src/main/java/samples/antlr/Sample.g +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Scott Stanchfield - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -grammar Sample; - -options { - language = Java; - output = AST; - output=template; -} - -@header { - package samples.antlr; -} - -@lexer::header { - package samples.antlr; -} - -program - : 'program' IDENT '=' - (constant | variable | function | procedure | typeDecl)* - 'begin' - statement* - 'end' IDENT '.' - ; - -constant - : 'constant' IDENT ':' type ':=' expression ';' - ; - -variable - : 'var' IDENT (',' IDENT)* ':' type (':=' expression)? ';' - ; - -type - : 'Integer' - | 'Boolean' - | 'String' - | 'Char' - | IDENT - | typeSpec - ; - -typeDecl - : 'type' IDENT '=' typeSpec ';' - ; - -typeSpec - : arrayType - | recordType - | enumType - ; - -arrayType - : 'array' '[' INTEGER '..' INTEGER ']' 'of' type - ; - -recordType - : 'record' field* 'end' 'record' - ; - -field - : IDENT ':' type ';' - ; - -enumType - : '<' IDENT (',' IDENT)* '>' - ; - -statement - : assignmentStatement - | ifStatement - | loopStatement - | whileStatement - | procedureCallStatement - ; - -procedureCallStatement - : IDENT '(' actualParameters? ')' ';' - ; - -actualParameters - : expression (',' expression)* - ; - -ifStatement - : 'if' expression 'then' statement+ - ('elsif' expression 'then' statement+)* - ('else' statement+)? - 'end' 'if' ';' - ; - -assignmentStatement - : IDENT ':=' expression ';' - ; - -exitStatement - : 'exit' 'when' expression ';' - ; - -whileStatement - : 'while' expression 'loop' - (statement|exitStatement)* - 'end' 'loop' ';' - ; - -loopStatement - : 'loop' (statement|exitStatement)* 'end' 'loop' ';' - ; - -returnStatement - : 'return' expression ';' - ; - -procedure - : 'procedure' IDENT '(' parameters? ')' '=' - (constant | variable)* - 'begin' - statement* - 'end' IDENT '.' - ; -function - : 'function' IDENT '(' parameters? ')' ':' type '=' - (constant | variable)* - 'begin' - (statement|returnStatement)* - 'end' IDENT '.' - ; - -parameters - : parameter (',' parameter)* - ; - -parameter - : 'var'? IDENT ':' type - ; - - -// expressions -- fun time! - -term - : IDENT - | '(' expression ')' - | INTEGER - | STRING_LITERAL - | CHAR_LITERAL - | IDENT '(' actualParameters ')' - ; - -negation - : 'not'* term - ; - -unary - : ('+' | '-')* negation - ; - -mult - : unary (('*' | '/' | 'mod') unary)* - ; - -add - : mult (('+' | '-') mult)* - ; - -relation - : add (('=' | '/=' | '<' | '<=' | '>=' | '>') add)* - ; - -expression - : relation (('and' | 'or') relation)* - ; - - -MULTILINE_COMMENT : '/*' .* '*/' {$channel = HIDDEN;} ; - -STRING_LITERAL - : '"' - { StringBuilder b = new StringBuilder(); } - ( '"' '"' { b.appendCodePoint('"');} - | c=~('"'|'\r'|'\n') { b.appendCodePoint(c);} - )* - '"' - { setText(b.toString()); } - ; - -CHAR_LITERAL - : '\'' . '\'' {setText(getText().substring(1,2));} - ; - -fragment LETTER : ('a'..'z' | 'A'..'Z') ; -fragment DIGIT : '0'..'9'; -INTEGER : DIGIT+ ; -IDENT : LETTER (LETTER | DIGIT)*; -WS : (' ' | '\t' | '\n' | '\r' | '\f')+ {$channel = HIDDEN;}; -COMMENT : '//' .* ('\n'|'\r') {$channel = HIDDEN;}; diff --git a/ethereumj-core/src/main/java/samples/antlr/Sample2Asm.stg b/ethereumj-core/src/main/java/samples/antlr/Sample2Asm.stg deleted file mode 100644 index 5a1728e3..00000000 --- a/ethereumj-core/src/main/java/samples/antlr/Sample2Asm.stg +++ /dev/null @@ -1,10 +0,0 @@ - -/** https://github.com/rollxx/antlr-php-runtime/blob/master/examples/cminus/Bytecode.stg */ - - - -variable(type,name) ::= ".var is <\n>" - -type_int() ::= "I" - -type_char() ::= "C" diff --git a/ethereumj-core/src/main/java/samples/antlr/SampleLexer.java b/ethereumj-core/src/main/java/samples/antlr/SampleLexer.java deleted file mode 100644 index c015d8c0..00000000 --- a/ethereumj-core/src/main/java/samples/antlr/SampleLexer.java +++ /dev/null @@ -1,2151 +0,0 @@ -// $ANTLR 3.5.2 E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g 2014-04-27 11:25:21 - - package samples.antlr; - - -import org.antlr.runtime.*; -import java.util.Stack; -import java.util.List; -import java.util.ArrayList; - -@SuppressWarnings("all") -public class SampleLexer extends Lexer { - public static final int EOF=-1; - public static final int T__13=13; - public static final int T__14=14; - public static final int T__15=15; - public static final int T__16=16; - public static final int T__17=17; - public static final int T__18=18; - public static final int T__19=19; - public static final int T__20=20; - public static final int T__21=21; - public static final int T__22=22; - public static final int T__23=23; - public static final int T__24=24; - public static final int T__25=25; - public static final int T__26=26; - public static final int T__27=27; - public static final int T__28=28; - public static final int T__29=29; - public static final int T__30=30; - public static final int T__31=31; - public static final int T__32=32; - public static final int T__33=33; - public static final int T__34=34; - public static final int T__35=35; - public static final int T__36=36; - public static final int T__37=37; - public static final int T__38=38; - public static final int T__39=39; - public static final int T__40=40; - public static final int T__41=41; - public static final int T__42=42; - public static final int T__43=43; - public static final int T__44=44; - public static final int T__45=45; - public static final int T__46=46; - public static final int T__47=47; - public static final int T__48=48; - public static final int T__49=49; - public static final int T__50=50; - public static final int T__51=51; - public static final int T__52=52; - public static final int T__53=53; - public static final int T__54=54; - public static final int T__55=55; - public static final int T__56=56; - public static final int T__57=57; - public static final int T__58=58; - public static final int T__59=59; - public static final int T__60=60; - public static final int CHAR_LITERAL=4; - public static final int COMMENT=5; - public static final int DIGIT=6; - public static final int IDENT=7; - public static final int INTEGER=8; - public static final int LETTER=9; - public static final int MULTILINE_COMMENT=10; - public static final int STRING_LITERAL=11; - public static final int WS=12; - - // delegates - // delegators - public Lexer[] getDelegates() { - return new Lexer[] {}; - } - - public SampleLexer() {} - public SampleLexer(CharStream input) { - this(input, new RecognizerSharedState()); - } - public SampleLexer(CharStream input, RecognizerSharedState state) { - super(input,state); - } - @Override public String getGrammarFileName() { return "E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g"; } - - // $ANTLR start "T__13" - public final void mT__13() throws RecognitionException { - try { - int _type = T__13; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:11:7: ( '(' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:11:9: '(' - { - match('('); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__13" - - // $ANTLR start "T__14" - public final void mT__14() throws RecognitionException { - try { - int _type = T__14; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:12:7: ( ')' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:12:9: ')' - { - match(')'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__14" - - // $ANTLR start "T__15" - public final void mT__15() throws RecognitionException { - try { - int _type = T__15; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:13:7: ( '*' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:13:9: '*' - { - match('*'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__15" - - // $ANTLR start "T__16" - public final void mT__16() throws RecognitionException { - try { - int _type = T__16; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:14:7: ( '+' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:14:9: '+' - { - match('+'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__16" - - // $ANTLR start "T__17" - public final void mT__17() throws RecognitionException { - try { - int _type = T__17; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:15:7: ( ',' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:15:9: ',' - { - match(','); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__17" - - // $ANTLR start "T__18" - public final void mT__18() throws RecognitionException { - try { - int _type = T__18; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:16:7: ( '-' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:16:9: '-' - { - match('-'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__18" - - // $ANTLR start "T__19" - public final void mT__19() throws RecognitionException { - try { - int _type = T__19; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:17:7: ( '.' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:17:9: '.' - { - match('.'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__19" - - // $ANTLR start "T__20" - public final void mT__20() throws RecognitionException { - try { - int _type = T__20; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:18:7: ( '..' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:18:9: '..' - { - match(".."); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__20" - - // $ANTLR start "T__21" - public final void mT__21() throws RecognitionException { - try { - int _type = T__21; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:19:7: ( '/' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:19:9: '/' - { - match('/'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__21" - - // $ANTLR start "T__22" - public final void mT__22() throws RecognitionException { - try { - int _type = T__22; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:20:7: ( '/=' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:20:9: '/=' - { - match("/="); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__22" - - // $ANTLR start "T__23" - public final void mT__23() throws RecognitionException { - try { - int _type = T__23; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:21:7: ( ':' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:21:9: ':' - { - match(':'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__23" - - // $ANTLR start "T__24" - public final void mT__24() throws RecognitionException { - try { - int _type = T__24; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:22:7: ( ':=' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:22:9: ':=' - { - match(":="); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__24" - - // $ANTLR start "T__25" - public final void mT__25() throws RecognitionException { - try { - int _type = T__25; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:23:7: ( ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:23:9: ';' - { - match(';'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__25" - - // $ANTLR start "T__26" - public final void mT__26() throws RecognitionException { - try { - int _type = T__26; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:24:7: ( '<' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:24:9: '<' - { - match('<'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__26" - - // $ANTLR start "T__27" - public final void mT__27() throws RecognitionException { - try { - int _type = T__27; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:25:7: ( '<=' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:25:9: '<=' - { - match("<="); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__27" - - // $ANTLR start "T__28" - public final void mT__28() throws RecognitionException { - try { - int _type = T__28; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:26:7: ( '=' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:26:9: '=' - { - match('='); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__28" - - // $ANTLR start "T__29" - public final void mT__29() throws RecognitionException { - try { - int _type = T__29; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:27:7: ( '>' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:27:9: '>' - { - match('>'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__29" - - // $ANTLR start "T__30" - public final void mT__30() throws RecognitionException { - try { - int _type = T__30; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:28:7: ( '>=' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:28:9: '>=' - { - match(">="); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__30" - - // $ANTLR start "T__31" - public final void mT__31() throws RecognitionException { - try { - int _type = T__31; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:29:7: ( 'Boolean' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:29:9: 'Boolean' - { - match("Boolean"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__31" - - // $ANTLR start "T__32" - public final void mT__32() throws RecognitionException { - try { - int _type = T__32; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:30:7: ( 'Char' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:30:9: 'Char' - { - match("Char"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__32" - - // $ANTLR start "T__33" - public final void mT__33() throws RecognitionException { - try { - int _type = T__33; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:31:7: ( 'Integer' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:31:9: 'Integer' - { - match("Integer"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__33" - - // $ANTLR start "T__34" - public final void mT__34() throws RecognitionException { - try { - int _type = T__34; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:32:7: ( 'String' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:32:9: 'String' - { - match("String"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__34" - - // $ANTLR start "T__35" - public final void mT__35() throws RecognitionException { - try { - int _type = T__35; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:33:7: ( '[' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:33:9: '[' - { - match('['); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__35" - - // $ANTLR start "T__36" - public final void mT__36() throws RecognitionException { - try { - int _type = T__36; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:34:7: ( ']' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:34:9: ']' - { - match(']'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__36" - - // $ANTLR start "T__37" - public final void mT__37() throws RecognitionException { - try { - int _type = T__37; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:35:7: ( 'and' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:35:9: 'and' - { - match("and"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__37" - - // $ANTLR start "T__38" - public final void mT__38() throws RecognitionException { - try { - int _type = T__38; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:36:7: ( 'array' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:36:9: 'array' - { - match("array"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__38" - - // $ANTLR start "T__39" - public final void mT__39() throws RecognitionException { - try { - int _type = T__39; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:37:7: ( 'begin' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:37:9: 'begin' - { - match("begin"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__39" - - // $ANTLR start "T__40" - public final void mT__40() throws RecognitionException { - try { - int _type = T__40; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:38:7: ( 'constant' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:38:9: 'constant' - { - match("constant"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__40" - - // $ANTLR start "T__41" - public final void mT__41() throws RecognitionException { - try { - int _type = T__41; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:39:7: ( 'else' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:39:9: 'else' - { - match("else"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__41" - - // $ANTLR start "T__42" - public final void mT__42() throws RecognitionException { - try { - int _type = T__42; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:40:7: ( 'elsif' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:40:9: 'elsif' - { - match("elsif"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__42" - - // $ANTLR start "T__43" - public final void mT__43() throws RecognitionException { - try { - int _type = T__43; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:41:7: ( 'end' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:41:9: 'end' - { - match("end"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__43" - - // $ANTLR start "T__44" - public final void mT__44() throws RecognitionException { - try { - int _type = T__44; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:42:7: ( 'exit' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:42:9: 'exit' - { - match("exit"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__44" - - // $ANTLR start "T__45" - public final void mT__45() throws RecognitionException { - try { - int _type = T__45; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:43:7: ( 'function' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:43:9: 'function' - { - match("function"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__45" - - // $ANTLR start "T__46" - public final void mT__46() throws RecognitionException { - try { - int _type = T__46; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:44:7: ( 'if' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:44:9: 'if' - { - match("if"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__46" - - // $ANTLR start "T__47" - public final void mT__47() throws RecognitionException { - try { - int _type = T__47; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:45:7: ( 'loop' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:45:9: 'loop' - { - match("loop"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__47" - - // $ANTLR start "T__48" - public final void mT__48() throws RecognitionException { - try { - int _type = T__48; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:46:7: ( 'mod' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:46:9: 'mod' - { - match("mod"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__48" - - // $ANTLR start "T__49" - public final void mT__49() throws RecognitionException { - try { - int _type = T__49; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:47:7: ( 'not' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:47:9: 'not' - { - match("not"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__49" - - // $ANTLR start "T__50" - public final void mT__50() throws RecognitionException { - try { - int _type = T__50; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:48:7: ( 'of' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:48:9: 'of' - { - match("of"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__50" - - // $ANTLR start "T__51" - public final void mT__51() throws RecognitionException { - try { - int _type = T__51; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:49:7: ( 'or' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:49:9: 'or' - { - match("or"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__51" - - // $ANTLR start "T__52" - public final void mT__52() throws RecognitionException { - try { - int _type = T__52; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:50:7: ( 'procedure' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:50:9: 'procedure' - { - match("procedure"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__52" - - // $ANTLR start "T__53" - public final void mT__53() throws RecognitionException { - try { - int _type = T__53; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:51:7: ( 'program' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:51:9: 'program' - { - match("program"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__53" - - // $ANTLR start "T__54" - public final void mT__54() throws RecognitionException { - try { - int _type = T__54; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:52:7: ( 'record' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:52:9: 'record' - { - match("record"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__54" - - // $ANTLR start "T__55" - public final void mT__55() throws RecognitionException { - try { - int _type = T__55; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:53:7: ( 'return' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:53:9: 'return' - { - match("return"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__55" - - // $ANTLR start "T__56" - public final void mT__56() throws RecognitionException { - try { - int _type = T__56; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:54:7: ( 'then' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:54:9: 'then' - { - match("then"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__56" - - // $ANTLR start "T__57" - public final void mT__57() throws RecognitionException { - try { - int _type = T__57; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:55:7: ( 'type' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:55:9: 'type' - { - match("type"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__57" - - // $ANTLR start "T__58" - public final void mT__58() throws RecognitionException { - try { - int _type = T__58; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:56:7: ( 'var' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:56:9: 'var' - { - match("var"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__58" - - // $ANTLR start "T__59" - public final void mT__59() throws RecognitionException { - try { - int _type = T__59; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:57:7: ( 'when' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:57:9: 'when' - { - match("when"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__59" - - // $ANTLR start "T__60" - public final void mT__60() throws RecognitionException { - try { - int _type = T__60; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:58:7: ( 'while' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:58:9: 'while' - { - match("while"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__60" - - // $ANTLR start "MULTILINE_COMMENT" - public final void mMULTILINE_COMMENT() throws RecognitionException { - try { - int _type = MULTILINE_COMMENT; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:180:19: ( '/*' ( . )* '*/' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:180:21: '/*' ( . )* '*/' - { - match("/*"); - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:180:26: ( . )* - loop1: - while (true) { - int alt1=2; - int LA1_0 = input.LA(1); - if ( (LA1_0=='*') ) { - int LA1_1 = input.LA(2); - if ( (LA1_1=='/') ) { - alt1=2; - } - else if ( ((LA1_1 >= '\u0000' && LA1_1 <= '.')||(LA1_1 >= '0' && LA1_1 <= '\uFFFF')) ) { - alt1=1; - } - - } - else if ( ((LA1_0 >= '\u0000' && LA1_0 <= ')')||(LA1_0 >= '+' && LA1_0 <= '\uFFFF')) ) { - alt1=1; - } - - switch (alt1) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:180:26: . - { - matchAny(); - } - break; - - default : - break loop1; - } - } - - match("*/"); - - _channel = HIDDEN; - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "MULTILINE_COMMENT" - - // $ANTLR start "STRING_LITERAL" - public final void mSTRING_LITERAL() throws RecognitionException { - try { - int _type = STRING_LITERAL; - int _channel = DEFAULT_TOKEN_CHANNEL; - int c; - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:183:2: ( '\"' ( '\"' '\"' |c=~ ( '\"' | '\\r' | '\\n' ) )* '\"' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:183:4: '\"' ( '\"' '\"' |c=~ ( '\"' | '\\r' | '\\n' ) )* '\"' - { - match('\"'); - StringBuilder b = new StringBuilder(); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:185:3: ( '\"' '\"' |c=~ ( '\"' | '\\r' | '\\n' ) )* - loop2: - while (true) { - int alt2=3; - int LA2_0 = input.LA(1); - if ( (LA2_0=='\"') ) { - int LA2_1 = input.LA(2); - if ( (LA2_1=='\"') ) { - alt2=1; - } - - } - else if ( ((LA2_0 >= '\u0000' && LA2_0 <= '\t')||(LA2_0 >= '\u000B' && LA2_0 <= '\f')||(LA2_0 >= '\u000E' && LA2_0 <= '!')||(LA2_0 >= '#' && LA2_0 <= '\uFFFF')) ) { - alt2=2; - } - - switch (alt2) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:185:5: '\"' '\"' - { - match('\"'); - match('\"'); - b.appendCodePoint('"'); - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:186:5: c=~ ( '\"' | '\\r' | '\\n' ) - { - c= input.LA(1); - if ( (input.LA(1) >= '\u0000' && input.LA(1) <= '\t')||(input.LA(1) >= '\u000B' && input.LA(1) <= '\f')||(input.LA(1) >= '\u000E' && input.LA(1) <= '!')||(input.LA(1) >= '#' && input.LA(1) <= '\uFFFF') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - b.appendCodePoint(c); - } - break; - - default : - break loop2; - } - } - - match('\"'); - setText(b.toString()); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "STRING_LITERAL" - - // $ANTLR start "CHAR_LITERAL" - public final void mCHAR_LITERAL() throws RecognitionException { - try { - int _type = CHAR_LITERAL; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:193:2: ( '\\'' . '\\'' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:193:4: '\\'' . '\\'' - { - match('\''); - matchAny(); - match('\''); - setText(getText().substring(1,2)); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "CHAR_LITERAL" - - // $ANTLR start "LETTER" - public final void mLETTER() throws RecognitionException { - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:196:17: ( ( 'a' .. 'z' | 'A' .. 'Z' ) ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g: - { - if ( (input.LA(1) >= 'A' && input.LA(1) <= 'Z')||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "LETTER" - - // $ANTLR start "DIGIT" - public final void mDIGIT() throws RecognitionException { - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:197:16: ( '0' .. '9' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g: - { - if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "DIGIT" - - // $ANTLR start "INTEGER" - public final void mINTEGER() throws RecognitionException { - try { - int _type = INTEGER; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:198:9: ( ( DIGIT )+ ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:198:11: ( DIGIT )+ - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:198:11: ( DIGIT )+ - int cnt3=0; - loop3: - while (true) { - int alt3=2; - int LA3_0 = input.LA(1); - if ( ((LA3_0 >= '0' && LA3_0 <= '9')) ) { - alt3=1; - } - - switch (alt3) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g: - { - if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - break; - - default : - if ( cnt3 >= 1 ) break loop3; - EarlyExitException eee = new EarlyExitException(3, input); - throw eee; - } - cnt3++; - } - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "INTEGER" - - // $ANTLR start "IDENT" - public final void mIDENT() throws RecognitionException { - try { - int _type = IDENT; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:199:7: ( LETTER ( LETTER | DIGIT )* ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:199:9: LETTER ( LETTER | DIGIT )* - { - mLETTER(); - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:199:16: ( LETTER | DIGIT )* - loop4: - while (true) { - int alt4=2; - int LA4_0 = input.LA(1); - if ( ((LA4_0 >= '0' && LA4_0 <= '9')||(LA4_0 >= 'A' && LA4_0 <= 'Z')||(LA4_0 >= 'a' && LA4_0 <= 'z')) ) { - alt4=1; - } - - switch (alt4) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g: - { - if ( (input.LA(1) >= '0' && input.LA(1) <= '9')||(input.LA(1) >= 'A' && input.LA(1) <= 'Z')||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - break; - - default : - break loop4; - } - } - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "IDENT" - - // $ANTLR start "WS" - public final void mWS() throws RecognitionException { - try { - int _type = WS; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:200:4: ( ( ' ' | '\\t' | '\\n' | '\\r' | '\\f' )+ ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:200:6: ( ' ' | '\\t' | '\\n' | '\\r' | '\\f' )+ - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:200:6: ( ' ' | '\\t' | '\\n' | '\\r' | '\\f' )+ - int cnt5=0; - loop5: - while (true) { - int alt5=2; - int LA5_0 = input.LA(1); - if ( ((LA5_0 >= '\t' && LA5_0 <= '\n')||(LA5_0 >= '\f' && LA5_0 <= '\r')||LA5_0==' ') ) { - alt5=1; - } - - switch (alt5) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g: - { - if ( (input.LA(1) >= '\t' && input.LA(1) <= '\n')||(input.LA(1) >= '\f' && input.LA(1) <= '\r')||input.LA(1)==' ' ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - break; - - default : - if ( cnt5 >= 1 ) break loop5; - EarlyExitException eee = new EarlyExitException(5, input); - throw eee; - } - cnt5++; - } - - _channel = HIDDEN; - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "WS" - - // $ANTLR start "COMMENT" - public final void mCOMMENT() throws RecognitionException { - try { - int _type = COMMENT; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:201:9: ( '//' ( . )* ( '\\n' | '\\r' ) ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:201:11: '//' ( . )* ( '\\n' | '\\r' ) - { - match("//"); - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:201:16: ( . )* - loop6: - while (true) { - int alt6=2; - int LA6_0 = input.LA(1); - if ( (LA6_0=='\n'||LA6_0=='\r') ) { - alt6=2; - } - else if ( ((LA6_0 >= '\u0000' && LA6_0 <= '\t')||(LA6_0 >= '\u000B' && LA6_0 <= '\f')||(LA6_0 >= '\u000E' && LA6_0 <= '\uFFFF')) ) { - alt6=1; - } - - switch (alt6) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:201:16: . - { - matchAny(); - } - break; - - default : - break loop6; - } - } - - if ( input.LA(1)=='\n'||input.LA(1)=='\r' ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - _channel = HIDDEN; - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "COMMENT" - - @Override - public void mTokens() throws RecognitionException { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:8: ( T__13 | T__14 | T__15 | T__16 | T__17 | T__18 | T__19 | T__20 | T__21 | T__22 | T__23 | T__24 | T__25 | T__26 | T__27 | T__28 | T__29 | T__30 | T__31 | T__32 | T__33 | T__34 | T__35 | T__36 | T__37 | T__38 | T__39 | T__40 | T__41 | T__42 | T__43 | T__44 | T__45 | T__46 | T__47 | T__48 | T__49 | T__50 | T__51 | T__52 | T__53 | T__54 | T__55 | T__56 | T__57 | T__58 | T__59 | T__60 | MULTILINE_COMMENT | STRING_LITERAL | CHAR_LITERAL | INTEGER | IDENT | WS | COMMENT ) - int alt7=55; - alt7 = dfa7.predict(input); - switch (alt7) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:10: T__13 - { - mT__13(); - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:16: T__14 - { - mT__14(); - - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:22: T__15 - { - mT__15(); - - } - break; - case 4 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:28: T__16 - { - mT__16(); - - } - break; - case 5 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:34: T__17 - { - mT__17(); - - } - break; - case 6 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:40: T__18 - { - mT__18(); - - } - break; - case 7 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:46: T__19 - { - mT__19(); - - } - break; - case 8 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:52: T__20 - { - mT__20(); - - } - break; - case 9 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:58: T__21 - { - mT__21(); - - } - break; - case 10 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:64: T__22 - { - mT__22(); - - } - break; - case 11 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:70: T__23 - { - mT__23(); - - } - break; - case 12 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:76: T__24 - { - mT__24(); - - } - break; - case 13 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:82: T__25 - { - mT__25(); - - } - break; - case 14 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:88: T__26 - { - mT__26(); - - } - break; - case 15 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:94: T__27 - { - mT__27(); - - } - break; - case 16 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:100: T__28 - { - mT__28(); - - } - break; - case 17 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:106: T__29 - { - mT__29(); - - } - break; - case 18 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:112: T__30 - { - mT__30(); - - } - break; - case 19 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:118: T__31 - { - mT__31(); - - } - break; - case 20 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:124: T__32 - { - mT__32(); - - } - break; - case 21 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:130: T__33 - { - mT__33(); - - } - break; - case 22 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:136: T__34 - { - mT__34(); - - } - break; - case 23 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:142: T__35 - { - mT__35(); - - } - break; - case 24 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:148: T__36 - { - mT__36(); - - } - break; - case 25 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:154: T__37 - { - mT__37(); - - } - break; - case 26 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:160: T__38 - { - mT__38(); - - } - break; - case 27 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:166: T__39 - { - mT__39(); - - } - break; - case 28 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:172: T__40 - { - mT__40(); - - } - break; - case 29 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:178: T__41 - { - mT__41(); - - } - break; - case 30 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:184: T__42 - { - mT__42(); - - } - break; - case 31 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:190: T__43 - { - mT__43(); - - } - break; - case 32 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:196: T__44 - { - mT__44(); - - } - break; - case 33 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:202: T__45 - { - mT__45(); - - } - break; - case 34 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:208: T__46 - { - mT__46(); - - } - break; - case 35 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:214: T__47 - { - mT__47(); - - } - break; - case 36 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:220: T__48 - { - mT__48(); - - } - break; - case 37 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:226: T__49 - { - mT__49(); - - } - break; - case 38 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:232: T__50 - { - mT__50(); - - } - break; - case 39 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:238: T__51 - { - mT__51(); - - } - break; - case 40 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:244: T__52 - { - mT__52(); - - } - break; - case 41 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:250: T__53 - { - mT__53(); - - } - break; - case 42 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:256: T__54 - { - mT__54(); - - } - break; - case 43 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:262: T__55 - { - mT__55(); - - } - break; - case 44 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:268: T__56 - { - mT__56(); - - } - break; - case 45 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:274: T__57 - { - mT__57(); - - } - break; - case 46 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:280: T__58 - { - mT__58(); - - } - break; - case 47 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:286: T__59 - { - mT__59(); - - } - break; - case 48 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:292: T__60 - { - mT__60(); - - } - break; - case 49 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:298: MULTILINE_COMMENT - { - mMULTILINE_COMMENT(); - - } - break; - case 50 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:316: STRING_LITERAL - { - mSTRING_LITERAL(); - - } - break; - case 51 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:331: CHAR_LITERAL - { - mCHAR_LITERAL(); - - } - break; - case 52 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:344: INTEGER - { - mINTEGER(); - - } - break; - case 53 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:352: IDENT - { - mIDENT(); - - } - break; - case 54 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:358: WS - { - mWS(); - - } - break; - case 55 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:1:361: COMMENT - { - mCOMMENT(); - - } - break; - - } - } - - - protected DFA7 dfa7 = new DFA7(this); - static final String DFA7_eotS = - "\7\uffff\1\51\1\55\1\57\1\uffff\1\61\1\uffff\1\63\4\46\2\uffff\17\46\21"+ - "\uffff\14\46\1\130\3\46\1\134\1\135\12\46\1\152\4\46\1\160\2\46\1\uffff"+ - "\1\46\1\164\1\165\2\uffff\5\46\1\174\3\46\1\u0080\2\46\1\uffff\3\46\1"+ - "\u0086\1\46\1\uffff\1\u0088\1\46\1\u008a\2\uffff\4\46\1\u008f\1\u0090"+ - "\1\uffff\1\u0091\2\46\1\uffff\2\46\1\u0096\1\u0097\1\46\1\uffff\1\u0099"+ - "\1\uffff\1\46\1\uffff\4\46\3\uffff\1\u009f\2\46\1\u00a2\2\uffff\1\46\1"+ - "\uffff\3\46\1\u00a7\1\u00a8\1\uffff\1\u00a9\1\u00aa\1\uffff\3\46\1\u00ae"+ - "\4\uffff\1\u00af\1\u00b0\1\46\3\uffff\1\u00b2\1\uffff"; - static final String DFA7_eofS = - "\u00b3\uffff"; - static final String DFA7_minS = - "\1\11\6\uffff\1\56\1\52\1\75\1\uffff\1\75\1\uffff\1\75\1\157\1\150\1\156"+ - "\1\164\2\uffff\1\156\1\145\1\157\1\154\1\165\1\146\3\157\1\146\1\162\1"+ - "\145\1\150\1\141\1\150\21\uffff\1\157\1\141\1\164\1\162\1\144\1\162\1"+ - "\147\1\156\1\163\1\144\1\151\1\156\1\60\1\157\1\144\1\164\2\60\1\157\1"+ - "\143\1\145\1\160\1\162\1\145\1\154\1\162\1\145\1\151\1\60\1\141\1\151"+ - "\1\163\1\145\1\60\1\164\1\143\1\uffff\1\160\2\60\2\uffff\1\143\1\157\1"+ - "\165\1\156\1\145\1\60\1\156\1\154\1\145\1\60\1\147\1\156\1\uffff\1\171"+ - "\1\156\1\164\1\60\1\146\1\uffff\1\60\1\164\1\60\2\uffff\1\145\3\162\2"+ - "\60\1\uffff\1\60\1\145\1\141\1\uffff\1\145\1\147\2\60\1\141\1\uffff\1"+ - "\60\1\uffff\1\151\1\uffff\1\144\1\141\1\144\1\156\3\uffff\1\60\1\156\1"+ - "\162\1\60\2\uffff\1\156\1\uffff\1\157\1\165\1\155\2\60\1\uffff\2\60\1"+ - "\uffff\1\164\1\156\1\162\1\60\4\uffff\2\60\1\145\3\uffff\1\60\1\uffff"; - static final String DFA7_maxS = - "\1\172\6\uffff\1\56\2\75\1\uffff\1\75\1\uffff\1\75\1\157\1\150\1\156\1"+ - "\164\2\uffff\1\162\1\145\1\157\1\170\1\165\1\146\3\157\2\162\1\145\1\171"+ - "\1\141\1\150\21\uffff\1\157\1\141\1\164\1\162\1\144\1\162\1\147\1\156"+ - "\1\163\1\144\1\151\1\156\1\172\1\157\1\144\1\164\2\172\1\157\1\164\1\145"+ - "\1\160\1\162\1\151\1\154\1\162\1\145\1\151\1\172\1\141\1\151\1\163\1\151"+ - "\1\172\1\164\1\143\1\uffff\1\160\2\172\2\uffff\1\147\1\157\1\165\1\156"+ - "\1\145\1\172\1\156\1\154\1\145\1\172\1\147\1\156\1\uffff\1\171\1\156\1"+ - "\164\1\172\1\146\1\uffff\1\172\1\164\1\172\2\uffff\1\145\3\162\2\172\1"+ - "\uffff\1\172\1\145\1\141\1\uffff\1\145\1\147\2\172\1\141\1\uffff\1\172"+ - "\1\uffff\1\151\1\uffff\1\144\1\141\1\144\1\156\3\uffff\1\172\1\156\1\162"+ - "\1\172\2\uffff\1\156\1\uffff\1\157\1\165\1\155\2\172\1\uffff\2\172\1\uffff"+ - "\1\164\1\156\1\162\1\172\4\uffff\2\172\1\145\3\uffff\1\172\1\uffff"; - static final String DFA7_acceptS = - "\1\uffff\1\1\1\2\1\3\1\4\1\5\1\6\3\uffff\1\15\1\uffff\1\20\5\uffff\1\27"+ - "\1\30\17\uffff\1\62\1\63\1\64\1\65\1\66\1\10\1\7\1\12\1\61\1\67\1\11\1"+ - "\14\1\13\1\17\1\16\1\22\1\21\44\uffff\1\42\3\uffff\1\46\1\47\14\uffff"+ - "\1\31\5\uffff\1\37\3\uffff\1\44\1\45\6\uffff\1\56\3\uffff\1\24\5\uffff"+ - "\1\35\1\uffff\1\40\1\uffff\1\43\4\uffff\1\54\1\55\1\57\4\uffff\1\32\1"+ - "\33\1\uffff\1\36\5\uffff\1\60\2\uffff\1\26\4\uffff\1\52\1\53\1\23\1\25"+ - "\3\uffff\1\51\1\34\1\41\1\uffff\1\50"; - static final String DFA7_specialS = - "\u00b3\uffff}>"; - static final String[] DFA7_transitionS = { - "\2\47\1\uffff\2\47\22\uffff\1\47\1\uffff\1\43\4\uffff\1\44\1\1\1\2\1"+ - "\3\1\4\1\5\1\6\1\7\1\10\12\45\1\11\1\12\1\13\1\14\1\15\2\uffff\1\46\1"+ - "\16\1\17\5\46\1\20\11\46\1\21\7\46\1\22\1\uffff\1\23\3\uffff\1\24\1\25"+ - "\1\26\1\46\1\27\1\30\2\46\1\31\2\46\1\32\1\33\1\34\1\35\1\36\1\46\1\37"+ - "\1\46\1\40\1\46\1\41\1\42\3\46", - "", - "", - "", - "", - "", - "", - "\1\50", - "\1\53\4\uffff\1\54\15\uffff\1\52", - "\1\56", - "", - "\1\60", - "", - "\1\62", - "\1\64", - "\1\65", - "\1\66", - "\1\67", - "", - "", - "\1\70\3\uffff\1\71", - "\1\72", - "\1\73", - "\1\74\1\uffff\1\75\11\uffff\1\76", - "\1\77", - "\1\100", - "\1\101", - "\1\102", - "\1\103", - "\1\104\13\uffff\1\105", - "\1\106", - "\1\107", - "\1\110\20\uffff\1\111", - "\1\112", - "\1\113", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "\1\114", - "\1\115", - "\1\116", - "\1\117", - "\1\120", - "\1\121", - "\1\122", - "\1\123", - "\1\124", - "\1\125", - "\1\126", - "\1\127", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\131", - "\1\132", - "\1\133", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\136", - "\1\137\20\uffff\1\140", - "\1\141", - "\1\142", - "\1\143", - "\1\144\3\uffff\1\145", - "\1\146", - "\1\147", - "\1\150", - "\1\151", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\153", - "\1\154", - "\1\155", - "\1\156\3\uffff\1\157", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\161", - "\1\162", - "", - "\1\163", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "", - "", - "\1\166\3\uffff\1\167", - "\1\170", - "\1\171", - "\1\172", - "\1\173", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\175", - "\1\176", - "\1\177", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\u0081", - "\1\u0082", - "", - "\1\u0083", - "\1\u0084", - "\1\u0085", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\u0087", - "", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\u0089", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "", - "", - "\1\u008b", - "\1\u008c", - "\1\u008d", - "\1\u008e", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\u0092", - "\1\u0093", - "", - "\1\u0094", - "\1\u0095", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\u0098", - "", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "", - "\1\u009a", - "", - "\1\u009b", - "\1\u009c", - "\1\u009d", - "\1\u009e", - "", - "", - "", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\u00a0", - "\1\u00a1", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "", - "", - "\1\u00a3", - "", - "\1\u00a4", - "\1\u00a5", - "\1\u00a6", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "", - "\1\u00ab", - "\1\u00ac", - "\1\u00ad", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "", - "", - "", - "", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "\1\u00b1", - "", - "", - "", - "\12\46\7\uffff\32\46\6\uffff\32\46", - "" - }; - - static final short[] DFA7_eot = DFA.unpackEncodedString(DFA7_eotS); - static final short[] DFA7_eof = DFA.unpackEncodedString(DFA7_eofS); - static final char[] DFA7_min = DFA.unpackEncodedStringToUnsignedChars(DFA7_minS); - static final char[] DFA7_max = DFA.unpackEncodedStringToUnsignedChars(DFA7_maxS); - static final short[] DFA7_accept = DFA.unpackEncodedString(DFA7_acceptS); - static final short[] DFA7_special = DFA.unpackEncodedString(DFA7_specialS); - static final short[][] DFA7_transition; - - static { - int numStates = DFA7_transitionS.length; - DFA7_transition = new short[numStates][]; - for (int i=0; i", "", "", "", "CHAR_LITERAL", "COMMENT", "DIGIT", - "IDENT", "INTEGER", "LETTER", "MULTILINE_COMMENT", "STRING_LITERAL", "WS", - "'('", "')'", "'*'", "'+'", "','", "'-'", "'.'", "'..'", "'/'", "'/='", - "':'", "':='", "';'", "'<'", "'<='", "'='", "'>'", "'>='", "'Boolean'", - "'Char'", "'Integer'", "'String'", "'['", "']'", "'and'", "'array'", "'begin'", - "'constant'", "'else'", "'elsif'", "'end'", "'exit'", "'function'", "'if'", - "'loop'", "'mod'", "'not'", "'of'", "'or'", "'procedure'", "'program'", - "'record'", "'return'", "'then'", "'type'", "'var'", "'when'", "'while'" - }; - public static final int EOF=-1; - public static final int T__13=13; - public static final int T__14=14; - public static final int T__15=15; - public static final int T__16=16; - public static final int T__17=17; - public static final int T__18=18; - public static final int T__19=19; - public static final int T__20=20; - public static final int T__21=21; - public static final int T__22=22; - public static final int T__23=23; - public static final int T__24=24; - public static final int T__25=25; - public static final int T__26=26; - public static final int T__27=27; - public static final int T__28=28; - public static final int T__29=29; - public static final int T__30=30; - public static final int T__31=31; - public static final int T__32=32; - public static final int T__33=33; - public static final int T__34=34; - public static final int T__35=35; - public static final int T__36=36; - public static final int T__37=37; - public static final int T__38=38; - public static final int T__39=39; - public static final int T__40=40; - public static final int T__41=41; - public static final int T__42=42; - public static final int T__43=43; - public static final int T__44=44; - public static final int T__45=45; - public static final int T__46=46; - public static final int T__47=47; - public static final int T__48=48; - public static final int T__49=49; - public static final int T__50=50; - public static final int T__51=51; - public static final int T__52=52; - public static final int T__53=53; - public static final int T__54=54; - public static final int T__55=55; - public static final int T__56=56; - public static final int T__57=57; - public static final int T__58=58; - public static final int T__59=59; - public static final int T__60=60; - public static final int CHAR_LITERAL=4; - public static final int COMMENT=5; - public static final int DIGIT=6; - public static final int IDENT=7; - public static final int INTEGER=8; - public static final int LETTER=9; - public static final int MULTILINE_COMMENT=10; - public static final int STRING_LITERAL=11; - public static final int WS=12; - - // delegates - public Parser[] getDelegates() { - return new Parser[] {}; - } - - // delegators - - - public SampleParser(TokenStream input) { - this(input, new RecognizerSharedState()); - } - public SampleParser(TokenStream input, RecognizerSharedState state) { - super(input, state); - } - - protected StringTemplateGroup templateLib = - new StringTemplateGroup("SampleParserTemplates", AngleBracketTemplateLexer.class); - - public void setTemplateLib(StringTemplateGroup templateLib) { - this.templateLib = templateLib; - } - public StringTemplateGroup getTemplateLib() { - return templateLib; - } - /** allows convenient multi-value initialization: - * "new STAttrMap().put(...).put(...)" - */ - @SuppressWarnings("serial") - public static class STAttrMap extends HashMap { - public STAttrMap put(String attrName, Object value) { - super.put(attrName, value); - return this; - } - } - @Override public String[] getTokenNames() { return SampleParser.tokenNames; } - @Override public String getGrammarFileName() { return "E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g"; } - - - public static class program_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "program" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:24:1: program : 'program' IDENT '=' ( constant | variable | function | procedure | typeDecl )* 'begin' ( statement )* 'end' IDENT '.' ; - public final program_return program() throws RecognitionException { - program_return retval = new program_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:25:2: ( 'program' IDENT '=' ( constant | variable | function | procedure | typeDecl )* 'begin' ( statement )* 'end' IDENT '.' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:25:4: 'program' IDENT '=' ( constant | variable | function | procedure | typeDecl )* 'begin' ( statement )* 'end' IDENT '.' - { - match(input,53,FOLLOW_53_in_program58); - match(input,IDENT,FOLLOW_IDENT_in_program60); - match(input,28,FOLLOW_28_in_program62); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:26:3: ( constant | variable | function | procedure | typeDecl )* - loop1: - while (true) { - int alt1=6; - switch ( input.LA(1) ) { - case 40: - { - alt1=1; - } - break; - case 58: - { - alt1=2; - } - break; - case 45: - { - alt1=3; - } - break; - case 52: - { - alt1=4; - } - break; - case 57: - { - alt1=5; - } - break; - } - switch (alt1) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:26:4: constant - { - pushFollow(FOLLOW_constant_in_program67); - constant(); - state._fsp--; - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:26:15: variable - { - pushFollow(FOLLOW_variable_in_program71); - variable(); - state._fsp--; - - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:26:26: function - { - pushFollow(FOLLOW_function_in_program75); - function(); - state._fsp--; - - } - break; - case 4 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:26:37: procedure - { - pushFollow(FOLLOW_procedure_in_program79); - procedure(); - state._fsp--; - - } - break; - case 5 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:26:49: typeDecl - { - pushFollow(FOLLOW_typeDecl_in_program83); - typeDecl(); - state._fsp--; - - } - break; - - default : - break loop1; - } - } - - match(input,39,FOLLOW_39_in_program89); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:28:3: ( statement )* - loop2: - while (true) { - int alt2=2; - int LA2_0 = input.LA(1); - if ( (LA2_0==IDENT||(LA2_0 >= 46 && LA2_0 <= 47)||LA2_0==60) ) { - alt2=1; - } - - switch (alt2) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:28:3: statement - { - pushFollow(FOLLOW_statement_in_program93); - statement(); - state._fsp--; - - } - break; - - default : - break loop2; - } - } - - match(input,43,FOLLOW_43_in_program98); - match(input,IDENT,FOLLOW_IDENT_in_program100); - match(input,19,FOLLOW_19_in_program102); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "program" - - - public static class constant_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "constant" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:32:1: constant : 'constant' IDENT ':' type ':=' expression ';' ; - public final constant_return constant() throws RecognitionException { - constant_return retval = new constant_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:33:2: ( 'constant' IDENT ':' type ':=' expression ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:33:4: 'constant' IDENT ':' type ':=' expression ';' - { - match(input,40,FOLLOW_40_in_constant113); - match(input,IDENT,FOLLOW_IDENT_in_constant115); - match(input,23,FOLLOW_23_in_constant117); - pushFollow(FOLLOW_type_in_constant119); - type(); - state._fsp--; - - match(input,24,FOLLOW_24_in_constant121); - pushFollow(FOLLOW_expression_in_constant123); - expression(); - state._fsp--; - - match(input,25,FOLLOW_25_in_constant125); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "constant" - - - public static class variable_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "variable" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:36:1: variable : 'var' IDENT ( ',' IDENT )* ':' type ( ':=' expression )? ';' ; - public final variable_return variable() throws RecognitionException { - variable_return retval = new variable_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:37:2: ( 'var' IDENT ( ',' IDENT )* ':' type ( ':=' expression )? ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:37:4: 'var' IDENT ( ',' IDENT )* ':' type ( ':=' expression )? ';' - { - match(input,58,FOLLOW_58_in_variable136); - match(input,IDENT,FOLLOW_IDENT_in_variable138); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:37:16: ( ',' IDENT )* - loop3: - while (true) { - int alt3=2; - int LA3_0 = input.LA(1); - if ( (LA3_0==17) ) { - alt3=1; - } - - switch (alt3) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:37:17: ',' IDENT - { - match(input,17,FOLLOW_17_in_variable141); - match(input,IDENT,FOLLOW_IDENT_in_variable143); - } - break; - - default : - break loop3; - } - } - - match(input,23,FOLLOW_23_in_variable147); - pushFollow(FOLLOW_type_in_variable149); - type(); - state._fsp--; - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:37:38: ( ':=' expression )? - int alt4=2; - int LA4_0 = input.LA(1); - if ( (LA4_0==24) ) { - alt4=1; - } - switch (alt4) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:37:39: ':=' expression - { - match(input,24,FOLLOW_24_in_variable152); - pushFollow(FOLLOW_expression_in_variable154); - expression(); - state._fsp--; - - } - break; - - } - - match(input,25,FOLLOW_25_in_variable158); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "variable" - - - public static class type_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "type" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:40:1: type : ( 'Integer' | 'Boolean' | 'String' | 'Char' | IDENT | typeSpec ); - public final type_return type() throws RecognitionException { - type_return retval = new type_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:41:2: ( 'Integer' | 'Boolean' | 'String' | 'Char' | IDENT | typeSpec ) - int alt5=6; - switch ( input.LA(1) ) { - case 33: - { - alt5=1; - } - break; - case 31: - { - alt5=2; - } - break; - case 34: - { - alt5=3; - } - break; - case 32: - { - alt5=4; - } - break; - case IDENT: - { - alt5=5; - } - break; - case 26: - case 38: - case 54: - { - alt5=6; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 5, 0, input); - throw nvae; - } - switch (alt5) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:41:4: 'Integer' - { - match(input,33,FOLLOW_33_in_type169); - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:42:4: 'Boolean' - { - match(input,31,FOLLOW_31_in_type174); - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:43:4: 'String' - { - match(input,34,FOLLOW_34_in_type179); - } - break; - case 4 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:44:4: 'Char' - { - match(input,32,FOLLOW_32_in_type184); - } - break; - case 5 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:45:4: IDENT - { - match(input,IDENT,FOLLOW_IDENT_in_type189); - } - break; - case 6 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:46:4: typeSpec - { - pushFollow(FOLLOW_typeSpec_in_type194); - typeSpec(); - state._fsp--; - - } - break; - - } - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "type" - - - public static class typeDecl_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "typeDecl" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:49:1: typeDecl : 'type' IDENT '=' typeSpec ';' ; - public final typeDecl_return typeDecl() throws RecognitionException { - typeDecl_return retval = new typeDecl_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:50:2: ( 'type' IDENT '=' typeSpec ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:50:4: 'type' IDENT '=' typeSpec ';' - { - match(input,57,FOLLOW_57_in_typeDecl205); - match(input,IDENT,FOLLOW_IDENT_in_typeDecl207); - match(input,28,FOLLOW_28_in_typeDecl209); - pushFollow(FOLLOW_typeSpec_in_typeDecl211); - typeSpec(); - state._fsp--; - - match(input,25,FOLLOW_25_in_typeDecl213); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "typeDecl" - - - public static class typeSpec_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "typeSpec" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:53:1: typeSpec : ( arrayType | recordType | enumType ); - public final typeSpec_return typeSpec() throws RecognitionException { - typeSpec_return retval = new typeSpec_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:54:2: ( arrayType | recordType | enumType ) - int alt6=3; - switch ( input.LA(1) ) { - case 38: - { - alt6=1; - } - break; - case 54: - { - alt6=2; - } - break; - case 26: - { - alt6=3; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 6, 0, input); - throw nvae; - } - switch (alt6) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:54:4: arrayType - { - pushFollow(FOLLOW_arrayType_in_typeSpec224); - arrayType(); - state._fsp--; - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:55:4: recordType - { - pushFollow(FOLLOW_recordType_in_typeSpec229); - recordType(); - state._fsp--; - - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:56:4: enumType - { - pushFollow(FOLLOW_enumType_in_typeSpec234); - enumType(); - state._fsp--; - - } - break; - - } - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "typeSpec" - - - public static class arrayType_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "arrayType" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:59:1: arrayType : 'array' '[' INTEGER '..' INTEGER ']' 'of' type ; - public final arrayType_return arrayType() throws RecognitionException { - arrayType_return retval = new arrayType_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:60:2: ( 'array' '[' INTEGER '..' INTEGER ']' 'of' type ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:60:4: 'array' '[' INTEGER '..' INTEGER ']' 'of' type - { - match(input,38,FOLLOW_38_in_arrayType245); - match(input,35,FOLLOW_35_in_arrayType247); - match(input,INTEGER,FOLLOW_INTEGER_in_arrayType249); - match(input,20,FOLLOW_20_in_arrayType251); - match(input,INTEGER,FOLLOW_INTEGER_in_arrayType253); - match(input,36,FOLLOW_36_in_arrayType255); - match(input,50,FOLLOW_50_in_arrayType257); - pushFollow(FOLLOW_type_in_arrayType259); - type(); - state._fsp--; - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "arrayType" - - - public static class recordType_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "recordType" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:63:1: recordType : 'record' ( field )* 'end' 'record' ; - public final recordType_return recordType() throws RecognitionException { - recordType_return retval = new recordType_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:64:2: ( 'record' ( field )* 'end' 'record' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:64:4: 'record' ( field )* 'end' 'record' - { - match(input,54,FOLLOW_54_in_recordType270); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:64:13: ( field )* - loop7: - while (true) { - int alt7=2; - int LA7_0 = input.LA(1); - if ( (LA7_0==IDENT) ) { - alt7=1; - } - - switch (alt7) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:64:13: field - { - pushFollow(FOLLOW_field_in_recordType272); - field(); - state._fsp--; - - } - break; - - default : - break loop7; - } - } - - match(input,43,FOLLOW_43_in_recordType275); - match(input,54,FOLLOW_54_in_recordType277); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "recordType" - - - public static class field_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "field" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:67:1: field : IDENT ':' type ';' ; - public final field_return field() throws RecognitionException { - field_return retval = new field_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:68:2: ( IDENT ':' type ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:68:4: IDENT ':' type ';' - { - match(input,IDENT,FOLLOW_IDENT_in_field288); - match(input,23,FOLLOW_23_in_field290); - pushFollow(FOLLOW_type_in_field292); - type(); - state._fsp--; - - match(input,25,FOLLOW_25_in_field294); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "field" - - - public static class enumType_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "enumType" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:71:1: enumType : '<' IDENT ( ',' IDENT )* '>' ; - public final enumType_return enumType() throws RecognitionException { - enumType_return retval = new enumType_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:72:2: ( '<' IDENT ( ',' IDENT )* '>' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:72:4: '<' IDENT ( ',' IDENT )* '>' - { - match(input,26,FOLLOW_26_in_enumType305); - match(input,IDENT,FOLLOW_IDENT_in_enumType307); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:72:14: ( ',' IDENT )* - loop8: - while (true) { - int alt8=2; - int LA8_0 = input.LA(1); - if ( (LA8_0==17) ) { - alt8=1; - } - - switch (alt8) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:72:15: ',' IDENT - { - match(input,17,FOLLOW_17_in_enumType310); - match(input,IDENT,FOLLOW_IDENT_in_enumType312); - } - break; - - default : - break loop8; - } - } - - match(input,29,FOLLOW_29_in_enumType316); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "enumType" - - - public static class statement_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "statement" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:75:1: statement : ( assignmentStatement | ifStatement | loopStatement | whileStatement | procedureCallStatement ); - public final statement_return statement() throws RecognitionException { - statement_return retval = new statement_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:76:2: ( assignmentStatement | ifStatement | loopStatement | whileStatement | procedureCallStatement ) - int alt9=5; - switch ( input.LA(1) ) { - case IDENT: - { - int LA9_1 = input.LA(2); - if ( (LA9_1==24) ) { - alt9=1; - } - else if ( (LA9_1==13) ) { - alt9=5; - } - - else { - int nvaeMark = input.mark(); - try { - input.consume(); - NoViableAltException nvae = - new NoViableAltException("", 9, 1, input); - throw nvae; - } finally { - input.rewind(nvaeMark); - } - } - - } - break; - case 46: - { - alt9=2; - } - break; - case 47: - { - alt9=3; - } - break; - case 60: - { - alt9=4; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 9, 0, input); - throw nvae; - } - switch (alt9) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:76:4: assignmentStatement - { - pushFollow(FOLLOW_assignmentStatement_in_statement327); - assignmentStatement(); - state._fsp--; - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:77:4: ifStatement - { - pushFollow(FOLLOW_ifStatement_in_statement332); - ifStatement(); - state._fsp--; - - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:78:4: loopStatement - { - pushFollow(FOLLOW_loopStatement_in_statement337); - loopStatement(); - state._fsp--; - - } - break; - case 4 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:79:4: whileStatement - { - pushFollow(FOLLOW_whileStatement_in_statement342); - whileStatement(); - state._fsp--; - - } - break; - case 5 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:80:4: procedureCallStatement - { - pushFollow(FOLLOW_procedureCallStatement_in_statement347); - procedureCallStatement(); - state._fsp--; - - } - break; - - } - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "statement" - - - public static class procedureCallStatement_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "procedureCallStatement" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:83:1: procedureCallStatement : IDENT '(' ( actualParameters )? ')' ';' ; - public final procedureCallStatement_return procedureCallStatement() throws RecognitionException { - procedureCallStatement_return retval = new procedureCallStatement_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:84:2: ( IDENT '(' ( actualParameters )? ')' ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:84:4: IDENT '(' ( actualParameters )? ')' ';' - { - match(input,IDENT,FOLLOW_IDENT_in_procedureCallStatement358); - match(input,13,FOLLOW_13_in_procedureCallStatement360); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:84:14: ( actualParameters )? - int alt10=2; - int LA10_0 = input.LA(1); - if ( (LA10_0==CHAR_LITERAL||(LA10_0 >= IDENT && LA10_0 <= INTEGER)||LA10_0==STRING_LITERAL||LA10_0==13||LA10_0==16||LA10_0==18||LA10_0==49) ) { - alt10=1; - } - switch (alt10) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:84:14: actualParameters - { - pushFollow(FOLLOW_actualParameters_in_procedureCallStatement362); - actualParameters(); - state._fsp--; - - } - break; - - } - - match(input,14,FOLLOW_14_in_procedureCallStatement365); - match(input,25,FOLLOW_25_in_procedureCallStatement367); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "procedureCallStatement" - - - public static class actualParameters_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "actualParameters" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:87:1: actualParameters : expression ( ',' expression )* ; - public final actualParameters_return actualParameters() throws RecognitionException { - actualParameters_return retval = new actualParameters_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:88:2: ( expression ( ',' expression )* ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:88:4: expression ( ',' expression )* - { - pushFollow(FOLLOW_expression_in_actualParameters378); - expression(); - state._fsp--; - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:88:15: ( ',' expression )* - loop11: - while (true) { - int alt11=2; - int LA11_0 = input.LA(1); - if ( (LA11_0==17) ) { - alt11=1; - } - - switch (alt11) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:88:16: ',' expression - { - match(input,17,FOLLOW_17_in_actualParameters381); - pushFollow(FOLLOW_expression_in_actualParameters383); - expression(); - state._fsp--; - - } - break; - - default : - break loop11; - } - } - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "actualParameters" - - - public static class ifStatement_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "ifStatement" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:91:1: ifStatement : 'if' expression 'then' ( statement )+ ( 'elsif' expression 'then' ( statement )+ )* ( 'else' ( statement )+ )? 'end' 'if' ';' ; - public final ifStatement_return ifStatement() throws RecognitionException { - ifStatement_return retval = new ifStatement_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:92:2: ( 'if' expression 'then' ( statement )+ ( 'elsif' expression 'then' ( statement )+ )* ( 'else' ( statement )+ )? 'end' 'if' ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:92:4: 'if' expression 'then' ( statement )+ ( 'elsif' expression 'then' ( statement )+ )* ( 'else' ( statement )+ )? 'end' 'if' ';' - { - match(input,46,FOLLOW_46_in_ifStatement396); - pushFollow(FOLLOW_expression_in_ifStatement398); - expression(); - state._fsp--; - - match(input,56,FOLLOW_56_in_ifStatement400); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:92:27: ( statement )+ - int cnt12=0; - loop12: - while (true) { - int alt12=2; - int LA12_0 = input.LA(1); - if ( (LA12_0==IDENT||(LA12_0 >= 46 && LA12_0 <= 47)||LA12_0==60) ) { - alt12=1; - } - - switch (alt12) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:92:27: statement - { - pushFollow(FOLLOW_statement_in_ifStatement402); - statement(); - state._fsp--; - - } - break; - - default : - if ( cnt12 >= 1 ) break loop12; - EarlyExitException eee = new EarlyExitException(12, input); - throw eee; - } - cnt12++; - } - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:93:3: ( 'elsif' expression 'then' ( statement )+ )* - loop14: - while (true) { - int alt14=2; - int LA14_0 = input.LA(1); - if ( (LA14_0==42) ) { - alt14=1; - } - - switch (alt14) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:93:4: 'elsif' expression 'then' ( statement )+ - { - match(input,42,FOLLOW_42_in_ifStatement408); - pushFollow(FOLLOW_expression_in_ifStatement410); - expression(); - state._fsp--; - - match(input,56,FOLLOW_56_in_ifStatement412); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:93:30: ( statement )+ - int cnt13=0; - loop13: - while (true) { - int alt13=2; - int LA13_0 = input.LA(1); - if ( (LA13_0==IDENT||(LA13_0 >= 46 && LA13_0 <= 47)||LA13_0==60) ) { - alt13=1; - } - - switch (alt13) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:93:30: statement - { - pushFollow(FOLLOW_statement_in_ifStatement414); - statement(); - state._fsp--; - - } - break; - - default : - if ( cnt13 >= 1 ) break loop13; - EarlyExitException eee = new EarlyExitException(13, input); - throw eee; - } - cnt13++; - } - - } - break; - - default : - break loop14; - } - } - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:94:3: ( 'else' ( statement )+ )? - int alt16=2; - int LA16_0 = input.LA(1); - if ( (LA16_0==41) ) { - alt16=1; - } - switch (alt16) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:94:4: 'else' ( statement )+ - { - match(input,41,FOLLOW_41_in_ifStatement422); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:94:11: ( statement )+ - int cnt15=0; - loop15: - while (true) { - int alt15=2; - int LA15_0 = input.LA(1); - if ( (LA15_0==IDENT||(LA15_0 >= 46 && LA15_0 <= 47)||LA15_0==60) ) { - alt15=1; - } - - switch (alt15) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:94:11: statement - { - pushFollow(FOLLOW_statement_in_ifStatement424); - statement(); - state._fsp--; - - } - break; - - default : - if ( cnt15 >= 1 ) break loop15; - EarlyExitException eee = new EarlyExitException(15, input); - throw eee; - } - cnt15++; - } - - } - break; - - } - - match(input,43,FOLLOW_43_in_ifStatement431); - match(input,46,FOLLOW_46_in_ifStatement433); - match(input,25,FOLLOW_25_in_ifStatement435); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "ifStatement" - - - public static class assignmentStatement_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "assignmentStatement" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:98:1: assignmentStatement : IDENT ':=' expression ';' ; - public final assignmentStatement_return assignmentStatement() throws RecognitionException { - assignmentStatement_return retval = new assignmentStatement_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:99:2: ( IDENT ':=' expression ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:99:4: IDENT ':=' expression ';' - { - match(input,IDENT,FOLLOW_IDENT_in_assignmentStatement446); - match(input,24,FOLLOW_24_in_assignmentStatement448); - pushFollow(FOLLOW_expression_in_assignmentStatement450); - expression(); - state._fsp--; - - match(input,25,FOLLOW_25_in_assignmentStatement452); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "assignmentStatement" - - - public static class exitStatement_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "exitStatement" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:102:1: exitStatement : 'exit' 'when' expression ';' ; - public final exitStatement_return exitStatement() throws RecognitionException { - exitStatement_return retval = new exitStatement_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:103:2: ( 'exit' 'when' expression ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:103:4: 'exit' 'when' expression ';' - { - match(input,44,FOLLOW_44_in_exitStatement463); - match(input,59,FOLLOW_59_in_exitStatement465); - pushFollow(FOLLOW_expression_in_exitStatement467); - expression(); - state._fsp--; - - match(input,25,FOLLOW_25_in_exitStatement469); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "exitStatement" - - - public static class whileStatement_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "whileStatement" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:106:1: whileStatement : 'while' expression 'loop' ( statement | exitStatement )* 'end' 'loop' ';' ; - public final whileStatement_return whileStatement() throws RecognitionException { - whileStatement_return retval = new whileStatement_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:107:2: ( 'while' expression 'loop' ( statement | exitStatement )* 'end' 'loop' ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:107:4: 'while' expression 'loop' ( statement | exitStatement )* 'end' 'loop' ';' - { - match(input,60,FOLLOW_60_in_whileStatement480); - pushFollow(FOLLOW_expression_in_whileStatement482); - expression(); - state._fsp--; - - match(input,47,FOLLOW_47_in_whileStatement484); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:108:3: ( statement | exitStatement )* - loop17: - while (true) { - int alt17=3; - int LA17_0 = input.LA(1); - if ( (LA17_0==IDENT||(LA17_0 >= 46 && LA17_0 <= 47)||LA17_0==60) ) { - alt17=1; - } - else if ( (LA17_0==44) ) { - alt17=2; - } - - switch (alt17) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:108:4: statement - { - pushFollow(FOLLOW_statement_in_whileStatement489); - statement(); - state._fsp--; - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:108:14: exitStatement - { - pushFollow(FOLLOW_exitStatement_in_whileStatement491); - exitStatement(); - state._fsp--; - - } - break; - - default : - break loop17; - } - } - - match(input,43,FOLLOW_43_in_whileStatement497); - match(input,47,FOLLOW_47_in_whileStatement499); - match(input,25,FOLLOW_25_in_whileStatement501); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "whileStatement" - - - public static class loopStatement_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "loopStatement" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:112:1: loopStatement : 'loop' ( statement | exitStatement )* 'end' 'loop' ';' ; - public final loopStatement_return loopStatement() throws RecognitionException { - loopStatement_return retval = new loopStatement_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:113:2: ( 'loop' ( statement | exitStatement )* 'end' 'loop' ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:113:4: 'loop' ( statement | exitStatement )* 'end' 'loop' ';' - { - match(input,47,FOLLOW_47_in_loopStatement512); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:113:11: ( statement | exitStatement )* - loop18: - while (true) { - int alt18=3; - int LA18_0 = input.LA(1); - if ( (LA18_0==IDENT||(LA18_0 >= 46 && LA18_0 <= 47)||LA18_0==60) ) { - alt18=1; - } - else if ( (LA18_0==44) ) { - alt18=2; - } - - switch (alt18) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:113:12: statement - { - pushFollow(FOLLOW_statement_in_loopStatement515); - statement(); - state._fsp--; - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:113:22: exitStatement - { - pushFollow(FOLLOW_exitStatement_in_loopStatement517); - exitStatement(); - state._fsp--; - - } - break; - - default : - break loop18; - } - } - - match(input,43,FOLLOW_43_in_loopStatement521); - match(input,47,FOLLOW_47_in_loopStatement523); - match(input,25,FOLLOW_25_in_loopStatement525); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "loopStatement" - - - public static class returnStatement_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "returnStatement" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:116:1: returnStatement : 'return' expression ';' ; - public final returnStatement_return returnStatement() throws RecognitionException { - returnStatement_return retval = new returnStatement_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:117:2: ( 'return' expression ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:117:4: 'return' expression ';' - { - match(input,55,FOLLOW_55_in_returnStatement536); - pushFollow(FOLLOW_expression_in_returnStatement538); - expression(); - state._fsp--; - - match(input,25,FOLLOW_25_in_returnStatement540); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "returnStatement" - - - public static class procedure_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "procedure" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:120:1: procedure : 'procedure' IDENT '(' ( parameters )? ')' '=' ( constant | variable )* 'begin' ( statement )* 'end' IDENT '.' ; - public final procedure_return procedure() throws RecognitionException { - procedure_return retval = new procedure_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:121:2: ( 'procedure' IDENT '(' ( parameters )? ')' '=' ( constant | variable )* 'begin' ( statement )* 'end' IDENT '.' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:121:4: 'procedure' IDENT '(' ( parameters )? ')' '=' ( constant | variable )* 'begin' ( statement )* 'end' IDENT '.' - { - match(input,52,FOLLOW_52_in_procedure551); - match(input,IDENT,FOLLOW_IDENT_in_procedure553); - match(input,13,FOLLOW_13_in_procedure555); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:121:26: ( parameters )? - int alt19=2; - int LA19_0 = input.LA(1); - if ( (LA19_0==IDENT||LA19_0==58) ) { - alt19=1; - } - switch (alt19) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:121:26: parameters - { - pushFollow(FOLLOW_parameters_in_procedure557); - parameters(); - state._fsp--; - - } - break; - - } - - match(input,14,FOLLOW_14_in_procedure560); - match(input,28,FOLLOW_28_in_procedure562); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:122:3: ( constant | variable )* - loop20: - while (true) { - int alt20=3; - int LA20_0 = input.LA(1); - if ( (LA20_0==40) ) { - alt20=1; - } - else if ( (LA20_0==58) ) { - alt20=2; - } - - switch (alt20) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:122:4: constant - { - pushFollow(FOLLOW_constant_in_procedure567); - constant(); - state._fsp--; - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:122:15: variable - { - pushFollow(FOLLOW_variable_in_procedure571); - variable(); - state._fsp--; - - } - break; - - default : - break loop20; - } - } - - match(input,39,FOLLOW_39_in_procedure577); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:124:3: ( statement )* - loop21: - while (true) { - int alt21=2; - int LA21_0 = input.LA(1); - if ( (LA21_0==IDENT||(LA21_0 >= 46 && LA21_0 <= 47)||LA21_0==60) ) { - alt21=1; - } - - switch (alt21) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:124:3: statement - { - pushFollow(FOLLOW_statement_in_procedure581); - statement(); - state._fsp--; - - } - break; - - default : - break loop21; - } - } - - match(input,43,FOLLOW_43_in_procedure586); - match(input,IDENT,FOLLOW_IDENT_in_procedure588); - match(input,19,FOLLOW_19_in_procedure590); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "procedure" - - - public static class function_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "function" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:127:1: function : 'function' IDENT '(' ( parameters )? ')' ':' type '=' ( constant | variable )* 'begin' ( statement | returnStatement )* 'end' IDENT '.' ; - public final function_return function() throws RecognitionException { - function_return retval = new function_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:128:2: ( 'function' IDENT '(' ( parameters )? ')' ':' type '=' ( constant | variable )* 'begin' ( statement | returnStatement )* 'end' IDENT '.' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:128:4: 'function' IDENT '(' ( parameters )? ')' ':' type '=' ( constant | variable )* 'begin' ( statement | returnStatement )* 'end' IDENT '.' - { - match(input,45,FOLLOW_45_in_function600); - match(input,IDENT,FOLLOW_IDENT_in_function602); - match(input,13,FOLLOW_13_in_function604); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:128:25: ( parameters )? - int alt22=2; - int LA22_0 = input.LA(1); - if ( (LA22_0==IDENT||LA22_0==58) ) { - alt22=1; - } - switch (alt22) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:128:25: parameters - { - pushFollow(FOLLOW_parameters_in_function606); - parameters(); - state._fsp--; - - } - break; - - } - - match(input,14,FOLLOW_14_in_function609); - match(input,23,FOLLOW_23_in_function611); - pushFollow(FOLLOW_type_in_function613); - type(); - state._fsp--; - - match(input,28,FOLLOW_28_in_function615); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:129:3: ( constant | variable )* - loop23: - while (true) { - int alt23=3; - int LA23_0 = input.LA(1); - if ( (LA23_0==40) ) { - alt23=1; - } - else if ( (LA23_0==58) ) { - alt23=2; - } - - switch (alt23) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:129:4: constant - { - pushFollow(FOLLOW_constant_in_function620); - constant(); - state._fsp--; - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:129:15: variable - { - pushFollow(FOLLOW_variable_in_function624); - variable(); - state._fsp--; - - } - break; - - default : - break loop23; - } - } - - match(input,39,FOLLOW_39_in_function630); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:131:3: ( statement | returnStatement )* - loop24: - while (true) { - int alt24=3; - int LA24_0 = input.LA(1); - if ( (LA24_0==IDENT||(LA24_0 >= 46 && LA24_0 <= 47)||LA24_0==60) ) { - alt24=1; - } - else if ( (LA24_0==55) ) { - alt24=2; - } - - switch (alt24) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:131:4: statement - { - pushFollow(FOLLOW_statement_in_function635); - statement(); - state._fsp--; - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:131:14: returnStatement - { - pushFollow(FOLLOW_returnStatement_in_function637); - returnStatement(); - state._fsp--; - - } - break; - - default : - break loop24; - } - } - - match(input,43,FOLLOW_43_in_function643); - match(input,IDENT,FOLLOW_IDENT_in_function645); - match(input,19,FOLLOW_19_in_function647); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "function" - - - public static class parameters_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "parameters" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:135:1: parameters : parameter ( ',' parameter )* ; - public final parameters_return parameters() throws RecognitionException { - parameters_return retval = new parameters_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:136:2: ( parameter ( ',' parameter )* ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:136:4: parameter ( ',' parameter )* - { - pushFollow(FOLLOW_parameter_in_parameters658); - parameter(); - state._fsp--; - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:136:14: ( ',' parameter )* - loop25: - while (true) { - int alt25=2; - int LA25_0 = input.LA(1); - if ( (LA25_0==17) ) { - alt25=1; - } - - switch (alt25) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:136:15: ',' parameter - { - match(input,17,FOLLOW_17_in_parameters661); - pushFollow(FOLLOW_parameter_in_parameters663); - parameter(); - state._fsp--; - - } - break; - - default : - break loop25; - } - } - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "parameters" - - - public static class parameter_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "parameter" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:139:1: parameter : ( 'var' )? IDENT ':' type ; - public final parameter_return parameter() throws RecognitionException { - parameter_return retval = new parameter_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:140:2: ( ( 'var' )? IDENT ':' type ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:140:4: ( 'var' )? IDENT ':' type - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:140:4: ( 'var' )? - int alt26=2; - int LA26_0 = input.LA(1); - if ( (LA26_0==58) ) { - alt26=1; - } - switch (alt26) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:140:4: 'var' - { - match(input,58,FOLLOW_58_in_parameter676); - } - break; - - } - - match(input,IDENT,FOLLOW_IDENT_in_parameter679); - match(input,23,FOLLOW_23_in_parameter681); - pushFollow(FOLLOW_type_in_parameter683); - type(); - state._fsp--; - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "parameter" - - - public static class term_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "term" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:146:1: term : ( IDENT | '(' expression ')' | INTEGER | STRING_LITERAL | CHAR_LITERAL | IDENT '(' actualParameters ')' ); - public final term_return term() throws RecognitionException { - term_return retval = new term_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:147:2: ( IDENT | '(' expression ')' | INTEGER | STRING_LITERAL | CHAR_LITERAL | IDENT '(' actualParameters ')' ) - int alt27=6; - switch ( input.LA(1) ) { - case IDENT: - { - int LA27_1 = input.LA(2); - if ( (LA27_1==13) ) { - alt27=6; - } - else if ( ((LA27_1 >= 14 && LA27_1 <= 18)||(LA27_1 >= 21 && LA27_1 <= 22)||(LA27_1 >= 25 && LA27_1 <= 30)||LA27_1==37||(LA27_1 >= 47 && LA27_1 <= 48)||LA27_1==51||LA27_1==56) ) { - alt27=1; - } - - else { - int nvaeMark = input.mark(); - try { - input.consume(); - NoViableAltException nvae = - new NoViableAltException("", 27, 1, input); - throw nvae; - } finally { - input.rewind(nvaeMark); - } - } - - } - break; - case 13: - { - alt27=2; - } - break; - case INTEGER: - { - alt27=3; - } - break; - case STRING_LITERAL: - { - alt27=4; - } - break; - case CHAR_LITERAL: - { - alt27=5; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 27, 0, input); - throw nvae; - } - switch (alt27) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:147:4: IDENT - { - match(input,IDENT,FOLLOW_IDENT_in_term697); - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:148:4: '(' expression ')' - { - match(input,13,FOLLOW_13_in_term702); - pushFollow(FOLLOW_expression_in_term704); - expression(); - state._fsp--; - - match(input,14,FOLLOW_14_in_term706); - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:149:4: INTEGER - { - match(input,INTEGER,FOLLOW_INTEGER_in_term711); - } - break; - case 4 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:150:4: STRING_LITERAL - { - match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_term716); - } - break; - case 5 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:151:4: CHAR_LITERAL - { - match(input,CHAR_LITERAL,FOLLOW_CHAR_LITERAL_in_term721); - } - break; - case 6 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:152:4: IDENT '(' actualParameters ')' - { - match(input,IDENT,FOLLOW_IDENT_in_term726); - match(input,13,FOLLOW_13_in_term728); - pushFollow(FOLLOW_actualParameters_in_term730); - actualParameters(); - state._fsp--; - - match(input,14,FOLLOW_14_in_term732); - } - break; - - } - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "term" - - - public static class negation_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "negation" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:155:1: negation : ( 'not' )* term ; - public final negation_return negation() throws RecognitionException { - negation_return retval = new negation_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:156:2: ( ( 'not' )* term ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:156:4: ( 'not' )* term - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:156:4: ( 'not' )* - loop28: - while (true) { - int alt28=2; - int LA28_0 = input.LA(1); - if ( (LA28_0==49) ) { - alt28=1; - } - - switch (alt28) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:156:4: 'not' - { - match(input,49,FOLLOW_49_in_negation743); - } - break; - - default : - break loop28; - } - } - - pushFollow(FOLLOW_term_in_negation746); - term(); - state._fsp--; - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "negation" - - - public static class unary_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "unary" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:159:1: unary : ( '+' | '-' )* negation ; - public final unary_return unary() throws RecognitionException { - unary_return retval = new unary_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:160:2: ( ( '+' | '-' )* negation ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:160:4: ( '+' | '-' )* negation - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:160:4: ( '+' | '-' )* - loop29: - while (true) { - int alt29=2; - int LA29_0 = input.LA(1); - if ( (LA29_0==16||LA29_0==18) ) { - alt29=1; - } - - switch (alt29) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g: - { - if ( input.LA(1)==16||input.LA(1)==18 ) { - input.consume(); - state.errorRecovery=false; - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - throw mse; - } - } - break; - - default : - break loop29; - } - } - - pushFollow(FOLLOW_negation_in_unary766); - negation(); - state._fsp--; - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "unary" - - - public static class mult_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "mult" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:163:1: mult : unary ( ( '*' | '/' | 'mod' ) unary )* ; - public final mult_return mult() throws RecognitionException { - mult_return retval = new mult_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:164:2: ( unary ( ( '*' | '/' | 'mod' ) unary )* ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:164:4: unary ( ( '*' | '/' | 'mod' ) unary )* - { - pushFollow(FOLLOW_unary_in_mult777); - unary(); - state._fsp--; - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:164:10: ( ( '*' | '/' | 'mod' ) unary )* - loop30: - while (true) { - int alt30=2; - int LA30_0 = input.LA(1); - if ( (LA30_0==15||LA30_0==21||LA30_0==48) ) { - alt30=1; - } - - switch (alt30) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:164:11: ( '*' | '/' | 'mod' ) unary - { - if ( input.LA(1)==15||input.LA(1)==21||input.LA(1)==48 ) { - input.consume(); - state.errorRecovery=false; - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - throw mse; - } - pushFollow(FOLLOW_unary_in_mult792); - unary(); - state._fsp--; - - } - break; - - default : - break loop30; - } - } - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "mult" - - - public static class add_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "add" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:167:1: add : mult ( ( '+' | '-' ) mult )* ; - public final add_return add() throws RecognitionException { - add_return retval = new add_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:168:2: ( mult ( ( '+' | '-' ) mult )* ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:168:4: mult ( ( '+' | '-' ) mult )* - { - pushFollow(FOLLOW_mult_in_add805); - mult(); - state._fsp--; - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:168:9: ( ( '+' | '-' ) mult )* - loop31: - while (true) { - int alt31=2; - int LA31_0 = input.LA(1); - if ( (LA31_0==16||LA31_0==18) ) { - alt31=1; - } - - switch (alt31) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:168:10: ( '+' | '-' ) mult - { - if ( input.LA(1)==16||input.LA(1)==18 ) { - input.consume(); - state.errorRecovery=false; - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - throw mse; - } - pushFollow(FOLLOW_mult_in_add816); - mult(); - state._fsp--; - - } - break; - - default : - break loop31; - } - } - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "add" - - - public static class relation_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "relation" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:171:1: relation : add ( ( '=' | '/=' | '<' | '<=' | '>=' | '>' ) add )* ; - public final relation_return relation() throws RecognitionException { - relation_return retval = new relation_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:172:2: ( add ( ( '=' | '/=' | '<' | '<=' | '>=' | '>' ) add )* ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:172:4: add ( ( '=' | '/=' | '<' | '<=' | '>=' | '>' ) add )* - { - pushFollow(FOLLOW_add_in_relation829); - add(); - state._fsp--; - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:172:8: ( ( '=' | '/=' | '<' | '<=' | '>=' | '>' ) add )* - loop32: - while (true) { - int alt32=2; - int LA32_0 = input.LA(1); - if ( (LA32_0==22||(LA32_0 >= 26 && LA32_0 <= 30)) ) { - alt32=1; - } - - switch (alt32) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:172:9: ( '=' | '/=' | '<' | '<=' | '>=' | '>' ) add - { - if ( input.LA(1)==22||(input.LA(1) >= 26 && input.LA(1) <= 30) ) { - input.consume(); - state.errorRecovery=false; - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - throw mse; - } - pushFollow(FOLLOW_add_in_relation856); - add(); - state._fsp--; - - } - break; - - default : - break loop32; - } - } - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "relation" - - - public static class expression_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "expression" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:175:1: expression : relation ( ( 'and' | 'or' ) relation )* ; - public final expression_return expression() throws RecognitionException { - expression_return retval = new expression_return(); - retval.start = input.LT(1); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:176:2: ( relation ( ( 'and' | 'or' ) relation )* ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:176:4: relation ( ( 'and' | 'or' ) relation )* - { - pushFollow(FOLLOW_relation_in_expression869); - relation(); - state._fsp--; - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:176:13: ( ( 'and' | 'or' ) relation )* - loop33: - while (true) { - int alt33=2; - int LA33_0 = input.LA(1); - if ( (LA33_0==37||LA33_0==51) ) { - alt33=1; - } - - switch (alt33) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\antlr\\Sample.g:176:14: ( 'and' | 'or' ) relation - { - if ( input.LA(1)==37||input.LA(1)==51 ) { - input.consume(); - state.errorRecovery=false; - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - throw mse; - } - pushFollow(FOLLOW_relation_in_expression880); - relation(); - state._fsp--; - - } - break; - - default : - break loop33; - } - } - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "expression" - - // Delegated rules - - - - public static final BitSet FOLLOW_53_in_program58 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_program60 = new BitSet(new long[]{0x0000000010000000L}); - public static final BitSet FOLLOW_28_in_program62 = new BitSet(new long[]{0x0610218000000000L}); - public static final BitSet FOLLOW_constant_in_program67 = new BitSet(new long[]{0x0610218000000000L}); - public static final BitSet FOLLOW_variable_in_program71 = new BitSet(new long[]{0x0610218000000000L}); - public static final BitSet FOLLOW_function_in_program75 = new BitSet(new long[]{0x0610218000000000L}); - public static final BitSet FOLLOW_procedure_in_program79 = new BitSet(new long[]{0x0610218000000000L}); - public static final BitSet FOLLOW_typeDecl_in_program83 = new BitSet(new long[]{0x0610218000000000L}); - public static final BitSet FOLLOW_39_in_program89 = new BitSet(new long[]{0x1000C80000000080L}); - public static final BitSet FOLLOW_statement_in_program93 = new BitSet(new long[]{0x1000C80000000080L}); - public static final BitSet FOLLOW_43_in_program98 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_program100 = new BitSet(new long[]{0x0000000000080000L}); - public static final BitSet FOLLOW_19_in_program102 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_40_in_constant113 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_constant115 = new BitSet(new long[]{0x0000000000800000L}); - public static final BitSet FOLLOW_23_in_constant117 = new BitSet(new long[]{0x0040004784000080L}); - public static final BitSet FOLLOW_type_in_constant119 = new BitSet(new long[]{0x0000000001000000L}); - public static final BitSet FOLLOW_24_in_constant121 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_expression_in_constant123 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_constant125 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_58_in_variable136 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_variable138 = new BitSet(new long[]{0x0000000000820000L}); - public static final BitSet FOLLOW_17_in_variable141 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_variable143 = new BitSet(new long[]{0x0000000000820000L}); - public static final BitSet FOLLOW_23_in_variable147 = new BitSet(new long[]{0x0040004784000080L}); - public static final BitSet FOLLOW_type_in_variable149 = new BitSet(new long[]{0x0000000003000000L}); - public static final BitSet FOLLOW_24_in_variable152 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_expression_in_variable154 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_variable158 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_33_in_type169 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_31_in_type174 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_34_in_type179 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_32_in_type184 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_IDENT_in_type189 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_typeSpec_in_type194 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_57_in_typeDecl205 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_typeDecl207 = new BitSet(new long[]{0x0000000010000000L}); - public static final BitSet FOLLOW_28_in_typeDecl209 = new BitSet(new long[]{0x0040004004000000L}); - public static final BitSet FOLLOW_typeSpec_in_typeDecl211 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_typeDecl213 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_arrayType_in_typeSpec224 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_recordType_in_typeSpec229 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_enumType_in_typeSpec234 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_38_in_arrayType245 = new BitSet(new long[]{0x0000000800000000L}); - public static final BitSet FOLLOW_35_in_arrayType247 = new BitSet(new long[]{0x0000000000000100L}); - public static final BitSet FOLLOW_INTEGER_in_arrayType249 = new BitSet(new long[]{0x0000000000100000L}); - public static final BitSet FOLLOW_20_in_arrayType251 = new BitSet(new long[]{0x0000000000000100L}); - public static final BitSet FOLLOW_INTEGER_in_arrayType253 = new BitSet(new long[]{0x0000001000000000L}); - public static final BitSet FOLLOW_36_in_arrayType255 = new BitSet(new long[]{0x0004000000000000L}); - public static final BitSet FOLLOW_50_in_arrayType257 = new BitSet(new long[]{0x0040004784000080L}); - public static final BitSet FOLLOW_type_in_arrayType259 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_54_in_recordType270 = new BitSet(new long[]{0x0000080000000080L}); - public static final BitSet FOLLOW_field_in_recordType272 = new BitSet(new long[]{0x0000080000000080L}); - public static final BitSet FOLLOW_43_in_recordType275 = new BitSet(new long[]{0x0040000000000000L}); - public static final BitSet FOLLOW_54_in_recordType277 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_IDENT_in_field288 = new BitSet(new long[]{0x0000000000800000L}); - public static final BitSet FOLLOW_23_in_field290 = new BitSet(new long[]{0x0040004784000080L}); - public static final BitSet FOLLOW_type_in_field292 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_field294 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_26_in_enumType305 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_enumType307 = new BitSet(new long[]{0x0000000020020000L}); - public static final BitSet FOLLOW_17_in_enumType310 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_enumType312 = new BitSet(new long[]{0x0000000020020000L}); - public static final BitSet FOLLOW_29_in_enumType316 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_assignmentStatement_in_statement327 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_ifStatement_in_statement332 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_loopStatement_in_statement337 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_whileStatement_in_statement342 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_procedureCallStatement_in_statement347 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_IDENT_in_procedureCallStatement358 = new BitSet(new long[]{0x0000000000002000L}); - public static final BitSet FOLLOW_13_in_procedureCallStatement360 = new BitSet(new long[]{0x0002000000056990L}); - public static final BitSet FOLLOW_actualParameters_in_procedureCallStatement362 = new BitSet(new long[]{0x0000000000004000L}); - public static final BitSet FOLLOW_14_in_procedureCallStatement365 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_procedureCallStatement367 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_expression_in_actualParameters378 = new BitSet(new long[]{0x0000000000020002L}); - public static final BitSet FOLLOW_17_in_actualParameters381 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_expression_in_actualParameters383 = new BitSet(new long[]{0x0000000000020002L}); - public static final BitSet FOLLOW_46_in_ifStatement396 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_expression_in_ifStatement398 = new BitSet(new long[]{0x0100000000000000L}); - public static final BitSet FOLLOW_56_in_ifStatement400 = new BitSet(new long[]{0x1000C00000000080L}); - public static final BitSet FOLLOW_statement_in_ifStatement402 = new BitSet(new long[]{0x1000CE0000000080L}); - public static final BitSet FOLLOW_42_in_ifStatement408 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_expression_in_ifStatement410 = new BitSet(new long[]{0x0100000000000000L}); - public static final BitSet FOLLOW_56_in_ifStatement412 = new BitSet(new long[]{0x1000C00000000080L}); - public static final BitSet FOLLOW_statement_in_ifStatement414 = new BitSet(new long[]{0x1000CE0000000080L}); - public static final BitSet FOLLOW_41_in_ifStatement422 = new BitSet(new long[]{0x1000C00000000080L}); - public static final BitSet FOLLOW_statement_in_ifStatement424 = new BitSet(new long[]{0x1000C80000000080L}); - public static final BitSet FOLLOW_43_in_ifStatement431 = new BitSet(new long[]{0x0000400000000000L}); - public static final BitSet FOLLOW_46_in_ifStatement433 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_ifStatement435 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_IDENT_in_assignmentStatement446 = new BitSet(new long[]{0x0000000001000000L}); - public static final BitSet FOLLOW_24_in_assignmentStatement448 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_expression_in_assignmentStatement450 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_assignmentStatement452 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_44_in_exitStatement463 = new BitSet(new long[]{0x0800000000000000L}); - public static final BitSet FOLLOW_59_in_exitStatement465 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_expression_in_exitStatement467 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_exitStatement469 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_60_in_whileStatement480 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_expression_in_whileStatement482 = new BitSet(new long[]{0x0000800000000000L}); - public static final BitSet FOLLOW_47_in_whileStatement484 = new BitSet(new long[]{0x1000D80000000080L}); - public static final BitSet FOLLOW_statement_in_whileStatement489 = new BitSet(new long[]{0x1000D80000000080L}); - public static final BitSet FOLLOW_exitStatement_in_whileStatement491 = new BitSet(new long[]{0x1000D80000000080L}); - public static final BitSet FOLLOW_43_in_whileStatement497 = new BitSet(new long[]{0x0000800000000000L}); - public static final BitSet FOLLOW_47_in_whileStatement499 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_whileStatement501 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_47_in_loopStatement512 = new BitSet(new long[]{0x1000D80000000080L}); - public static final BitSet FOLLOW_statement_in_loopStatement515 = new BitSet(new long[]{0x1000D80000000080L}); - public static final BitSet FOLLOW_exitStatement_in_loopStatement517 = new BitSet(new long[]{0x1000D80000000080L}); - public static final BitSet FOLLOW_43_in_loopStatement521 = new BitSet(new long[]{0x0000800000000000L}); - public static final BitSet FOLLOW_47_in_loopStatement523 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_loopStatement525 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_55_in_returnStatement536 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_expression_in_returnStatement538 = new BitSet(new long[]{0x0000000002000000L}); - public static final BitSet FOLLOW_25_in_returnStatement540 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_52_in_procedure551 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_procedure553 = new BitSet(new long[]{0x0000000000002000L}); - public static final BitSet FOLLOW_13_in_procedure555 = new BitSet(new long[]{0x0400000000004080L}); - public static final BitSet FOLLOW_parameters_in_procedure557 = new BitSet(new long[]{0x0000000000004000L}); - public static final BitSet FOLLOW_14_in_procedure560 = new BitSet(new long[]{0x0000000010000000L}); - public static final BitSet FOLLOW_28_in_procedure562 = new BitSet(new long[]{0x0400018000000000L}); - public static final BitSet FOLLOW_constant_in_procedure567 = new BitSet(new long[]{0x0400018000000000L}); - public static final BitSet FOLLOW_variable_in_procedure571 = new BitSet(new long[]{0x0400018000000000L}); - public static final BitSet FOLLOW_39_in_procedure577 = new BitSet(new long[]{0x1000C80000000080L}); - public static final BitSet FOLLOW_statement_in_procedure581 = new BitSet(new long[]{0x1000C80000000080L}); - public static final BitSet FOLLOW_43_in_procedure586 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_procedure588 = new BitSet(new long[]{0x0000000000080000L}); - public static final BitSet FOLLOW_19_in_procedure590 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_45_in_function600 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_function602 = new BitSet(new long[]{0x0000000000002000L}); - public static final BitSet FOLLOW_13_in_function604 = new BitSet(new long[]{0x0400000000004080L}); - public static final BitSet FOLLOW_parameters_in_function606 = new BitSet(new long[]{0x0000000000004000L}); - public static final BitSet FOLLOW_14_in_function609 = new BitSet(new long[]{0x0000000000800000L}); - public static final BitSet FOLLOW_23_in_function611 = new BitSet(new long[]{0x0040004784000080L}); - public static final BitSet FOLLOW_type_in_function613 = new BitSet(new long[]{0x0000000010000000L}); - public static final BitSet FOLLOW_28_in_function615 = new BitSet(new long[]{0x0400018000000000L}); - public static final BitSet FOLLOW_constant_in_function620 = new BitSet(new long[]{0x0400018000000000L}); - public static final BitSet FOLLOW_variable_in_function624 = new BitSet(new long[]{0x0400018000000000L}); - public static final BitSet FOLLOW_39_in_function630 = new BitSet(new long[]{0x1080C80000000080L}); - public static final BitSet FOLLOW_statement_in_function635 = new BitSet(new long[]{0x1080C80000000080L}); - public static final BitSet FOLLOW_returnStatement_in_function637 = new BitSet(new long[]{0x1080C80000000080L}); - public static final BitSet FOLLOW_43_in_function643 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_function645 = new BitSet(new long[]{0x0000000000080000L}); - public static final BitSet FOLLOW_19_in_function647 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_parameter_in_parameters658 = new BitSet(new long[]{0x0000000000020002L}); - public static final BitSet FOLLOW_17_in_parameters661 = new BitSet(new long[]{0x0400000000000080L}); - public static final BitSet FOLLOW_parameter_in_parameters663 = new BitSet(new long[]{0x0000000000020002L}); - public static final BitSet FOLLOW_58_in_parameter676 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_IDENT_in_parameter679 = new BitSet(new long[]{0x0000000000800000L}); - public static final BitSet FOLLOW_23_in_parameter681 = new BitSet(new long[]{0x0040004784000080L}); - public static final BitSet FOLLOW_type_in_parameter683 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_IDENT_in_term697 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_13_in_term702 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_expression_in_term704 = new BitSet(new long[]{0x0000000000004000L}); - public static final BitSet FOLLOW_14_in_term706 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_INTEGER_in_term711 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_STRING_LITERAL_in_term716 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_CHAR_LITERAL_in_term721 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_IDENT_in_term726 = new BitSet(new long[]{0x0000000000002000L}); - public static final BitSet FOLLOW_13_in_term728 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_actualParameters_in_term730 = new BitSet(new long[]{0x0000000000004000L}); - public static final BitSet FOLLOW_14_in_term732 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_49_in_negation743 = new BitSet(new long[]{0x0002000000002990L}); - public static final BitSet FOLLOW_term_in_negation746 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_negation_in_unary766 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_unary_in_mult777 = new BitSet(new long[]{0x0001000000208002L}); - public static final BitSet FOLLOW_set_in_mult780 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_unary_in_mult792 = new BitSet(new long[]{0x0001000000208002L}); - public static final BitSet FOLLOW_mult_in_add805 = new BitSet(new long[]{0x0000000000050002L}); - public static final BitSet FOLLOW_set_in_add808 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_mult_in_add816 = new BitSet(new long[]{0x0000000000050002L}); - public static final BitSet FOLLOW_add_in_relation829 = new BitSet(new long[]{0x000000007C400002L}); - public static final BitSet FOLLOW_set_in_relation832 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_add_in_relation856 = new BitSet(new long[]{0x000000007C400002L}); - public static final BitSet FOLLOW_relation_in_expression869 = new BitSet(new long[]{0x0008002000000002L}); - public static final BitSet FOLLOW_set_in_expression872 = new BitSet(new long[]{0x0002000000052990L}); - public static final BitSet FOLLOW_relation_in_expression880 = new BitSet(new long[]{0x0008002000000002L}); -} diff --git a/ethereumj-core/src/main/java/samples/antlr/Test1.java b/ethereumj-core/src/main/java/samples/antlr/Test1.java deleted file mode 100644 index 2513de23..00000000 --- a/ethereumj-core/src/main/java/samples/antlr/Test1.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Scott Stanchfield - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package samples.antlr; - -import org.antlr.runtime.*; -import org.antlr.runtime.tree.CommonTree; -import org.antlr.runtime.tree.DOTTreeGenerator; -import org.antlr.stringtemplate.StringTemplate; -import org.antlr.stringtemplate.StringTemplateGroup; - - - -public class Test1 { - public static void main(String[] args) throws RecognitionException { - CharStream stream = - new ANTLRStringStream("program XLSample1 =\r\n" + - "/*\r\n" + - " constant one : Integer := 1;\r\n" + - " constant two : Integer := 2 * 3;\r\n" + - " var x, y, z : Integer := 42;\r\n" + - "*/\r\n" + - "\r\n" + - " procedure foo() =\r\n" + - " var x : Integer := 2;\r\n" + - " begin\r\n" + - " end foo.\r\n" + - " procedure fee(y : Integer) =\r\n" + - " var x : Integer := 2;\r\n" + - " begin\r\n" + - " end fee.\r\n" + - " function fie(y : Integer) : Integer =\r\n" + - " var x : Integer := 2;\r\n" + - " begin\r\n" + - " return y;\r\n" + - " end fie.\r\n" + - "begin\r\n" + - "end XLSample1."); - SampleLexer lexer = new SampleLexer(stream); - TokenStream tokenStream = new CommonTokenStream(lexer); - SampleParser parser = new SampleParser(tokenStream); - CommonTree astTree = (CommonTree) parser.program().getTree(); - - DOTTreeGenerator gen = new DOTTreeGenerator(); - StringTemplate st = gen.toDOT(astTree); - - - String userDir = System.getProperty("user.dir"); - - String stgFile = userDir + "\\src\\main\\java\\samples\\antlr\\Sample2Asm.stg"; - - - - StringTemplateGroup stg = new StringTemplateGroup(stgFile); - - parser.setTemplateLib(stg); - - RuleReturnScope r = parser.program(); -// System.out.println(r.getTemplate().toString()); - - - -// System.out.println(st); - - - - -/* - Lexical Analysis (scanning) - Semantic Analysis (parsing) - Tree Generation ==> Abstract Syntax Tree (AST) - Code Generation ==> using stg file - Interpretation -*/ - System.out.println("ok"); - } -} diff --git a/ethereumj-core/src/main/java/samples/netty/Client.java b/ethereumj-core/src/main/java/samples/netty/Client.java deleted file mode 100644 index 4555270d..00000000 --- a/ethereumj-core/src/main/java/samples/netty/Client.java +++ /dev/null @@ -1,51 +0,0 @@ -package samples.netty; - -import io.netty.bootstrap.Bootstrap; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioSocketChannel; - -import java.nio.channels.SocketChannel; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 10/04/14 08:20 - */ -public class Client { - - - public static void main(String[] args) throws Exception { - - String host = "85.65.126.45"; - int port = 10101; - - EventLoopGroup workerGroup = new NioEventLoopGroup(); - - try { - - Bootstrap b = new Bootstrap(); - b.group(workerGroup); - b.channel(NioSocketChannel.class); - - b.option(ChannelOption.SO_KEEPALIVE, true); - b.handler(new ChannelInitializer() { - @Override - public void initChannel(NioSocketChannel ch) throws Exception { - ch.pipeline().addLast(new ClientMessageHandler()); - } - }); - - // Start the client. - ChannelFuture f = b.connect(host, port).sync(); // (5) - - // Wait until the connection is closed. - f.channel().closeFuture().sync(); - } finally { - workerGroup.shutdownGracefully(); - } - } -} diff --git a/ethereumj-core/src/main/java/samples/netty/ClientMessageHandler.java b/ethereumj-core/src/main/java/samples/netty/ClientMessageHandler.java deleted file mode 100644 index bbe6977f..00000000 --- a/ethereumj-core/src/main/java/samples/netty/ClientMessageHandler.java +++ /dev/null @@ -1,70 +0,0 @@ -package samples.netty; - - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.util.ReferenceCountUtil; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 10/04/14 08:19 - */ -public class ClientMessageHandler extends ChannelInboundHandlerAdapter { - - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - - - ByteBuf input = ((ByteBuf)msg); - - try { - - int inputSize = input.readableBytes(); - byte[] payload = new byte[inputSize]; - input.readBytes(payload); - - if (payload.length < 5){ - System.out.println("Not a Roman server disconnect"); - ctx.close(); - } - - String prefix = new String(payload, 0, 5); - - if (!prefix.equals("9191-")){ - System.out.println("Not a Roman server disconnect"); - ctx.close(); - } - - - String newMessage = new String(payload); - System.out.println(newMessage); - - Thread.sleep(1000); - - String answer = RomanProtocol.getAnswer(newMessage); - final ByteBuf buffer = ctx.alloc().buffer(answer.length()); - buffer.writeBytes(answer.getBytes()); - ctx.writeAndFlush(buffer); - -// String answer2 = "cool sir 2!!!"; -// final ByteBuf helloMessage2 = ctx.alloc().buffer(answer2.length()); -// helloMessage2.writeBytes(answer2.getBytes()); -// ctx.writeAndFlush(helloMessage2); - - - } finally { - ReferenceCountUtil.release(input); - } - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - cause.printStackTrace(); - ctx.close(); - } -} diff --git a/ethereumj-core/src/main/java/samples/netty/RomanProtocol.java b/ethereumj-core/src/main/java/samples/netty/RomanProtocol.java deleted file mode 100644 index b7427a96..00000000 --- a/ethereumj-core/src/main/java/samples/netty/RomanProtocol.java +++ /dev/null @@ -1,47 +0,0 @@ -package samples.netty; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 10/04/14 11:19 - */ -public class RomanProtocol { - - - public static String getAnswer(String msg){ - - if (msg.equals("9191-Hello")) - return ("9191-Good day sir"); - - if (msg.equals("9191-Good day sir")) - return ("9191-What is you name"); - - if (msg.equals("9191-What is you name")) - return ("9191-My Name is Ethereum"); - - if (msg.matches("9191-My Name is ([\\w])*")) { - - String name = msg.substring(16); - - return ("9191-Good to see you: " + name); - } - - if (msg.matches("9191-Good to see you: ([\\w])*")) { - - return ("9191-Hello"); - } - - - return "9191-Sorry I don't understand you"; - } - - public static void main(String args[]){ - - System.out.println(getAnswer("9191-My Name is Vasia")); - - -// 1800-0770-77 - - - } -} diff --git a/ethereumj-core/src/main/java/samples/netty/Server.java b/ethereumj-core/src/main/java/samples/netty/Server.java deleted file mode 100644 index 7e2e5ded..00000000 --- a/ethereumj-core/src/main/java/samples/netty/Server.java +++ /dev/null @@ -1,69 +0,0 @@ -package samples.netty; - -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.channel.socket.nio.NioSocketChannel; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 10/04/14 08:20 - */ -public class Server { - - int port; - - - public Server(int port) { - this.port = port; - } - - - public void start(){ - - EventLoopGroup bossGroup = new NioEventLoopGroup(); - EventLoopGroup workerGroup = new NioEventLoopGroup(); - - - ServerBootstrap bootstrap = new ServerBootstrap(); - bootstrap.group(bossGroup, workerGroup) - .channel(NioServerSocketChannel.class) - .childHandler(new ChannelInitializer() { - - public void initChannel(NioSocketChannel channel){ - - channel.pipeline().addLast(new ServerMessageHandler()); - - }; - - }).option(ChannelOption.SO_BACKLOG, 128) - .childOption(ChannelOption.SO_KEEPALIVE, true); - - try { - - System.out.println("Server started"); - ChannelFuture future = bootstrap.bind(port).sync(); - - future.channel().closeFuture().sync(); - - - - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - workerGroup.shutdownGracefully(); - bossGroup.shutdownGracefully(); - } - } - - public static void main(String args[]){ - - new Server(10101).start(); - - } -} diff --git a/ethereumj-core/src/main/java/samples/netty/ServerMessageHandler.java b/ethereumj-core/src/main/java/samples/netty/ServerMessageHandler.java deleted file mode 100644 index 4d8abd65..00000000 --- a/ethereumj-core/src/main/java/samples/netty/ServerMessageHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -package samples.netty; - - -import io.netty.buffer.ByteBuf; -import io.netty.channel.*; -import io.netty.util.ReferenceCountUtil; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 10/04/14 08:19 - */ -public class ServerMessageHandler extends ChannelInboundHandlerAdapter { - - - @Override - public void channelActive(final ChannelHandlerContext ctx) { - - String helloString = "9191-Hello"; - - final ByteBuf helloMessage = ctx.alloc().buffer(helloString.length()); - helloMessage.writeBytes(helloString.getBytes()); - - final ChannelFuture channelFuture = ctx.writeAndFlush(helloMessage); - } - - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - - - ByteBuf input = ((ByteBuf)msg); - - try { - - int inputSize = input.readableBytes(); - byte[] payload = new byte[inputSize]; - input.readBytes(payload); - - String newMessage = new String(payload); - System.out.println(newMessage); - - Thread.sleep(1000); - - String answer = RomanProtocol.getAnswer(newMessage); - final ByteBuf buffer = ctx.alloc().buffer(answer.length()); - buffer.writeBytes(answer.getBytes()); - ctx.writeAndFlush(buffer); - - - - - } finally { - ReferenceCountUtil.release(input); - } - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - - System.out.println("Client disconnected"); -// cause.printStackTrace(); - ctx.close(); - } -} diff --git a/ethereumj-core/src/main/java/samples/niotut/ChangeRequest.java b/ethereumj-core/src/main/java/samples/niotut/ChangeRequest.java deleted file mode 100644 index 2d638fdc..00000000 --- a/ethereumj-core/src/main/java/samples/niotut/ChangeRequest.java +++ /dev/null @@ -1,18 +0,0 @@ -package samples.niotut; - -import java.nio.channels.SocketChannel; - -public class ChangeRequest { - public static final int REGISTER = 1; - public static final int CHANGEOPS = 2; - - public SocketChannel socket; - public int type; - public int ops; - - public ChangeRequest(SocketChannel socket, int type, int ops) { - this.socket = socket; - this.type = type; - this.ops = ops; - } -} diff --git a/ethereumj-core/src/main/java/samples/niotut/EchoWorker.java b/ethereumj-core/src/main/java/samples/niotut/EchoWorker.java deleted file mode 100644 index b6ef02b7..00000000 --- a/ethereumj-core/src/main/java/samples/niotut/EchoWorker.java +++ /dev/null @@ -1,38 +0,0 @@ -package samples.niotut; - -import java.nio.channels.SocketChannel; -import java.util.LinkedList; -import java.util.List; - -public class EchoWorker implements Runnable { - private List queue = new LinkedList(); - - public void processData(NioServer server, SocketChannel socket, byte[] data, int count) { - byte[] dataCopy = new byte[count]; - System.arraycopy(data, 0, dataCopy, 0, count); - synchronized(queue) { - queue.add(new ServerDataEvent(server, socket, dataCopy)); - queue.notify(); - } - } - - public void run() { - ServerDataEvent dataEvent; - - while(true) { - // Wait for data to become available - synchronized(queue) { - while(queue.isEmpty()) { - try { - queue.wait(); - } catch (InterruptedException e) { - } - } - dataEvent = (ServerDataEvent) queue.remove(0); - } - - // Return to sender - dataEvent.server.send(dataEvent.socket, dataEvent.data); - } - } -} diff --git a/ethereumj-core/src/main/java/samples/niotut/NioClient.java b/ethereumj-core/src/main/java/samples/niotut/NioClient.java deleted file mode 100644 index 28cf42b5..00000000 --- a/ethereumj-core/src/main/java/samples/niotut/NioClient.java +++ /dev/null @@ -1,403 +0,0 @@ -package samples.niotut; - - -/* BASED ON: http://rox-xmlrpc.sourceforge.net/niotut/#The client */ - -import org.ethereum.util.Utils; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.nio.ByteBuffer; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.SocketChannel; -import java.nio.channels.spi.SelectorProvider; -import java.util.*; - -public class NioClient implements Runnable { - // The host:port combination to connect to - private InetAddress hostAddress; - private int port; - - // The selector we'll be monitoring - private Selector selector; - - // The buffer into which we'll read data when it's available - private ByteBuffer readBuffer = ByteBuffer.allocate(8192); - - // A list of PendingChange instances - private List pendingChanges = new LinkedList(); - - // Maps a SocketChannel to a list of ByteBuffer instances - private Map pendingData = new HashMap(); - - // Maps a SocketChannel to a RspHandler - private Map rspHandlers = Collections.synchronizedMap(new HashMap()); - - public SocketChannel socket; - public RspHandler handler; - - - public static final String helloString = "22 40 08 91 00 00 00 79 F8 77 80 0B 80 AD 45 74 " + - "68 65 72 65 75 6D 28 2B 2B 29 2F 5A 65 72 6F 47 " + - "6F 78 2F 76 30 2E 34 2E 31 2F 6E 63 75 72 73 65 " + - "73 2F 4C 69 6E 75 78 2F 67 2B 2B 07 82 76 5F B8 " + - "40 D8 D6 0C 25 80 FA 79 5C FC 03 13 EF DE BA 86 " + - "9D 21 94 E7 9E 7C B2 B5 22 F7 82 FF A0 39 2C BB " + - "AB 8D 1B AC 30 12 08 B1 37 E0 DE 49 98 33 4F 3B " + - "CF 73 FA 11 7E F2 13 F8 74 17 08 9F EA F8 4C 21 " + - "B0 "; - - public static final String pingString = "22 40 08 91 00 00 00 02 C1 02 "; - public static final String pongString = "22 40 08 91 00 00 00 02 C1 03 "; - - public static final String getPeersString = "22 40 08 91 00 00 00 02 C1 10 "; - - public static final String getTransactions = "22 40 08 91 00 00 00 02 C1 16 "; - - public static final String getChain = "22 40 08 91 00 00 00 26 F8 24 14 " + - "AB 6B 9A 56 13 97 0F AA 77 1B 12 D4 49 B2 E9 BB 92 5A B7 A3 69 F0 A4 B8 6B 28 6E 9D 54 00 99 CF " + - "82 01 00 "; - - public static final String getTxString = "22 40 08 91 00 00 00 02 C1 16 "; - - - - public NioClient(InetAddress hostAddress, int port) throws IOException { - this.hostAddress = hostAddress; - this.port = port; - this.selector = this.initSelector(); - - // Start a new connection - this.socket = this.initiateConnection(); - - // Register the response handler - this.handler = new RspHandler(); - this.rspHandlers.put(socket, handler); - - } - - public void send(byte[] data) throws IOException { - - // And queue the data we want written - synchronized (this.pendingData) { - List queue = (List) this.pendingData.get(socket); - if (queue == null) { - queue = new ArrayList(); - this.pendingData.put(socket, queue); - } - queue.add(ByteBuffer.wrap(data)); - } - - // Finally, wake up our selecting thread so it can make the required changes - this.selector.wakeup(); - } - - public void run() { - - - while (true) { - try { - // Process any pending changes - synchronized (this.pendingChanges) { - Iterator changes = this.pendingChanges.iterator(); - while (changes.hasNext()) { - ChangeRequest change = (ChangeRequest) changes.next(); - - switch (change.type) { - case ChangeRequest.CHANGEOPS: - SelectionKey key = change.socket.keyFor(this.selector); - key.interestOps(change.ops); - break; - case ChangeRequest.REGISTER: - change.socket.register(this.selector, change.ops); - break; - } - } - this.pendingChanges.clear(); - } - - // Wait for an event one of the registered channels - // THIS ONE ACTUALLY BLOCKS AND SHOULD AWAKE WHEN SOME I/O HAPPENS - this.selector.select(); - - // Iterate over the set of keys for which events are available - Iterator selectedKeys = this.selector.selectedKeys().iterator(); - while (selectedKeys.hasNext()) { - SelectionKey key = (SelectionKey) selectedKeys.next(); - selectedKeys.remove(); - - if (!key.isValid()) { - continue; - } - - // Check what event is available and deal with it - if (key.isConnectable()) { - this.establishConnection(key); - } else if (key.isReadable()) { - this.read(key); - } else if (key.isWritable()) { - this.write(key); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private void read(SelectionKey key) throws IOException { - SocketChannel socketChannel = (SocketChannel) key.channel(); - - // Clear out our read buffer so it's ready for new data - this.readBuffer.clear(); - - // Attempt to read off the channel - int numRead; - try { - - numRead = socketChannel.read(this.readBuffer); - System.out.println("reading: " + numRead); -// key.interestOps(SelectionKey.OP_WRITE); - - } catch (IOException e) { - // The remote forcibly closed the connection, cancel - // the selection key and close the channel. - key.cancel(); - socketChannel.close(); - return; - } - - if (numRead == -1) { - // Remote entity shut the socket down cleanly. Do the - // same from our end and cancel the channel. -// key.channel().close(); -// key.cancel(); - - - return; - } - - // Handle the response - - - this.handleResponse(socketChannel, this.readBuffer.array(), numRead); - } - - private void handleResponse(SocketChannel socketChannel, byte[] data, int numRead) throws IOException { - - // Make a correctly sized copy of the data before handing it - // to the client - byte[] rspData = new byte[numRead]; - System.arraycopy(data, 0, rspData, 0, numRead); - - - - // Look up the handler for this channel - RspHandler handler = (RspHandler) this.rspHandlers.get(socketChannel); - - // And pass the response to it - if (handler.handleResponse(rspData)) { - // The handler has seen enough, close the connection -// socketChannel.close(); -// socketChannel.keyFor(this.selector).cancel(); - } - } - - private void write(SelectionKey key) throws IOException { - SocketChannel socketChannel = (SocketChannel) key.channel(); - - synchronized (this.pendingData) { - List queue = (List) this.pendingData.get(socketChannel); - - - // Write until there's not more data ... - while (queue != null && !queue.isEmpty()) { - ByteBuffer buf = (ByteBuffer) queue.get(0); - byte[] packet = buf.array(); - - System.out.print("write: "); - Utils.printHexStringForByteArray(packet); - - socketChannel.write(buf); - - if (buf.remaining() > 0) { - // ... or the socket's buffer fills up - break; - } - queue.remove(0); - } -// key.interestOps(SelectionKey.OP_READ); - - if (queue == null || queue.isEmpty()) { - // We wrote away all data, so we're no longer interested - // in writing on this socket. Switch back to waiting for - // data. - key.interestOps(SelectionKey.OP_READ); - } - } - } - - private void establishConnection(SelectionKey key) throws IOException { - SocketChannel socketChannel = (SocketChannel) key.channel(); - - // Finish the connection. If the connection operation failed - // this will raise an IOException. - try { - socketChannel.finishConnect(); - } catch (IOException e) { - // Cancel the channel's registration with our selector - System.out.println(e); - key.cancel(); - return; - } - - // Register an interest in writing on this channel - key.interestOps(SelectionKey.OP_WRITE); - } - - private SocketChannel initiateConnection() throws IOException { - // Create a non-blocking socket channel - SocketChannel socketChannel = SocketChannel.open(); - socketChannel.configureBlocking(false); - - // Kick off connection establishment - socketChannel.connect(new InetSocketAddress(this.hostAddress, this.port)); - - // Queue a channel registration since the caller is not the - // selecting thread. As part of the registration we'll register - // an interest in connection events. These are raised when a channel - // is ready to complete connection establishment. - synchronized(this.pendingChanges) { - this.pendingChanges.add(new ChangeRequest(socketChannel, - ChangeRequest.REGISTER, SelectionKey.OP_CONNECT)); - } - - return socketChannel; - } - - private Selector initSelector() throws IOException { - // Create a new selector - return SelectorProvider.provider().openSelector(); - } - - public static void main(String[] args) { - try { - - NioClient client = new NioClient(InetAddress.getByName("localhost"), 20202); - Thread t = new Thread(client, "ClientThread"); - t.setDaemon(true); - t.start(); - -// client.send(new byte[0]); -// client.handler.waitForResponse(); - Thread.sleep(2000); - - - System.out.println("\nsending HELLO"); - client.enableWriting(); -// client.send(hexStringToByteArr(helloString)); - Thread.sleep(100); - - System.out.println("\nsending PONG"); -// client.enableWriting(); -// client.send(hexStringToByteArr(pongString)); - - Thread.sleep(100); - System.out.println("\nsending GETCHAIN"); -// client.enableWriting(); -// client.send(hexStringToByteArr(getChain)); - - - - -// System.out.println("\nsending PING"); -// client.send(hexStringToByteArr(pingString)); -// client.handler.waitForResponse(); - - - System.out.println("SLEEPING"); - Thread.sleep(5000); - - client.handler.waitForResponse(); - -// System.out.println("\nsending GETCHAIN"); -// client.send(hexStringToByteArr(getChain)); -// client.handler.waitForResponse(); - - -// System.out.println("\nsending GETPEERS"); -// client.send(hexStringToByteArr(getPeersString)); -// client.handler.waitForResponse(); -// client.handler.waitForResponse(); - -// System.out.println("\nsending GETTRANSACTIONS"); -// client.send(hexStringToByteArr(getTransactions)); - - - System.out.println("\nsleeping 5 secs before death"); - - - Thread.sleep(5000); - - client.socket.close(); - - - - - -/* - client.send(hexStringToByteArr(helloString)); - client.handler.waitForResponse(); - - - System.out.println(""); - client.send(hexStringToByteArr(getPeersString)); - client.handler.waitForResponse(); - - - System.out.println(""); - client.handler.waitForResponse(); - - System.out.println(""); - client.handler.waitForResponse(); -*/ - - } catch (Exception e) { - e.printStackTrace(); - } - } - - - public static byte[] hexStringToByteArr(String hexString){ - - String hexSymbols = "0123456789ABCDEF"; - - int arrSize = (int) (hexString.length() / 3); - byte[] result = new byte[arrSize]; - - for (int i = 0; i < arrSize; ++i){ - - int digit1 = hexSymbols.indexOf( hexString.charAt(i * 3) ); - int digit2 = hexSymbols.indexOf( hexString.charAt(i * 3 + 1) ); - - result[i] = (byte) (digit1 * 16 + digit2); - } - - - return result; - } - - - public void enableWriting(){ - SelectionKey key = this.socket.keyFor(this.selector); - key.interestOps(SelectionKey.OP_WRITE | SelectionKey.OP_READ); - } - - public void enableOnlyReading(){ - SelectionKey key = this.socket.keyFor(this.selector); - key.interestOps(SelectionKey.OP_READ); - } - -} diff --git a/ethereumj-core/src/main/java/samples/niotut/NioServer.java b/ethereumj-core/src/main/java/samples/niotut/NioServer.java deleted file mode 100644 index 80860955..00000000 --- a/ethereumj-core/src/main/java/samples/niotut/NioServer.java +++ /dev/null @@ -1,213 +0,0 @@ -package samples.niotut; - - -/* BASED ON: http://rox-xmlrpc.sourceforge.net/niotut/#The client */ -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.nio.ByteBuffer; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.nio.channels.spi.SelectorProvider; -import java.util.*; - -public class NioServer implements Runnable { - // The host:port combination to listen on - private InetAddress hostAddress; - private int port; - - // The channel on which we'll accept connections - private ServerSocketChannel serverChannel; - - // The selector we'll be monitoring - private Selector selector; - - // The buffer into which we'll read data when it's available - private ByteBuffer readBuffer = ByteBuffer.allocate(8192); - - private EchoWorker worker; - - // A list of PendingChange instances - private List pendingChanges = new LinkedList(); - - // Maps a SocketChannel to a list of ByteBuffer instances - private Map pendingData = new HashMap(); - - public NioServer(InetAddress hostAddress, int port, EchoWorker worker) throws IOException { - this.hostAddress = hostAddress; - this.port = port; - this.selector = this.initSelector(); - this.worker = worker; - } - - public void send(SocketChannel socket, byte[] data) { - synchronized (this.pendingChanges) { - // Indicate we want the interest ops set changed - this.pendingChanges.add(new ChangeRequest(socket, ChangeRequest.CHANGEOPS, SelectionKey.OP_WRITE)); - - // And queue the data we want written - synchronized (this.pendingData) { - List queue = (List) this.pendingData.get(socket); - if (queue == null) { - queue = new ArrayList(); - this.pendingData.put(socket, queue); - } - queue.add(ByteBuffer.wrap(data)); - } - } - - // Finally, wake up our selecting thread so it can make the required changes - this.selector.wakeup(); - } - - public void run() { - while (true) { - try { - // Process any pending changes - synchronized (this.pendingChanges) { - Iterator changes = this.pendingChanges.iterator(); - while (changes.hasNext()) { - ChangeRequest change = (ChangeRequest) changes.next(); - switch (change.type) { - case ChangeRequest.CHANGEOPS: - SelectionKey key = change.socket.keyFor(this.selector); - key.interestOps(change.ops); - } - } - this.pendingChanges.clear(); - } - - // Wait for an event one of the registered channels - System.out.println("accepting"); - this.selector.select(); - - // Iterate over the set of keys for which events are available - Iterator selectedKeys = this.selector.selectedKeys().iterator(); - while (selectedKeys.hasNext()) { - SelectionKey key = (SelectionKey) selectedKeys.next(); - selectedKeys.remove(); - - if (!key.isValid()) { - continue; - } - - // Check what event is available and deal with it - if (key.isAcceptable()) { - System.out.println("new channel"); - this.accept(key); - } else if (key.isReadable()) { - System.out.println("reading"); - this.read(key); - } else if (key.isWritable()) { - System.out.println("writing"); - this.write(key); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private void accept(SelectionKey key) throws IOException { - // For an accept to be pending the channel must be a server socket channel. - ServerSocketChannel serverSocketChannel = (ServerSocketChannel) key.channel(); - - // Accept the connection and make it non-blocking - SocketChannel socketChannel = serverSocketChannel.accept(); - Socket socket = socketChannel.socket(); - socketChannel.configureBlocking(false); - - // Register the new SocketChannel with our Selector, indicating - // we'd like to be notified when there's data waiting to be read - socketChannel.register(this.selector, SelectionKey.OP_READ); - } - - private void read(SelectionKey key) throws IOException { - SocketChannel socketChannel = (SocketChannel) key.channel(); - - // Clear out our read buffer so it's ready for new data - this.readBuffer.clear(); - - // Attempt to read off the channel - int numRead; - try { - numRead = socketChannel.read(this.readBuffer); - } catch (IOException e) { - // The remote forcibly closed the connection, cancel - // the selection key and close the channel. - key.cancel(); - socketChannel.close(); - return; - } - - if (numRead == -1) { - // Remote entity shut the socket down cleanly. Do the - // same from our end and cancel the channel. - key.channel().close(); - key.cancel(); - return; - } - - // Hand the data off to our worker thread - this.worker.processData(this, socketChannel, this.readBuffer.array(), numRead); - } - - private void write(SelectionKey key) throws IOException { - SocketChannel socketChannel = (SocketChannel) key.channel(); - - synchronized (this.pendingData) { - List queue = (List) this.pendingData.get(socketChannel); - - // Write until there's not more data ... - while (!queue.isEmpty()) { - ByteBuffer buf = (ByteBuffer) queue.get(0); - socketChannel.write(buf); - if (buf.remaining() > 0) { - // ... or the socket's buffer fills up - break; - } - queue.remove(0); - } - - if (queue.isEmpty()) { - // We wrote away all data, so we're no longer interested - // in writing on this socket. Switch back to waiting for - // data. - key.interestOps(SelectionKey.OP_READ); - } - } - } - - private Selector initSelector() throws IOException { - // Create a new selector - Selector socketSelector = SelectorProvider.provider().openSelector(); - - // Create a new non-blocking server socket channel - this.serverChannel = ServerSocketChannel.open(); - serverChannel.configureBlocking(false); - - // Bind the server socket to the specified address and port - InetSocketAddress isa = new InetSocketAddress(this.hostAddress, this.port); - serverChannel.socket().bind(isa); - - // Register the server socket channel, indicating an interest in - // accepting new connections - serverChannel.register(socketSelector, SelectionKey.OP_ACCEPT); - - return socketSelector; - } - - public static void main(String[] args) { - try { - EchoWorker worker = new EchoWorker(); - new Thread(worker).start(); - new Thread(new NioServer(null, 9090, worker)).start(); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/ethereumj-core/src/main/java/samples/niotut/RspHandler.java b/ethereumj-core/src/main/java/samples/niotut/RspHandler.java deleted file mode 100644 index 55212e85..00000000 --- a/ethereumj-core/src/main/java/samples/niotut/RspHandler.java +++ /dev/null @@ -1,107 +0,0 @@ -package samples.niotut; - -import org.ethereum.net.RLP; -import org.ethereum.util.Utils; - -import java.util.LinkedList; -import java.util.Queue; - -public class RspHandler { - - public Queue packetsRecived = new LinkedList(); - - - public synchronized boolean handleResponse(byte[] rsp) { - - packetsRecived.add(rsp); - this.notify(); - return true; - } - - public synchronized void waitForResponse() { - - - while(packetsRecived.isEmpty()) { - try { - this.wait(); - } catch (InterruptedException e) { - } - } - - while (!packetsRecived.isEmpty()) { - - byte[] rsp = packetsRecived.remove(); - Utils.printHexStringForByteArray(rsp); - - - if (rsp.length < 9){ - // Can't be any ether packet - } - - boolean noMoreMessages = false; - - - // 22 40 08 91 - magic packet - if ((rsp[0] & 0xFF) == 0x22 && - (rsp[1] & 0xFF) == 0x40 && - (rsp[2] & 0xFF) == 0x08 && - (rsp[3] & 0xFF) == 0x91 ){ - - - // Got ethereum message - } - - - int numMessages = 0; - // count number of messages in the packet - for (int i = 0; i < rsp.length - 3; ++i){ - - if ( (rsp[i + 0] & 0xFF) == 0x22 && - (rsp[i + 1] & 0xFF) == 0x40 && - (rsp[i + 2] & 0xFF) == 0x08 && - (rsp[i + 3] & 0xFF) == 0x91 ){ - - ++numMessages; - } - } - - System.out.println("This packet contains: " + numMessages + " messages"); - - for (int i = 0; i < numMessages; ++i){ - - // Callc message length - int messageLength = ((rsp[4] & 0xFF) << 24) + - ((rsp[5] & 0xFF) << 16) + - ((rsp[6] & 0xFF) << 8) + - ((rsp[7] & 0xFF)); - - byte[] msgPayload = new byte[messageLength]; - - System.out.println("payload size: " + msgPayload.length ); - System.out.println("packet size: " + messageLength ); - System.arraycopy(rsp, 8, msgPayload, 0, messageLength); - - Utils.printHexStringForByteArray(msgPayload); - - - - - Queue index = new LinkedList(); - - RLP.fullTraverse(msgPayload, 0, 0, msgPayload.length, 1, index); - -// Message msg = MessageFactory.createMessage(msgPayload, index); -// System.out.println("msg: " + msg); - - // shift next message to the start of the packet array - if (i + 1 < numMessages){ - - System.arraycopy(rsp, msgPayload.length + 8, rsp, 0, rsp.length - msgPayload.length - 8); - - } - } - - System.out.println(); - } - } -} diff --git a/ethereumj-core/src/main/java/samples/niotut/ServerDataEvent.java b/ethereumj-core/src/main/java/samples/niotut/ServerDataEvent.java deleted file mode 100644 index acc1a0fe..00000000 --- a/ethereumj-core/src/main/java/samples/niotut/ServerDataEvent.java +++ /dev/null @@ -1,16 +0,0 @@ - -package samples.niotut; - -import java.nio.channels.SocketChannel; - -class ServerDataEvent { - public NioServer server; - public SocketChannel socket; - public byte[] data; - - public ServerDataEvent(NioServer server, SocketChannel socket, byte[] data) { - this.server = server; - this.socket = socket; - this.data = data; - } -} \ No newline at end of file diff --git a/ethereumj-core/src/main/java/samples/stg/Bytecode.stg b/ethereumj-core/src/main/java/samples/stg/Bytecode.stg deleted file mode 100644 index 86769cad..00000000 --- a/ethereumj-core/src/main/java/samples/stg/Bytecode.stg +++ /dev/null @@ -1,74 +0,0 @@ -group Bytecode; - -program(globals,functions) ::= << -.class public Wrapper -.super java/lang/Object - - ->> - -variable(type,name) ::= ".var is <\n>" - -globalVariable(type,name) ::= ".field <\n>" - -function(type,name,args,locals,stats) ::= << -.method (}>) - - - return -.end method ->> - -type_int() ::= "I" - -type_char() ::= "C" - -type_user_object(name) ::= "L;" - -parameter(type,name) ::= " " - -statement(expr) ::= "" - -statementList(locals,stats) ::= << - - ->> - -forLoop(e1,e2,e3,locals,stats) ::= << - -start: - -bf exit - - - -goto start -exit: ->> - -assign(lhs,rhs) ::= << - -store ->> - - -equals(left,right) ::= << - - -equals ->> - -lessThan(left,right) ::= << - - -lt ->> - -add(left,right) ::= << - - -add ->> - -refVar(id) ::= "push " -iconst(value) ::= "iconst " diff --git a/ethereumj-core/src/main/java/samples/stg/CMinus.g b/ethereumj-core/src/main/java/samples/stg/CMinus.g deleted file mode 100644 index 37322b3e..00000000 --- a/ethereumj-core/src/main/java/samples/stg/CMinus.g +++ /dev/null @@ -1,152 +0,0 @@ -grammar CMinus; -options {output=template;} - -scope slist { - List locals; // must be defined one per semicolon - List stats; -} - -/* -@slist::init { - locals = new ArrayList(); - stats = new ArrayList(); -} -*/ - -@header { -package samples.stg; -import org.antlr.stringtemplate.*; -} - -@lexer::header { -package samples.stg; -} - - -program -scope { - List globals; - List functions; -} -@init { - $program::globals = new ArrayList(); - $program::functions = new ArrayList(); -} - : declaration+ - -> program(globals={$program::globals},functions={$program::functions}) - ; - -declaration - : variable {$program::globals.add($variable.st);} - | f=function {$program::functions.add($f.st);} - ; - -// ack is $function.st ambig? It can mean the rule's dyn scope or -// the ref in this rule. Ack. - -variable - : type declarator ';' - -> {$function.size()>0 && $function::name==null}? - globalVariable(type={$type.st},name={$declarator.st}) - -> variable(type={$type.st},name={$declarator.st}) - ; - -declarator - : ID -> {new StringTemplate($ID.text)} - ; - -function -scope { - String name; -} -scope slist; -@init { - $slist::locals = new ArrayList(); - $slist::stats = new ArrayList(); -} - : type ID {$function::name=$ID.text;} - '(' ( p+=formalParameter ( ',' p+=formalParameter )* )? ')' - block - -> function(type={$type.st}, name={$function::name}, - locals={$slist::locals}, - stats={$slist::stats}, - args={$p}) - ; - -formalParameter - : type declarator - -> parameter(type={$type.st},name={$declarator.st}) - ; - -type - : 'int' -> type_int() - | 'char' -> type_char() - | ID -> type_user_object(name={$ID.text}) - ; - -block - : '{' - ( variable {$slist::locals.add($variable.st);} )* - ( stat {$slist::stats.add($stat.st);})* - '}' - ; - -stat -scope slist; -@init { - $slist::locals = new ArrayList(); - $slist::stats = new ArrayList(); -} - : forStat -> {$forStat.st} - | expr ';' -> statement(expr={$expr.st}) - | block -> statementList(locals={$slist::locals}, stats={$slist::stats}) - | assignStat ';' -> {$assignStat.st} - | ';' -> {new StringTemplate(";")} - ; - -forStat -scope slist; -@init { - $slist::locals = new ArrayList(); - $slist::stats = new ArrayList(); -} - : 'for' '(' e1=assignStat ';' e2=expr ';' e3=assignStat ')' block - -> forLoop(e1={$e1.st},e2={$e2.st},e3={$e3.st}, - locals={$slist::locals}, stats={$slist::stats}) - ; - -assignStat - : ID '=' expr -> assign(lhs={$ID.text}, rhs={$expr.st}) - ; - -expr: condExpr -> {$condExpr.st} - ; - -condExpr - : a=aexpr - ( ( '==' b=aexpr -> equals(left={$a.st},right={$b.st}) - | '<' b=aexpr -> lessThan(left={$a.st},right={$b.st}) - ) - | -> {$a.st} // else just aexpr - ) - ; - -aexpr - : (a=atom -> {$a.st}) - ( '+' b=atom -> add(left={$aexpr.st}, right={$b.st}) )* - ; - -atom - : ID -> refVar(id={$ID.text}) - | INT -> iconst(value={$INT.text}) - | '(' expr ')' -> {$expr.st} - ; - -ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* - ; - -INT : ('0'..'9')+ - ; - -WS : (' ' | '\t' | '\r' | '\n')+ {$channel=HIDDEN;} - ; diff --git a/ethereumj-core/src/main/java/samples/stg/CMinusLexer.java b/ethereumj-core/src/main/java/samples/stg/CMinusLexer.java deleted file mode 100644 index 151bc94c..00000000 --- a/ethereumj-core/src/main/java/samples/stg/CMinusLexer.java +++ /dev/null @@ -1,824 +0,0 @@ -// $ANTLR 3.5.2 E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g 2014-04-27 13:24:16 - -package samples.stg; - - -import org.antlr.runtime.*; -import java.util.Stack; -import java.util.List; -import java.util.ArrayList; - -@SuppressWarnings("all") -public class CMinusLexer extends Lexer { - public static final int EOF=-1; - public static final int T__7=7; - public static final int T__8=8; - public static final int T__9=9; - public static final int T__10=10; - public static final int T__11=11; - public static final int T__12=12; - public static final int T__13=13; - public static final int T__14=14; - public static final int T__15=15; - public static final int T__16=16; - public static final int T__17=17; - public static final int T__18=18; - public static final int T__19=19; - public static final int ID=4; - public static final int INT=5; - public static final int WS=6; - - // delegates - // delegators - public Lexer[] getDelegates() { - return new Lexer[] {}; - } - - public CMinusLexer() {} - public CMinusLexer(CharStream input) { - this(input, new RecognizerSharedState()); - } - public CMinusLexer(CharStream input, RecognizerSharedState state) { - super(input,state); - } - @Override public String getGrammarFileName() { return "E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g"; } - - // $ANTLR start "T__7" - public final void mT__7() throws RecognitionException { - try { - int _type = T__7; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:6:6: ( '(' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:6:8: '(' - { - match('('); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__7" - - // $ANTLR start "T__8" - public final void mT__8() throws RecognitionException { - try { - int _type = T__8; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:7:6: ( ')' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:7:8: ')' - { - match(')'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__8" - - // $ANTLR start "T__9" - public final void mT__9() throws RecognitionException { - try { - int _type = T__9; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:8:6: ( '+' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:8:8: '+' - { - match('+'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__9" - - // $ANTLR start "T__10" - public final void mT__10() throws RecognitionException { - try { - int _type = T__10; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:9:7: ( ',' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:9:9: ',' - { - match(','); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__10" - - // $ANTLR start "T__11" - public final void mT__11() throws RecognitionException { - try { - int _type = T__11; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:10:7: ( ';' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:10:9: ';' - { - match(';'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__11" - - // $ANTLR start "T__12" - public final void mT__12() throws RecognitionException { - try { - int _type = T__12; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:11:7: ( '<' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:11:9: '<' - { - match('<'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__12" - - // $ANTLR start "T__13" - public final void mT__13() throws RecognitionException { - try { - int _type = T__13; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:12:7: ( '=' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:12:9: '=' - { - match('='); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__13" - - // $ANTLR start "T__14" - public final void mT__14() throws RecognitionException { - try { - int _type = T__14; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:13:7: ( '==' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:13:9: '==' - { - match("=="); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__14" - - // $ANTLR start "T__15" - public final void mT__15() throws RecognitionException { - try { - int _type = T__15; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:14:7: ( 'char' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:14:9: 'char' - { - match("char"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__15" - - // $ANTLR start "T__16" - public final void mT__16() throws RecognitionException { - try { - int _type = T__16; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:15:7: ( 'for' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:15:9: 'for' - { - match("for"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__16" - - // $ANTLR start "T__17" - public final void mT__17() throws RecognitionException { - try { - int _type = T__17; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:16:7: ( 'int' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:16:9: 'int' - { - match("int"); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__17" - - // $ANTLR start "T__18" - public final void mT__18() throws RecognitionException { - try { - int _type = T__18; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:17:7: ( '{' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:17:9: '{' - { - match('{'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__18" - - // $ANTLR start "T__19" - public final void mT__19() throws RecognitionException { - try { - int _type = T__19; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:18:7: ( '}' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:18:9: '}' - { - match('}'); - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "T__19" - - // $ANTLR start "ID" - public final void mID() throws RecognitionException { - try { - int _type = ID; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:145:5: ( ( 'a' .. 'z' | 'A' .. 'Z' | '_' ) ( 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' )* ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:145:9: ( 'a' .. 'z' | 'A' .. 'Z' | '_' ) ( 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' )* - { - if ( (input.LA(1) >= 'A' && input.LA(1) <= 'Z')||input.LA(1)=='_'||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:145:33: ( 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' )* - loop1: - while (true) { - int alt1=2; - int LA1_0 = input.LA(1); - if ( ((LA1_0 >= '0' && LA1_0 <= '9')||(LA1_0 >= 'A' && LA1_0 <= 'Z')||LA1_0=='_'||(LA1_0 >= 'a' && LA1_0 <= 'z')) ) { - alt1=1; - } - - switch (alt1) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g: - { - if ( (input.LA(1) >= '0' && input.LA(1) <= '9')||(input.LA(1) >= 'A' && input.LA(1) <= 'Z')||input.LA(1)=='_'||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - break; - - default : - break loop1; - } - } - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "ID" - - // $ANTLR start "INT" - public final void mINT() throws RecognitionException { - try { - int _type = INT; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:148:5: ( ( '0' .. '9' )+ ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:148:7: ( '0' .. '9' )+ - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:148:7: ( '0' .. '9' )+ - int cnt2=0; - loop2: - while (true) { - int alt2=2; - int LA2_0 = input.LA(1); - if ( ((LA2_0 >= '0' && LA2_0 <= '9')) ) { - alt2=1; - } - - switch (alt2) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g: - { - if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - break; - - default : - if ( cnt2 >= 1 ) break loop2; - EarlyExitException eee = new EarlyExitException(2, input); - throw eee; - } - cnt2++; - } - - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "INT" - - // $ANTLR start "WS" - public final void mWS() throws RecognitionException { - try { - int _type = WS; - int _channel = DEFAULT_TOKEN_CHANNEL; - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:151:5: ( ( ' ' | '\\t' | '\\r' | '\\n' )+ ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:151:9: ( ' ' | '\\t' | '\\r' | '\\n' )+ - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:151:9: ( ' ' | '\\t' | '\\r' | '\\n' )+ - int cnt3=0; - loop3: - while (true) { - int alt3=2; - int LA3_0 = input.LA(1); - if ( ((LA3_0 >= '\t' && LA3_0 <= '\n')||LA3_0=='\r'||LA3_0==' ') ) { - alt3=1; - } - - switch (alt3) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g: - { - if ( (input.LA(1) >= '\t' && input.LA(1) <= '\n')||input.LA(1)=='\r'||input.LA(1)==' ' ) { - input.consume(); - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse; - } - } - break; - - default : - if ( cnt3 >= 1 ) break loop3; - EarlyExitException eee = new EarlyExitException(3, input); - throw eee; - } - cnt3++; - } - - _channel=HIDDEN; - } - - state.type = _type; - state.channel = _channel; - } - finally { - // do for sure before leaving - } - } - // $ANTLR end "WS" - - @Override - public void mTokens() throws RecognitionException { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:8: ( T__7 | T__8 | T__9 | T__10 | T__11 | T__12 | T__13 | T__14 | T__15 | T__16 | T__17 | T__18 | T__19 | ID | INT | WS ) - int alt4=16; - switch ( input.LA(1) ) { - case '(': - { - alt4=1; - } - break; - case ')': - { - alt4=2; - } - break; - case '+': - { - alt4=3; - } - break; - case ',': - { - alt4=4; - } - break; - case ';': - { - alt4=5; - } - break; - case '<': - { - alt4=6; - } - break; - case '=': - { - int LA4_7 = input.LA(2); - if ( (LA4_7=='=') ) { - alt4=8; - } - - else { - alt4=7; - } - - } - break; - case 'c': - { - int LA4_8 = input.LA(2); - if ( (LA4_8=='h') ) { - int LA4_18 = input.LA(3); - if ( (LA4_18=='a') ) { - int LA4_21 = input.LA(4); - if ( (LA4_21=='r') ) { - int LA4_24 = input.LA(5); - if ( ((LA4_24 >= '0' && LA4_24 <= '9')||(LA4_24 >= 'A' && LA4_24 <= 'Z')||LA4_24=='_'||(LA4_24 >= 'a' && LA4_24 <= 'z')) ) { - alt4=14; - } - - else { - alt4=9; - } - - } - - else { - alt4=14; - } - - } - - else { - alt4=14; - } - - } - - else { - alt4=14; - } - - } - break; - case 'f': - { - int LA4_9 = input.LA(2); - if ( (LA4_9=='o') ) { - int LA4_19 = input.LA(3); - if ( (LA4_19=='r') ) { - int LA4_22 = input.LA(4); - if ( ((LA4_22 >= '0' && LA4_22 <= '9')||(LA4_22 >= 'A' && LA4_22 <= 'Z')||LA4_22=='_'||(LA4_22 >= 'a' && LA4_22 <= 'z')) ) { - alt4=14; - } - - else { - alt4=10; - } - - } - - else { - alt4=14; - } - - } - - else { - alt4=14; - } - - } - break; - case 'i': - { - int LA4_10 = input.LA(2); - if ( (LA4_10=='n') ) { - int LA4_20 = input.LA(3); - if ( (LA4_20=='t') ) { - int LA4_23 = input.LA(4); - if ( ((LA4_23 >= '0' && LA4_23 <= '9')||(LA4_23 >= 'A' && LA4_23 <= 'Z')||LA4_23=='_'||(LA4_23 >= 'a' && LA4_23 <= 'z')) ) { - alt4=14; - } - - else { - alt4=11; - } - - } - - else { - alt4=14; - } - - } - - else { - alt4=14; - } - - } - break; - case '{': - { - alt4=12; - } - break; - case '}': - { - alt4=13; - } - break; - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - case 'a': - case 'b': - case 'd': - case 'e': - case 'g': - case 'h': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': - { - alt4=14; - } - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - { - alt4=15; - } - break; - case '\t': - case '\n': - case '\r': - case ' ': - { - alt4=16; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 4, 0, input); - throw nvae; - } - switch (alt4) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:10: T__7 - { - mT__7(); - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:15: T__8 - { - mT__8(); - - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:20: T__9 - { - mT__9(); - - } - break; - case 4 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:25: T__10 - { - mT__10(); - - } - break; - case 5 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:31: T__11 - { - mT__11(); - - } - break; - case 6 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:37: T__12 - { - mT__12(); - - } - break; - case 7 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:43: T__13 - { - mT__13(); - - } - break; - case 8 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:49: T__14 - { - mT__14(); - - } - break; - case 9 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:55: T__15 - { - mT__15(); - - } - break; - case 10 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:61: T__16 - { - mT__16(); - - } - break; - case 11 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:67: T__17 - { - mT__17(); - - } - break; - case 12 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:73: T__18 - { - mT__18(); - - } - break; - case 13 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:79: T__19 - { - mT__19(); - - } - break; - case 14 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:85: ID - { - mID(); - - } - break; - case 15 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:88: INT - { - mINT(); - - } - break; - case 16 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:1:92: WS - { - mWS(); - - } - break; - - } - } - - - -} diff --git a/ethereumj-core/src/main/java/samples/stg/CMinusParser.java b/ethereumj-core/src/main/java/samples/stg/CMinusParser.java deleted file mode 100644 index 15ebaad4..00000000 --- a/ethereumj-core/src/main/java/samples/stg/CMinusParser.java +++ /dev/null @@ -1,1574 +0,0 @@ -// $ANTLR 3.5.2 E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g 2014-04-27 13:24:16 - -package samples.stg; -import org.antlr.stringtemplate.*; - - -import org.antlr.runtime.*; -import java.util.Stack; -import java.util.List; -import java.util.ArrayList; - -import org.antlr.stringtemplate.*; -import org.antlr.stringtemplate.language.*; -import java.util.HashMap; -@SuppressWarnings("all") -public class CMinusParser extends Parser { - public static final String[] tokenNames = new String[] { - "", "", "", "", "ID", "INT", "WS", "'('", "')'", - "'+'", "','", "';'", "'<'", "'='", "'=='", "'char'", "'for'", "'int'", - "'{'", "'}'" - }; - public static final int EOF=-1; - public static final int T__7=7; - public static final int T__8=8; - public static final int T__9=9; - public static final int T__10=10; - public static final int T__11=11; - public static final int T__12=12; - public static final int T__13=13; - public static final int T__14=14; - public static final int T__15=15; - public static final int T__16=16; - public static final int T__17=17; - public static final int T__18=18; - public static final int T__19=19; - public static final int ID=4; - public static final int INT=5; - public static final int WS=6; - - // delegates - public Parser[] getDelegates() { - return new Parser[] {}; - } - - // delegators - - protected static class slist_scope { - List locals; - List stats; - } - protected Stack slist_stack = new Stack(); - - - public CMinusParser(TokenStream input) { - this(input, new RecognizerSharedState()); - } - public CMinusParser(TokenStream input, RecognizerSharedState state) { - super(input, state); - } - - protected StringTemplateGroup templateLib = - new StringTemplateGroup("CMinusParserTemplates", AngleBracketTemplateLexer.class); - - public void setTemplateLib(StringTemplateGroup templateLib) { - this.templateLib = templateLib; - } - public StringTemplateGroup getTemplateLib() { - return templateLib; - } - /** allows convenient multi-value initialization: - * "new STAttrMap().put(...).put(...)" - */ - @SuppressWarnings("serial") - public static class STAttrMap extends HashMap { - public STAttrMap put(String attrName, Object value) { - super.put(attrName, value); - return this; - } - } - @Override public String[] getTokenNames() { return CMinusParser.tokenNames; } - @Override public String getGrammarFileName() { return "E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g"; } - - - protected static class program_scope { - List globals; - List functions; - } - protected Stack program_stack = new Stack(); - - public static class program_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "program" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:26:1: program : ( declaration )+ -> program(globals=$program::globalsfunctions=$program::functions); - public final program_return program() throws RecognitionException { - program_stack.push(new program_scope()); - program_return retval = new program_return(); - retval.start = input.LT(1); - - - program_stack.peek().globals = new ArrayList(); - program_stack.peek().functions = new ArrayList(); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:35:5: ( ( declaration )+ -> program(globals=$program::globalsfunctions=$program::functions)) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:35:9: ( declaration )+ - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:35:9: ( declaration )+ - int cnt1=0; - loop1: - while (true) { - int alt1=2; - int LA1_0 = input.LA(1); - if ( (LA1_0==ID||LA1_0==15||LA1_0==17) ) { - alt1=1; - } - - switch (alt1) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:35:9: declaration - { - pushFollow(FOLLOW_declaration_in_program58); - declaration(); - state._fsp--; - - } - break; - - default : - if ( cnt1 >= 1 ) break loop1; - EarlyExitException eee = new EarlyExitException(1, input); - throw eee; - } - cnt1++; - } - - // TEMPLATE REWRITE - // 36:9: -> program(globals=$program::globalsfunctions=$program::functions) - { - retval.st = templateLib.getInstanceOf("program",new STAttrMap().put("globals", program_stack.peek().globals).put("functions", program_stack.peek().functions)); - } - - - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - program_stack.pop(); - } - return retval; - } - // $ANTLR end "program" - - - public static class declaration_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "declaration" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:39:1: declaration : ( variable |f= function ); - public final declaration_return declaration() throws RecognitionException { - declaration_return retval = new declaration_return(); - retval.start = input.LT(1); - - ParserRuleReturnScope f =null; - ParserRuleReturnScope variable1 =null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:40:5: ( variable |f= function ) - int alt2=2; - switch ( input.LA(1) ) { - case 17: - { - int LA2_1 = input.LA(2); - if ( (LA2_1==ID) ) { - int LA2_4 = input.LA(3); - if ( (LA2_4==11) ) { - alt2=1; - } - else if ( (LA2_4==7) ) { - alt2=2; - } - - else { - int nvaeMark = input.mark(); - try { - for (int nvaeConsume = 0; nvaeConsume < 3 - 1; nvaeConsume++) { - input.consume(); - } - NoViableAltException nvae = - new NoViableAltException("", 2, 4, input); - throw nvae; - } finally { - input.rewind(nvaeMark); - } - } - - } - - else { - int nvaeMark = input.mark(); - try { - input.consume(); - NoViableAltException nvae = - new NoViableAltException("", 2, 1, input); - throw nvae; - } finally { - input.rewind(nvaeMark); - } - } - - } - break; - case 15: - { - int LA2_2 = input.LA(2); - if ( (LA2_2==ID) ) { - int LA2_4 = input.LA(3); - if ( (LA2_4==11) ) { - alt2=1; - } - else if ( (LA2_4==7) ) { - alt2=2; - } - - else { - int nvaeMark = input.mark(); - try { - for (int nvaeConsume = 0; nvaeConsume < 3 - 1; nvaeConsume++) { - input.consume(); - } - NoViableAltException nvae = - new NoViableAltException("", 2, 4, input); - throw nvae; - } finally { - input.rewind(nvaeMark); - } - } - - } - - else { - int nvaeMark = input.mark(); - try { - input.consume(); - NoViableAltException nvae = - new NoViableAltException("", 2, 2, input); - throw nvae; - } finally { - input.rewind(nvaeMark); - } - } - - } - break; - case ID: - { - int LA2_3 = input.LA(2); - if ( (LA2_3==ID) ) { - int LA2_4 = input.LA(3); - if ( (LA2_4==11) ) { - alt2=1; - } - else if ( (LA2_4==7) ) { - alt2=2; - } - - else { - int nvaeMark = input.mark(); - try { - for (int nvaeConsume = 0; nvaeConsume < 3 - 1; nvaeConsume++) { - input.consume(); - } - NoViableAltException nvae = - new NoViableAltException("", 2, 4, input); - throw nvae; - } finally { - input.rewind(nvaeMark); - } - } - - } - - else { - int nvaeMark = input.mark(); - try { - input.consume(); - NoViableAltException nvae = - new NoViableAltException("", 2, 3, input); - throw nvae; - } finally { - input.rewind(nvaeMark); - } - } - - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 2, 0, input); - throw nvae; - } - switch (alt2) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:40:9: variable - { - pushFollow(FOLLOW_variable_in_declaration99); - variable1=variable(); - state._fsp--; - - program_stack.peek().globals.add((variable1!=null?((StringTemplate)variable1.getTemplate()):null)); - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:41:9: f= function - { - pushFollow(FOLLOW_function_in_declaration115); - f=function(); - state._fsp--; - - program_stack.peek().functions.add((f!=null?((StringTemplate)f.getTemplate()):null)); - } - break; - - } - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "declaration" - - - public static class variable_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "variable" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:47:1: variable : type declarator ';' -> {$function.size()>0 && $function::name==null}? globalVariable(type=$type.stname=$declarator.st) -> variable(type=$type.stname=$declarator.st); - public final variable_return variable() throws RecognitionException { - variable_return retval = new variable_return(); - retval.start = input.LT(1); - - ParserRuleReturnScope type2 =null; - ParserRuleReturnScope declarator3 =null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:48:5: ( type declarator ';' -> {$function.size()>0 && $function::name==null}? globalVariable(type=$type.stname=$declarator.st) -> variable(type=$type.stname=$declarator.st)) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:48:9: type declarator ';' - { - pushFollow(FOLLOW_type_in_variable139); - type2=type(); - state._fsp--; - - pushFollow(FOLLOW_declarator_in_variable141); - declarator3=declarator(); - state._fsp--; - - match(input,11,FOLLOW_11_in_variable143); - // TEMPLATE REWRITE - // 49:9: -> {$function.size()>0 && $function::name==null}? globalVariable(type=$type.stname=$declarator.st) - if (function_stack.size()>0 && function_stack.peek().name==null) { - retval.st = templateLib.getInstanceOf("globalVariable",new STAttrMap().put("type", (type2!=null?((StringTemplate)type2.getTemplate()):null)).put("name", (declarator3!=null?((StringTemplate)declarator3.getTemplate()):null))); - } - - else // 51:9: -> variable(type=$type.stname=$declarator.st) - { - retval.st = templateLib.getInstanceOf("variable",new STAttrMap().put("type", (type2!=null?((StringTemplate)type2.getTemplate()):null)).put("name", (declarator3!=null?((StringTemplate)declarator3.getTemplate()):null))); - } - - - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "variable" - - - public static class declarator_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "declarator" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:54:1: declarator : ID -> {new StringTemplate($ID.text)}; - public final declarator_return declarator() throws RecognitionException { - declarator_return retval = new declarator_return(); - retval.start = input.LT(1); - - Token ID4=null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:55:5: ( ID -> {new StringTemplate($ID.text)}) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:55:9: ID - { - ID4=(Token)match(input,ID,FOLLOW_ID_in_declarator217); - // TEMPLATE REWRITE - // 55:12: -> {new StringTemplate($ID.text)} - { - retval.st = new StringTemplate((ID4!=null?ID4.getText():null)); - } - - - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "declarator" - - - protected static class function_scope { - String name; - } - protected Stack function_stack = new Stack(); - - public static class function_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "function" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:58:1: function : type ID '(' (p+= formalParameter ( ',' p+= formalParameter )* )? ')' block -> function(type=$type.stname=$function::namelocals=$slist::localsstats=$slist::statsargs=$p); - public final function_return function() throws RecognitionException { - slist_stack.push(new slist_scope()); - function_stack.push(new function_scope()); - function_return retval = new function_return(); - retval.start = input.LT(1); - - Token ID5=null; - List list_p=null; - ParserRuleReturnScope type6 =null; - RuleReturnScope p = null; - - slist_stack.peek().locals = new ArrayList(); - slist_stack.peek().stats = new ArrayList(); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:67:5: ( type ID '(' (p+= formalParameter ( ',' p+= formalParameter )* )? ')' block -> function(type=$type.stname=$function::namelocals=$slist::localsstats=$slist::statsargs=$p)) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:67:9: type ID '(' (p+= formalParameter ( ',' p+= formalParameter )* )? ')' block - { - pushFollow(FOLLOW_type_in_function254); - type6=type(); - state._fsp--; - - ID5=(Token)match(input,ID,FOLLOW_ID_in_function256); - function_stack.peek().name =(ID5!=null?ID5.getText():null); - match(input,7,FOLLOW_7_in_function268); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:68:13: (p+= formalParameter ( ',' p+= formalParameter )* )? - int alt4=2; - int LA4_0 = input.LA(1); - if ( (LA4_0==ID||LA4_0==15||LA4_0==17) ) { - alt4=1; - } - switch (alt4) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:68:15: p+= formalParameter ( ',' p+= formalParameter )* - { - pushFollow(FOLLOW_formalParameter_in_function274); - p=formalParameter(); - state._fsp--; - - if (list_p==null) list_p=new ArrayList(); - list_p.add(p.getTemplate()); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:68:34: ( ',' p+= formalParameter )* - loop3: - while (true) { - int alt3=2; - int LA3_0 = input.LA(1); - if ( (LA3_0==10) ) { - alt3=1; - } - - switch (alt3) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:68:36: ',' p+= formalParameter - { - match(input,10,FOLLOW_10_in_function278); - pushFollow(FOLLOW_formalParameter_in_function282); - p=formalParameter(); - state._fsp--; - - if (list_p==null) list_p=new ArrayList(); - list_p.add(p.getTemplate()); - } - break; - - default : - break loop3; - } - } - - } - break; - - } - - match(input,8,FOLLOW_8_in_function290); - pushFollow(FOLLOW_block_in_function300); - block(); - state._fsp--; - - // TEMPLATE REWRITE - // 70:9: -> function(type=$type.stname=$function::namelocals=$slist::localsstats=$slist::statsargs=$p) - { - retval.st = templateLib.getInstanceOf("function",new STAttrMap().put("type", (type6!=null?((StringTemplate)type6.getTemplate()):null)).put("name", function_stack.peek().name).put("locals", slist_stack.peek().locals).put("stats", slist_stack.peek().stats).put("args", list_p)); - } - - - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - slist_stack.pop(); - function_stack.pop(); - } - return retval; - } - // $ANTLR end "function" - - - public static class formalParameter_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "formalParameter" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:76:1: formalParameter : type declarator -> parameter(type=$type.stname=$declarator.st); - public final formalParameter_return formalParameter() throws RecognitionException { - formalParameter_return retval = new formalParameter_return(); - retval.start = input.LT(1); - - ParserRuleReturnScope type7 =null; - ParserRuleReturnScope declarator8 =null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:77:5: ( type declarator -> parameter(type=$type.stname=$declarator.st)) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:77:9: type declarator - { - pushFollow(FOLLOW_type_in_formalParameter416); - type7=type(); - state._fsp--; - - pushFollow(FOLLOW_declarator_in_formalParameter418); - declarator8=declarator(); - state._fsp--; - - // TEMPLATE REWRITE - // 78:9: -> parameter(type=$type.stname=$declarator.st) - { - retval.st = templateLib.getInstanceOf("parameter",new STAttrMap().put("type", (type7!=null?((StringTemplate)type7.getTemplate()):null)).put("name", (declarator8!=null?((StringTemplate)declarator8.getTemplate()):null))); - } - - - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "formalParameter" - - - public static class type_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "type" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:81:1: type : ( 'int' -> type_int(| 'char' -> type_char(| ID -> type_user_object(name=$ID.text)); - public final type_return type() throws RecognitionException { - type_return retval = new type_return(); - retval.start = input.LT(1); - - Token ID9=null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:82:5: ( 'int' -> type_int(| 'char' -> type_char(| ID -> type_user_object(name=$ID.text)) - int alt5=3; - switch ( input.LA(1) ) { - case 17: - { - alt5=1; - } - break; - case 15: - { - alt5=2; - } - break; - case ID: - { - alt5=3; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 5, 0, input); - throw nvae; - } - switch (alt5) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:82:9: 'int' - { - match(input,17,FOLLOW_17_in_type459); - // TEMPLATE REWRITE - // 82:16: -> type_int( - { - retval.st = templateLib.getInstanceOf("type_int"); - } - - - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:83:9: 'char' - { - match(input,15,FOLLOW_15_in_type476); - // TEMPLATE REWRITE - // 83:16: -> type_char( - { - retval.st = templateLib.getInstanceOf("type_char"); - } - - - - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:84:9: ID - { - ID9=(Token)match(input,ID,FOLLOW_ID_in_type492); - // TEMPLATE REWRITE - // 84:16: -> type_user_object(name=$ID.text) - { - retval.st = templateLib.getInstanceOf("type_user_object",new STAttrMap().put("name", (ID9!=null?ID9.getText():null))); - } - - - - } - break; - - } - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "type" - - - public static class block_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "block" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:87:1: block : '{' ( variable )* ( stat )* '}' ; - public final block_return block() throws RecognitionException { - block_return retval = new block_return(); - retval.start = input.LT(1); - - ParserRuleReturnScope variable10 =null; - ParserRuleReturnScope stat11 =null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:88:5: ( '{' ( variable )* ( stat )* '}' ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:88:8: '{' ( variable )* ( stat )* '}' - { - match(input,18,FOLLOW_18_in_block523); - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:89:8: ( variable )* - loop6: - while (true) { - int alt6=2; - int LA6_0 = input.LA(1); - if ( (LA6_0==ID) ) { - int LA6_2 = input.LA(2); - if ( (LA6_2==ID) ) { - alt6=1; - } - - } - else if ( (LA6_0==15||LA6_0==17) ) { - alt6=1; - } - - switch (alt6) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:89:10: variable - { - pushFollow(FOLLOW_variable_in_block534); - variable10=variable(); - state._fsp--; - - slist_stack.peek().locals.add((variable10!=null?((StringTemplate)variable10.getTemplate()):null)); - } - break; - - default : - break loop6; - } - } - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:90:8: ( stat )* - loop7: - while (true) { - int alt7=2; - int LA7_0 = input.LA(1); - if ( ((LA7_0 >= ID && LA7_0 <= INT)||LA7_0==7||LA7_0==11||LA7_0==16||LA7_0==18) ) { - alt7=1; - } - - switch (alt7) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:90:10: stat - { - pushFollow(FOLLOW_stat_in_block550); - stat11=stat(); - state._fsp--; - - slist_stack.peek().stats.add((stat11!=null?((StringTemplate)stat11.getTemplate()):null)); - } - break; - - default : - break loop7; - } - } - - match(input,19,FOLLOW_19_in_block563); - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "block" - - - public static class stat_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "stat" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:94:1: stat : ( forStat -> {$forStat.st}| expr ';' -> statement(expr=$expr.st)| block -> statementList(locals=$slist::localsstats=$slist::stats)| assignStat ';' -> {$assignStat.st}| ';' -> {new StringTemplate(\";\")}); - public final stat_return stat() throws RecognitionException { - slist_stack.push(new slist_scope()); - - stat_return retval = new stat_return(); - retval.start = input.LT(1); - - ParserRuleReturnScope forStat12 =null; - ParserRuleReturnScope expr13 =null; - ParserRuleReturnScope assignStat14 =null; - - - slist_stack.peek().locals = new ArrayList(); - slist_stack.peek().stats = new ArrayList(); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:100:5: ( forStat -> {$forStat.st}| expr ';' -> statement(expr=$expr.st)| block -> statementList(locals=$slist::localsstats=$slist::stats)| assignStat ';' -> {$assignStat.st}| ';' -> {new StringTemplate(\";\")}) - int alt8=5; - switch ( input.LA(1) ) { - case 16: - { - alt8=1; - } - break; - case ID: - { - int LA8_2 = input.LA(2); - if ( (LA8_2==13) ) { - alt8=4; - } - else if ( (LA8_2==9||(LA8_2 >= 11 && LA8_2 <= 12)||LA8_2==14) ) { - alt8=2; - } - - else { - int nvaeMark = input.mark(); - try { - input.consume(); - NoViableAltException nvae = - new NoViableAltException("", 8, 2, input); - throw nvae; - } finally { - input.rewind(nvaeMark); - } - } - - } - break; - case INT: - case 7: - { - alt8=2; - } - break; - case 18: - { - alt8=3; - } - break; - case 11: - { - alt8=5; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 8, 0, input); - throw nvae; - } - switch (alt8) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:100:7: forStat - { - pushFollow(FOLLOW_forStat_in_stat590); - forStat12=forStat(); - state._fsp--; - - // TEMPLATE REWRITE - // 100:15: -> {$forStat.st} - { - retval.st = (forStat12!=null?((StringTemplate)forStat12.getTemplate()):null); - } - - - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:101:7: expr ';' - { - pushFollow(FOLLOW_expr_in_stat602); - expr13=expr(); - state._fsp--; - - match(input,11,FOLLOW_11_in_stat604); - // TEMPLATE REWRITE - // 101:16: -> statement(expr=$expr.st) - { - retval.st = templateLib.getInstanceOf("statement",new STAttrMap().put("expr", (expr13!=null?((StringTemplate)expr13.getTemplate()):null))); - } - - - - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:102:7: block - { - pushFollow(FOLLOW_block_in_stat621); - block(); - state._fsp--; - - // TEMPLATE REWRITE - // 102:13: -> statementList(locals=$slist::localsstats=$slist::stats) - { - retval.st = templateLib.getInstanceOf("statementList",new STAttrMap().put("locals", slist_stack.peek().locals).put("stats", slist_stack.peek().stats)); - } - - - - } - break; - case 4 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:103:7: assignStat ';' - { - pushFollow(FOLLOW_assignStat_in_stat643); - assignStat14=assignStat(); - state._fsp--; - - match(input,11,FOLLOW_11_in_stat645); - // TEMPLATE REWRITE - // 103:22: -> {$assignStat.st} - { - retval.st = (assignStat14!=null?((StringTemplate)assignStat14.getTemplate()):null); - } - - - - } - break; - case 5 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:104:7: ';' - { - match(input,11,FOLLOW_11_in_stat657); - // TEMPLATE REWRITE - // 104:11: -> {new StringTemplate(\";\")} - { - retval.st = new StringTemplate(";"); - } - - - - } - break; - - } - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - slist_stack.pop(); - - } - return retval; - } - // $ANTLR end "stat" - - - public static class forStat_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "forStat" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:107:1: forStat : 'for' '(' e1= assignStat ';' e2= expr ';' e3= assignStat ')' block -> forLoop(e1=$e1.ste2=$e2.ste3=$e3.stlocals=$slist::localsstats=$slist::stats); - public final forStat_return forStat() throws RecognitionException { - slist_stack.push(new slist_scope()); - - forStat_return retval = new forStat_return(); - retval.start = input.LT(1); - - ParserRuleReturnScope e1 =null; - ParserRuleReturnScope e2 =null; - ParserRuleReturnScope e3 =null; - - - slist_stack.peek().locals = new ArrayList(); - slist_stack.peek().stats = new ArrayList(); - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:113:5: ( 'for' '(' e1= assignStat ';' e2= expr ';' e3= assignStat ')' block -> forLoop(e1=$e1.ste2=$e2.ste3=$e3.stlocals=$slist::localsstats=$slist::stats)) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:113:9: 'for' '(' e1= assignStat ';' e2= expr ';' e3= assignStat ')' block - { - match(input,16,FOLLOW_16_in_forStat690); - match(input,7,FOLLOW_7_in_forStat692); - pushFollow(FOLLOW_assignStat_in_forStat696); - e1=assignStat(); - state._fsp--; - - match(input,11,FOLLOW_11_in_forStat698); - pushFollow(FOLLOW_expr_in_forStat702); - e2=expr(); - state._fsp--; - - match(input,11,FOLLOW_11_in_forStat704); - pushFollow(FOLLOW_assignStat_in_forStat708); - e3=assignStat(); - state._fsp--; - - match(input,8,FOLLOW_8_in_forStat710); - pushFollow(FOLLOW_block_in_forStat712); - block(); - state._fsp--; - - // TEMPLATE REWRITE - // 114:9: -> forLoop(e1=$e1.ste2=$e2.ste3=$e3.stlocals=$slist::localsstats=$slist::stats) - { - retval.st = templateLib.getInstanceOf("forLoop",new STAttrMap().put("e1", (e1!=null?((StringTemplate)e1.getTemplate()):null)).put("e2", (e2!=null?((StringTemplate)e2.getTemplate()):null)).put("e3", (e3!=null?((StringTemplate)e3.getTemplate()):null)).put("locals", slist_stack.peek().locals).put("stats", slist_stack.peek().stats)); - } - - - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - slist_stack.pop(); - - } - return retval; - } - // $ANTLR end "forStat" - - - public static class assignStat_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "assignStat" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:118:1: assignStat : ID '=' expr -> assign(lhs=$ID.textrhs=$expr.st); - public final assignStat_return assignStat() throws RecognitionException { - assignStat_return retval = new assignStat_return(); - retval.start = input.LT(1); - - Token ID15=null; - ParserRuleReturnScope expr16 =null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:119:5: ( ID '=' expr -> assign(lhs=$ID.textrhs=$expr.st)) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:119:9: ID '=' expr - { - ID15=(Token)match(input,ID,FOLLOW_ID_in_assignStat785); - match(input,13,FOLLOW_13_in_assignStat787); - pushFollow(FOLLOW_expr_in_assignStat789); - expr16=expr(); - state._fsp--; - - // TEMPLATE REWRITE - // 119:21: -> assign(lhs=$ID.textrhs=$expr.st) - { - retval.st = templateLib.getInstanceOf("assign",new STAttrMap().put("lhs", (ID15!=null?ID15.getText():null)).put("rhs", (expr16!=null?((StringTemplate)expr16.getTemplate()):null))); - } - - - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "assignStat" - - - public static class expr_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "expr" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:122:1: expr : condExpr -> {$condExpr.st}; - public final expr_return expr() throws RecognitionException { - expr_return retval = new expr_return(); - retval.start = input.LT(1); - - ParserRuleReturnScope condExpr17 =null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:122:5: ( condExpr -> {$condExpr.st}) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:122:9: condExpr - { - pushFollow(FOLLOW_condExpr_in_expr817); - condExpr17=condExpr(); - state._fsp--; - - // TEMPLATE REWRITE - // 122:18: -> {$condExpr.st} - { - retval.st = (condExpr17!=null?((StringTemplate)condExpr17.getTemplate()):null); - } - - - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "expr" - - - public static class condExpr_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "condExpr" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:125:1: condExpr : a= aexpr ( ( '==' b= aexpr -> equals(left=$a.stright=$b.st)| '<' b= aexpr -> lessThan(left=$a.stright=$b.st)) | -> {$a.st}) ; - public final condExpr_return condExpr() throws RecognitionException { - condExpr_return retval = new condExpr_return(); - retval.start = input.LT(1); - - ParserRuleReturnScope a =null; - ParserRuleReturnScope b =null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:126:5: (a= aexpr ( ( '==' b= aexpr -> equals(left=$a.stright=$b.st)| '<' b= aexpr -> lessThan(left=$a.stright=$b.st)) | -> {$a.st}) ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:126:9: a= aexpr ( ( '==' b= aexpr -> equals(left=$a.stright=$b.st)| '<' b= aexpr -> lessThan(left=$a.stright=$b.st)) | -> {$a.st}) - { - pushFollow(FOLLOW_aexpr_in_condExpr842); - a=aexpr(); - state._fsp--; - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:127:9: ( ( '==' b= aexpr -> equals(left=$a.stright=$b.st)| '<' b= aexpr -> lessThan(left=$a.stright=$b.st)) | -> {$a.st}) - int alt10=2; - int LA10_0 = input.LA(1); - if ( (LA10_0==12||LA10_0==14) ) { - alt10=1; - } - else if ( (LA10_0==8||LA10_0==11) ) { - alt10=2; - } - - else { - NoViableAltException nvae = - new NoViableAltException("", 10, 0, input); - throw nvae; - } - - switch (alt10) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:127:13: ( '==' b= aexpr -> equals(left=$a.stright=$b.st)| '<' b= aexpr -> lessThan(left=$a.stright=$b.st)) - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:127:13: ( '==' b= aexpr -> equals(left=$a.stright=$b.st)| '<' b= aexpr -> lessThan(left=$a.stright=$b.st)) - int alt9=2; - int LA9_0 = input.LA(1); - if ( (LA9_0==14) ) { - alt9=1; - } - else if ( (LA9_0==12) ) { - alt9=2; - } - - else { - NoViableAltException nvae = - new NoViableAltException("", 9, 0, input); - throw nvae; - } - - switch (alt9) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:127:16: '==' b= aexpr - { - match(input,14,FOLLOW_14_in_condExpr859); - pushFollow(FOLLOW_aexpr_in_condExpr863); - b=aexpr(); - state._fsp--; - - // TEMPLATE REWRITE - // 127:29: -> equals(left=$a.stright=$b.st) - { - retval.st = templateLib.getInstanceOf("equals",new STAttrMap().put("left", (a!=null?((StringTemplate)a.getTemplate()):null)).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); - } - - - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:128:16: '<' b= aexpr - { - match(input,12,FOLLOW_12_in_condExpr893); - pushFollow(FOLLOW_aexpr_in_condExpr897); - b=aexpr(); - state._fsp--; - - // TEMPLATE REWRITE - // 128:30: -> lessThan(left=$a.stright=$b.st) - { - retval.st = templateLib.getInstanceOf("lessThan",new STAttrMap().put("left", (a!=null?((StringTemplate)a.getTemplate()):null)).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); - } - - - - } - break; - - } - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:130:13: - { - // TEMPLATE REWRITE - // 130:13: -> {$a.st} - { - retval.st = (a!=null?((StringTemplate)a.getTemplate()):null); - } - - - - } - break; - - } - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "condExpr" - - - public static class aexpr_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "aexpr" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:134:1: aexpr : (a= atom -> {$a.st}) ( '+' b= atom -> add(left=$aexpr.stright=$b.st))* ; - public final aexpr_return aexpr() throws RecognitionException { - aexpr_return retval = new aexpr_return(); - retval.start = input.LT(1); - - ParserRuleReturnScope a =null; - ParserRuleReturnScope b =null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:135:5: ( (a= atom -> {$a.st}) ( '+' b= atom -> add(left=$aexpr.stright=$b.st))* ) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:135:9: (a= atom -> {$a.st}) ( '+' b= atom -> add(left=$aexpr.stright=$b.st))* - { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:135:9: (a= atom -> {$a.st}) - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:135:10: a= atom - { - pushFollow(FOLLOW_atom_in_aexpr975); - a=atom(); - state._fsp--; - - // TEMPLATE REWRITE - // 135:17: -> {$a.st} - { - retval.st = (a!=null?((StringTemplate)a.getTemplate()):null); - } - - - - } - - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:136:9: ( '+' b= atom -> add(left=$aexpr.stright=$b.st))* - loop11: - while (true) { - int alt11=2; - int LA11_0 = input.LA(1); - if ( (LA11_0==9) ) { - alt11=1; - } - - switch (alt11) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:136:11: '+' b= atom - { - match(input,9,FOLLOW_9_in_aexpr992); - pushFollow(FOLLOW_atom_in_aexpr996); - b=atom(); - state._fsp--; - - // TEMPLATE REWRITE - // 136:22: -> add(left=$aexpr.stright=$b.st) - { - retval.st = templateLib.getInstanceOf("add",new STAttrMap().put("left", retval.st).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); - } - - - - } - break; - - default : - break loop11; - } - } - - } - - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "aexpr" - - - public static class atom_return extends ParserRuleReturnScope { - public StringTemplate st; - public Object getTemplate() { return st; } - public String toString() { return st==null?null:st.toString(); } - }; - - - // $ANTLR start "atom" - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:139:1: atom : ( ID -> refVar(id=$ID.text)| INT -> iconst(value=$INT.text)| '(' expr ')' -> {$expr.st}); - public final atom_return atom() throws RecognitionException { - atom_return retval = new atom_return(); - retval.start = input.LT(1); - - Token ID18=null; - Token INT19=null; - ParserRuleReturnScope expr20 =null; - - try { - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:140:5: ( ID -> refVar(id=$ID.text)| INT -> iconst(value=$INT.text)| '(' expr ')' -> {$expr.st}) - int alt12=3; - switch ( input.LA(1) ) { - case ID: - { - alt12=1; - } - break; - case INT: - { - alt12=2; - } - break; - case 7: - { - alt12=3; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 12, 0, input); - throw nvae; - } - switch (alt12) { - case 1 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:140:7: ID - { - ID18=(Token)match(input,ID,FOLLOW_ID_in_atom1030); - // TEMPLATE REWRITE - // 140:10: -> refVar(id=$ID.text) - { - retval.st = templateLib.getInstanceOf("refVar",new STAttrMap().put("id", (ID18!=null?ID18.getText():null))); - } - - - - } - break; - case 2 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:141:7: INT - { - INT19=(Token)match(input,INT,FOLLOW_INT_in_atom1047); - // TEMPLATE REWRITE - // 141:11: -> iconst(value=$INT.text) - { - retval.st = templateLib.getInstanceOf("iconst",new STAttrMap().put("value", (INT19!=null?INT19.getText():null))); - } - - - - } - break; - case 3 : - // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\samples\\stg\\CMinus.g:142:7: '(' expr ')' - { - match(input,7,FOLLOW_7_in_atom1064); - pushFollow(FOLLOW_expr_in_atom1066); - expr20=expr(); - state._fsp--; - - match(input,8,FOLLOW_8_in_atom1068); - // TEMPLATE REWRITE - // 142:20: -> {$expr.st} - { - retval.st = (expr20!=null?((StringTemplate)expr20.getTemplate()):null); - } - - - - } - break; - - } - retval.stop = input.LT(-1); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - // do for sure before leaving - } - return retval; - } - // $ANTLR end "atom" - - // Delegated rules - - - - public static final BitSet FOLLOW_declaration_in_program58 = new BitSet(new long[]{0x0000000000028012L}); - public static final BitSet FOLLOW_variable_in_declaration99 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_function_in_declaration115 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_type_in_variable139 = new BitSet(new long[]{0x0000000000000010L}); - public static final BitSet FOLLOW_declarator_in_variable141 = new BitSet(new long[]{0x0000000000000800L}); - public static final BitSet FOLLOW_11_in_variable143 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_ID_in_declarator217 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_type_in_function254 = new BitSet(new long[]{0x0000000000000010L}); - public static final BitSet FOLLOW_ID_in_function256 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_7_in_function268 = new BitSet(new long[]{0x0000000000028110L}); - public static final BitSet FOLLOW_formalParameter_in_function274 = new BitSet(new long[]{0x0000000000000500L}); - public static final BitSet FOLLOW_10_in_function278 = new BitSet(new long[]{0x0000000000028010L}); - public static final BitSet FOLLOW_formalParameter_in_function282 = new BitSet(new long[]{0x0000000000000500L}); - public static final BitSet FOLLOW_8_in_function290 = new BitSet(new long[]{0x0000000000040000L}); - public static final BitSet FOLLOW_block_in_function300 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_type_in_formalParameter416 = new BitSet(new long[]{0x0000000000000010L}); - public static final BitSet FOLLOW_declarator_in_formalParameter418 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_17_in_type459 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_15_in_type476 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_ID_in_type492 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_18_in_block523 = new BitSet(new long[]{0x00000000000F88B0L}); - public static final BitSet FOLLOW_variable_in_block534 = new BitSet(new long[]{0x00000000000F88B0L}); - public static final BitSet FOLLOW_stat_in_block550 = new BitSet(new long[]{0x00000000000D08B0L}); - public static final BitSet FOLLOW_19_in_block563 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_forStat_in_stat590 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_expr_in_stat602 = new BitSet(new long[]{0x0000000000000800L}); - public static final BitSet FOLLOW_11_in_stat604 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_block_in_stat621 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_assignStat_in_stat643 = new BitSet(new long[]{0x0000000000000800L}); - public static final BitSet FOLLOW_11_in_stat645 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_11_in_stat657 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_16_in_forStat690 = new BitSet(new long[]{0x0000000000000080L}); - public static final BitSet FOLLOW_7_in_forStat692 = new BitSet(new long[]{0x0000000000000010L}); - public static final BitSet FOLLOW_assignStat_in_forStat696 = new BitSet(new long[]{0x0000000000000800L}); - public static final BitSet FOLLOW_11_in_forStat698 = new BitSet(new long[]{0x00000000000000B0L}); - public static final BitSet FOLLOW_expr_in_forStat702 = new BitSet(new long[]{0x0000000000000800L}); - public static final BitSet FOLLOW_11_in_forStat704 = new BitSet(new long[]{0x0000000000000010L}); - public static final BitSet FOLLOW_assignStat_in_forStat708 = new BitSet(new long[]{0x0000000000000100L}); - public static final BitSet FOLLOW_8_in_forStat710 = new BitSet(new long[]{0x0000000000040000L}); - public static final BitSet FOLLOW_block_in_forStat712 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_ID_in_assignStat785 = new BitSet(new long[]{0x0000000000002000L}); - public static final BitSet FOLLOW_13_in_assignStat787 = new BitSet(new long[]{0x00000000000000B0L}); - public static final BitSet FOLLOW_expr_in_assignStat789 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_condExpr_in_expr817 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_aexpr_in_condExpr842 = new BitSet(new long[]{0x0000000000005002L}); - public static final BitSet FOLLOW_14_in_condExpr859 = new BitSet(new long[]{0x00000000000000B0L}); - public static final BitSet FOLLOW_aexpr_in_condExpr863 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_12_in_condExpr893 = new BitSet(new long[]{0x00000000000000B0L}); - public static final BitSet FOLLOW_aexpr_in_condExpr897 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_atom_in_aexpr975 = new BitSet(new long[]{0x0000000000000202L}); - public static final BitSet FOLLOW_9_in_aexpr992 = new BitSet(new long[]{0x00000000000000B0L}); - public static final BitSet FOLLOW_atom_in_aexpr996 = new BitSet(new long[]{0x0000000000000202L}); - public static final BitSet FOLLOW_ID_in_atom1030 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_INT_in_atom1047 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_7_in_atom1064 = new BitSet(new long[]{0x00000000000000B0L}); - public static final BitSet FOLLOW_expr_in_atom1066 = new BitSet(new long[]{0x0000000000000100L}); - public static final BitSet FOLLOW_8_in_atom1068 = new BitSet(new long[]{0x0000000000000002L}); -} diff --git a/ethereumj-core/src/main/java/samples/stg/GenParser.java b/ethereumj-core/src/main/java/samples/stg/GenParser.java deleted file mode 100644 index 19c64df9..00000000 --- a/ethereumj-core/src/main/java/samples/stg/GenParser.java +++ /dev/null @@ -1,17 +0,0 @@ -package samples.stg; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 25/04/14 17:06 - */ -public class GenParser { - - - public static void main(String args[]){ - - String userDir = System.getProperty("user.dir"); - org.antlr.Tool.main(new String[]{userDir + "\\src\\main\\java\\samples\\stg\\CMinus.g"}); - - } -} diff --git a/ethereumj-core/src/main/java/samples/stg/Java.stg b/ethereumj-core/src/main/java/samples/stg/Java.stg deleted file mode 100644 index c6a3f34d..00000000 --- a/ethereumj-core/src/main/java/samples/stg/Java.stg +++ /dev/null @@ -1,55 +0,0 @@ -group Java; - -program(globals,functions) ::= << -class Wrapper { - - -} ->> - -variable(type,name) ::= " ;" - -globalVariable ::= variable - -function(type,name,args,locals,stats) ::= << - () { - - -} ->> - -type_int() ::= "int" - -type_char() ::= "char" - -type_user_object(name) ::= "" - -parameter(type,name) ::= " " - -statement(expr) ::= ";" - -statementList(locals,stats) ::= << -{ - - -}<\n> ->> - -forLoop(e1,e2,e3,locals,stats) ::= << -for ( ; ) { - - -} ->> - -assign(lhs,rhs) ::= " = ;" - -equals(left,right) ::= " == " - -lessThan(left,right) ::= " \< " - -add(left,right) ::= " + " - -refVar(id) ::= "" - -iconst(value) ::= "" diff --git a/ethereumj-core/src/main/java/samples/stg/Main.java b/ethereumj-core/src/main/java/samples/stg/Main.java deleted file mode 100644 index 34f73bbc..00000000 --- a/ethereumj-core/src/main/java/samples/stg/Main.java +++ /dev/null @@ -1,30 +0,0 @@ - -package samples.stg; -import java.io.*; -import org.antlr.runtime.*; -import org.antlr.stringtemplate.*; -import org.antlr.stringtemplate.language.*; - -public class Main { - public static StringTemplateGroup templates; - - public static void main(String[] args) throws Exception { - String templateFileName; - - String userDir = System.getProperty("user.dir"); - - templateFileName = userDir + "\\src\\main\\java\\samples\\stg\\Bytecode.stg"; - templates = new StringTemplateGroup(new FileReader(templateFileName), - AngleBracketTemplateLexer.class); - - String srcFile = userDir + "\\src\\main\\java\\samples\\stg\\input"; - - CharStream input = new ANTLRFileStream(srcFile); - CMinusLexer lexer = new CMinusLexer(input); - CommonTokenStream tokens = new CommonTokenStream(lexer); - CMinusParser parser = new CMinusParser(tokens); - parser.setTemplateLib(templates); - RuleReturnScope r = parser.program(); - System.out.println(r.getTemplate().toString()); - } -} diff --git a/ethereumj-core/src/main/java/samples/stg/Python.stg b/ethereumj-core/src/main/java/samples/stg/Python.stg deleted file mode 100644 index 9ea37bda..00000000 --- a/ethereumj-core/src/main/java/samples/stg/Python.stg +++ /dev/null @@ -1,48 +0,0 @@ -group Python; - -program(globals,functions) ::= << - ->> - -variable(type,name) ::= " " - -globalVariable ::= variable - -function(type,name,args,locals,stats) ::= << -def (): - ->> - -type_int() ::= "int" - -type_char() ::= "char" - -type_user_object(name) ::= "" - -parameter(type,name) ::= "" - -statement(expr) ::= "" - -statementList(locals,stats) ::= << - ->> - -// python has a weird FOR, use a WHILE. :) -forLoop(e1,e2,e3,locals,stats) ::= << - -while ( ): - - ->> - -assign(lhs,rhs) ::= " = " - -equals(left,right) ::= " == " - -lessThan(left,right) ::= " \< " - -add(left,right) ::= " + " - -refVar(id) ::= "" - -iconst(value) ::= "" diff --git a/ethereumj-core/src/main/java/samples/stg/files b/ethereumj-core/src/main/java/samples/stg/files deleted file mode 100644 index ecda47a0..00000000 --- a/ethereumj-core/src/main/java/samples/stg/files +++ /dev/null @@ -1,7 +0,0 @@ -Java.stg -Bytecode.stg -Python.stg -Main.java -CMinus.g -input -output diff --git a/ethereumj-core/src/main/java/samples/stg/input b/ethereumj-core/src/main/java/samples/stg/input deleted file mode 100644 index 416f4fc4..00000000 --- a/ethereumj-core/src/main/java/samples/stg/input +++ /dev/null @@ -1,9 +0,0 @@ -char c; -int x; -int foo(int y, char d) { - int i; - for (i=0; i<3; i=i+1) { - x=3; - y=5; - } -} diff --git a/ethereumj-core/src/main/java/samples/stg/output b/ethereumj-core/src/main/java/samples/stg/output deleted file mode 100644 index 17ab43db..00000000 --- a/ethereumj-core/src/main/java/samples/stg/output +++ /dev/null @@ -1,11 +0,0 @@ -class Wrapper { - char c; - int x; - int foo(int y, char d) { - int i; - for (i = 0; i < 3; i = i + 1;) { - x = 3; - y = 5; - } - } -} diff --git a/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java b/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java index acae6946..8ab86f09 100644 --- a/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java @@ -1,20 +1,15 @@ package org.ethereum.block; -import org.bouncycastle.util.encoders.Hex; +import org.spongycastle.util.encoders.Hex; +import org.ethereum.crypto.HashUtil; import org.ethereum.net.RLP; import org.ethereum.net.rlp.RLPList; import org.ethereum.net.vo.BlockData; -import org.ethereum.util.Utils; import org.junit.Test; import java.io.IOException; import java.math.BigInteger; -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 19/04/14 13:30 - */ public class BlockTest { @Test /* Creating genesis hash not ready yet */ @@ -37,8 +32,6 @@ public class BlockTest { */ /* - - ( 0(256) - parentHash SHA3(RLP(emptyList)) - hashes of transactions 0(160) - coinbase @@ -56,15 +49,10 @@ public class BlockTest { block.appendRaw(RLPEmptyList); block.appendRaw(RLPEmptyList); - */ - - // gennesis hash //ab6b9a5613970faa771b12d449b2e9bb925ab7a369f0a4b86b286e9d540099cf - - /* 1 */ byte[] prevHash = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -72,7 +60,7 @@ public class BlockTest { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; prevHash = RLP.encodeElement(prevHash); - /* 2 */ byte[] uncleList = RLP.encodeElement(Utils.sha3(RLP.encodeList(new byte[]{}))); + /* 2 */ byte[] uncleList = RLP.encodeElement(HashUtil.sha3(RLP.encodeList(new byte[]{}))); /* 3 */ byte[] coinbase = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -86,7 +74,7 @@ public class BlockTest { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; rootState = RLP.encodeElement(rootState); - /* 5 */ byte[] transactionsRoot = RLP.encodeElement(Utils.sha3(RLP.encodeList(new byte[]{}))); + /* 5 */ byte[] transactionsRoot = RLP.encodeElement(HashUtil.sha3(RLP.encodeList(new byte[]{}))); /* 6 */ BigInteger difficulty = new BigInteger("2"); difficulty = difficulty.pow(22); @@ -99,9 +87,7 @@ public class BlockTest { extradata = RLP.encodeElement(extradata); /* 9 */ byte[] nonce = {42}; - nonce = RLP.encodeElement( Utils.sha3(nonce) ); - - + nonce = RLP.encodeElement(HashUtil.sha3(nonce)); byte[] header = RLP.encodeList( prevHash, uncleList, @@ -115,14 +101,13 @@ public class BlockTest { // block.appendList(9) << h256() << sha3EmptyList << h160() << stateRoot << sha3EmptyList << c_genesisDifficulty << (uint)0 << string() << sha3(bytes(1, 42)); - byte[] txList = RLP.encodeList(new byte[]{}); byte[] unclesList = RLP.encodeList(new byte[]{}); byte[] genesis = RLP.encodeList(header, txList, unclesList); System.out.println(Hex.toHexString(genesis)); - byte[] hash = Utils.sha3(genesis); + byte[] hash = HashUtil.sha3(genesis); System.out.println(Hex.toHexString(hash)); @@ -133,10 +118,9 @@ public class BlockTest { public void test2(){ byte[] goGenesisBytes = Hex.decode("f8a4f8a0a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794000000000000000000000000000000000000000080a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347834000008080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0"); - System.out.println( Hex.toHexString( Utils.sha3(goGenesisBytes) ) ); + System.out.println( Hex.toHexString( HashUtil.sha3(goGenesisBytes) ) ); } - @Test /* create BlockData from part of real RLP BLOCKS message */ public void test3(){ @@ -148,14 +132,10 @@ public class BlockTest { RLP.parseObjects(payload, rlpList); BlockData blockData = new BlockData(rlpList); - RLPList.recursivePrint(rlpList); - } } - - /* [[ab6b9a5613970faa771b12d449b2e9bb925ab7a369f0a4b86b286e9d540099cf, 1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347, 3854aaf203ba5f8d49b1ec221329c7aebcf050d3, 990dc3b5acbee04124361d958fe51acb582593613fc290683940a0769549d3ed, 9bfe4817d274ea3eb8672e9fe848c3885b53bbbd1d7c26e6039f90fb96b942b0, 3ff000, 533f16b7, null, 00000000000000000000000000000000000000000000000077377adff6c227db, ] [ diff --git a/ethereumj-core/src/test/java/org/ethereum/crypto/CryptoTest.java b/ethereumj-core/src/test/java/org/ethereum/crypto/CryptoTest.java index 21035bbf..3a64aad7 100644 --- a/ethereumj-core/src/test/java/org/ethereum/crypto/CryptoTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/crypto/CryptoTest.java @@ -1,109 +1,78 @@ package org.ethereum.crypto; -import junit.framework.Assert; -import org.bouncycastle.util.encoders.Hex; +import org.spongycastle.util.encoders.Hex; import org.ethereum.util.Utils; import org.junit.Test; +import static org.junit.Assert.*; + import java.math.BigInteger; -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 17/04/14 15:02 - */ - public class CryptoTest { - - @Test public void test1(){ - byte[] result = Utils.sha3("horse".getBytes()); + byte[] result = HashUtil.sha3("horse".getBytes()); - Assert.assertEquals("c87f65ff3f271bf5dc8643484f66b200109caffe4bf98c4cb393dc35740b28c0", + assertEquals("c87f65ff3f271bf5dc8643484f66b200109caffe4bf98c4cb393dc35740b28c0", Hex.toHexString(result)); - result = Utils.sha3("cow".getBytes()); + result = HashUtil.sha3("cow".getBytes()); - Assert.assertEquals("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4", + assertEquals("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4", Hex.toHexString(result)); - - } - @Test - public void test2(){ - - byte[] result = Utils.ripemd160("c87f65ff3f271bf5dc8643484f66b200109caffe4bf98c4cb393dc35740b28c0".getBytes()); - - - System.out.println(Hex.toHexString(result)); - - } - - @Test public void test3(){ BigInteger privKey = new BigInteger("cd244b3015703ddf545595da06ada5516628c5feadbf49dc66049c4b370cc5d8", 16); - byte[] addr = Utils.privToAddress(privKey.toByteArray()); - Assert.assertEquals("89b44e4d3c81ede05d0f5de8d1a68f754d73d997", Hex.toHexString(addr)); + byte[] addr = ECKey.fromPrivate(privKey).getAddress(); + assertEquals("89b44e4d3c81ede05d0f5de8d1a68f754d73d997", Hex.toHexString(addr)); } @Test public void test4(){ - byte[] cowBytes = Utils.sha3("cow".getBytes()); - - byte[] addr = Utils.privToAddress(cowBytes); - Assert.assertEquals("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826", Hex.toHexString(addr).toUpperCase()); + byte[] cowBytes = HashUtil.sha3("cow".getBytes()); + byte[] addr = ECKey.fromPrivate(cowBytes).getAddress(); + assertEquals("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826", Hex.toHexString(addr).toUpperCase()); } @Test public void test5(){ - byte[] horseBytes = Utils.sha3("horse".getBytes()); - - byte[] addr = Utils.privToAddress(horseBytes); - Assert.assertEquals("13978AEE95F38490E9769C39B2773ED763D9CD5F", Hex.toHexString(addr).toUpperCase()); + byte[] horseBytes = HashUtil.sha3("horse".getBytes()); + byte[] addr = ECKey.fromPrivate(horseBytes).getAddress(); + assertEquals("13978AEE95F38490E9769C39B2773ED763D9CD5F", Hex.toHexString(addr).toUpperCase()); } @Test /* performance test */ public void test6(){ - long firstTime = System.currentTimeMillis(); System.out.println(firstTime); for (int i = 0; i < 1000; ++i){ - byte[] horseBytes = Utils.sha3("horse".getBytes()); - - byte[] addr = Utils.privToAddress(horseBytes); - Assert.assertEquals("13978AEE95F38490E9769C39B2773ED763D9CD5F", Hex.toHexString(addr).toUpperCase()); + byte[] horseBytes = HashUtil.sha3("horse".getBytes()); + byte[] addr = ECKey.fromPrivate(horseBytes).getAddress(); + assertEquals("13978AEE95F38490E9769C39B2773ED763D9CD5F", Hex.toHexString(addr).toUpperCase()); } long secondTime = System.currentTimeMillis(); System.out.println(secondTime); - System.out.println(secondTime - firstTime + " millisec"); - // 1) result: ~52 address calculation every second - } - @Test /* real tx hash calc */ public void test7(){ String txRaw = "F89D80809400000000000000000000000000000000000000008609184E72A000822710B3606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C5884336069571CA07F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4A06D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC"; - - byte[] txHashB = Utils.sha3(Hex.decode(txRaw)); + byte[] txHashB = HashUtil.sha3(Hex.decode(txRaw)); String txHash = Utils.toHexString(txHashB); - - Assert.assertEquals("4b7d9670a92bf120d5b43400543b69304a14d767cf836a7f6abff4edde092895", txHash); - + assertEquals("4b7d9670a92bf120d5b43400543b69304a14d767cf836a7f6abff4edde092895", txHash); } @Test /* real block hash calc */ @@ -111,23 +80,14 @@ public class CryptoTest { String blockRaw = "F885F8818080A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347940000000000000000000000000000000000000000A0BCDDD284BF396739C224DBA0411566C891C32115FEB998A3E2B4E61F3F35582AA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D4934783800000808080C0C0"; - byte[] blockHashB = Utils.sha3(Hex.decode(blockRaw)); + byte[] blockHashB = HashUtil.sha3(Hex.decode(blockRaw)); String blockHash = Utils.toHexString(blockHashB); - System.out.println(blockHash); - - } - @Test public void test9(){ - // todo: https://tools.ietf.org/html/rfc6979#section-2.2 // todo: https://github.com/bcgit/bc-java/blob/master/core/src/main/java/org/bouncycastle/crypto/signers/ECDSASigner.java - - } - - // } diff --git a/ethereumj-core/src/test/java/org/ethereum/crypto/ECKeyTest.java b/ethereumj-core/src/test/java/org/ethereum/crypto/ECKeyTest.java new file mode 100644 index 00000000..8474a66d --- /dev/null +++ b/ethereumj-core/src/test/java/org/ethereum/crypto/ECKeyTest.java @@ -0,0 +1,292 @@ +package org.ethereum.crypto; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.junit.Assert.*; + +import java.io.IOException; +import java.math.BigInteger; +import java.security.SignatureException; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.Executors; + +import org.ethereum.crypto.ECKey.ECDSASignature; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spongycastle.util.encoders.Hex; + +import com.google.common.collect.Lists; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; + +public class ECKeyTest { + private static final Logger log = LoggerFactory.getLogger(ECKeyTest.class); + + private String privString = "3ecb44df2159c26e0f995712d4f39b6f6e499b40749b1cf1246c37f9516cb6a4"; + private BigInteger privateKey = new BigInteger(Hex.decode(privString)); + + private String pubString = "0497466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce78549b514e4453d74ef11b0cd5e4e4c364effddac8b51bcfc8de80682f952896f"; + private String compressedPubString = "0397466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce7"; + private byte[] pubKey = Hex.decode(pubString); + private byte[] compressedPubKey = Hex.decode(compressedPubString); + private String address = "8a40bfaa73256b60764c1bf40675a99083efb075"; + + private String exampleMessage = new String("This is an example of a signed message."); + private String bitcoinSigBase64 = "HIb1Pb2tCwt/f15R9c/nlCgQrFTAxIt7TooOqG4B8ODNSaUdTtcW1N2E9bH+mF9HGjfd88H8QOyG0sPZtp2uaCQ="; + private String ethereumSigBase64 = "HD5AsBr4wuH6UU9tXuSJhUvgfGayfwoY0cKT03sFUjnpQsupHznd/3mCIRfLuNHlRCVGdAyHecdyM8IVZMtc1I8="; + + @Test + public void testHashCode() { + fail("Not yet implemented"); + } + + @Test + public void testECKey() { + ECKey key = new ECKey(); + assertTrue(key.isPubKeyCanonical()); + assertNotNull(key.getPubKey()); + assertNotNull(key.getPrivKeyBytes()); + log.debug(Hex.toHexString(key.getPrivKeyBytes()) + " :Generated privkey"); + log.debug(Hex.toHexString(key.getPubKey()) + " :Generated pubkey"); + } + + @Test + public void testFromPrivateKey() { + ECKey key = ECKey.fromPrivate(privateKey).decompress(); + assertTrue(key.isPubKeyCanonical()); + assertTrue(key.hasPrivKey()); + assertArrayEquals(pubKey, key.getPubKey()); + } + + @Test(expected=IllegalArgumentException.class) + public void testPrivatePublicKeyBytesNoArg() { + new ECKey(null, null); + fail("Expecting an IllegalArgumentException for using only null-parameters"); + } + + @Test + public void testIsPubKeyOnly() { + ECKey key = ECKey.fromPublicOnly(pubKey); + assertTrue(key.isPubKeyCanonical()); + assertTrue(key.isPubKeyOnly()); + assertArrayEquals(key.getPubKey(), pubKey); + } + + @Test + public void testPublicKeyFromPrivate() { + byte[] pubFromPriv = ECKey.publicKeyFromPrivate(privateKey, false); + assertArrayEquals(pubKey, pubFromPriv); + } + + @Test + public void testPublicKeyFromPrivateCompressed() { + byte[] pubFromPriv = ECKey.publicKeyFromPrivate(privateKey, true); + assertArrayEquals(compressedPubKey, pubFromPriv); + } + + @Test + public void testGetAddress() { + ECKey key = ECKey.fromPublicOnly(pubKey); + assertArrayEquals(Hex.decode(address), key.getAddress()); + } + + @Test + public void testToString() { + ECKey key = ECKey.fromPrivate(BigInteger.TEN); // An example private key. + assertEquals("pub:04a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7", key.toString()); + } + + @Test + public void testSignBitcoin() throws IOException { + // TODO: Understand why key must be decompressed for this to work + ECKey key = ECKey.fromPrivate(privateKey).decompress(); + System.out.println("Secret: " + Hex.toHexString(key.getPrivKeyBytes())); + System.out.println("Pubkey: " + Hex.toHexString(key.getPubKey())); + String output = key.signBitcoinMessage(exampleMessage); + + System.out.println("Signtr: " + output + " (Base64) - length: " + output.length()); + + assertEquals(bitcoinSigBase64, output); + } + + @Test + public void testEthereumSign() throws IOException { + // TODO: Understand why key must be decompressed for this to work + ECKey key = ECKey.fromPrivate(privateKey).decompress(); + System.out.println("Secret\t: " + Hex.toHexString(key.getPrivKeyBytes())); + System.out.println("Pubkey\t: " + Hex.toHexString(key.getPubKey())); + System.out.println("Data\t: " + exampleMessage); + byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes()); + ECDSASignature signature = key.sign(messageHash); + String output = signature.toBase64(); + System.out.println("Signtr\t: " + output + " (Base64, length: " + output.length() + ")"); + assertEquals(ethereumSigBase64, output); + } + + @Test + public void testVerifySignature1() { + ECKey key = ECKey.fromPublicOnly(pubKey); + BigInteger r = new BigInteger("28157690258821599598544026901946453245423343069728565040002908283498585537001"); + BigInteger s = new BigInteger("30212485197630673222315826773656074299979444367665131281281249560925428307087"); + ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray()); + sig.v = 28; + key.verify(HashUtil.sha3(exampleMessage.getBytes()), sig); + } + + @Test + public void testVerifySignature2() { + BigInteger r = new BigInteger("c52c114d4f5a3ba904a9b3036e5e118fe0dbb987fe3955da20f2cd8f6c21ab9c", 16); + BigInteger s = new BigInteger("6ba4c2874299a55ad947dbc98a25ee895aabf6b625c26c435e84bfd70edf2f69", 16); + ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray()); + sig.v = 0x1b; + byte[] rawtx = Hex.decode("f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480"); + try { + ECKey key = ECKey.signatureToKey(HashUtil.sha3(rawtx), sig.toBase64()); + System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey())); + System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress())); + assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(key.getAddress())); + key.verify(HashUtil.sha3(rawtx), sig); + } catch (SignatureException e) { + fail(); + } + } + + @Test + public void testVerifyBitcoinMessage() { + ECKey key = ECKey.fromPublicOnly(pubKey); + try { + key.verifyBitcoinMessage(exampleMessage, bitcoinSigBase64); + } catch (SignatureException e) { + fail(); + } + } + + @Test + public void testSValue() throws Exception { + // Check that we never generate an S value that is larger than half the curve order. This avoids a malleability + // issue that can allow someone to change a transaction [hash] without invalidating the signature. + final int ITERATIONS = 10; + ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(ITERATIONS)); + List> sigFutures = Lists.newArrayList(); + final ECKey key = new ECKey(); + for (byte i = 0; i < ITERATIONS; i++) { + final byte[] hash = HashUtil.sha3(new byte[]{i}); + sigFutures.add(executor.submit(new Callable() { + @Override + public ECKey.ECDSASignature call() throws Exception { + return key.doSign(hash); + } + })); + } + List sigs = Futures.allAsList(sigFutures).get(); + for (ECKey.ECDSASignature signature : sigs) { + assertTrue(signature.s.compareTo(ECKey.HALF_CURVE_ORDER) <= 0); + } + final ECKey.ECDSASignature duplicate = new ECKey.ECDSASignature(sigs.get(0).r, sigs.get(0).s); + assertEquals(sigs.get(0), duplicate); + assertEquals(sigs.get(0).hashCode(), duplicate.hashCode()); + } + + @Test + public void testSignVerify() { + ECKey key = ECKey.fromPrivate(privateKey); + String message = new String("This is an example of a signed message."); + ECDSASignature output = key.doSign(message.getBytes()); + assertTrue(key.verify(message.getBytes(), output)); + } + + @Test + public void testIsPubKeyCanonicalCorect() { + // Test correct prefix 4, right length 65 + byte[] canonicalPubkey1 = new byte[65]; canonicalPubkey1[0] = 0x04; + assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey1)); + // Test correct prefix 2, right length 33 + byte[] canonicalPubkey2 = new byte[33]; canonicalPubkey2[0] = 0x02; + assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey2)); + // Test correct prefix 3, right length 33 + byte[] canonicalPubkey3 = new byte[33]; canonicalPubkey3[0] = 0x03; + assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey3)); + } + + @Test + public void testIsPubKeyCanonicalWrongLength() { + // Test correct prefix 4, but wrong length !65 + byte[] nonCanonicalPubkey1 = new byte[64]; nonCanonicalPubkey1[0] = 0x04; + assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey1)); + // Test correct prefix 2, but wrong length !33 + byte[] nonCanonicalPubkey2 = new byte[32]; nonCanonicalPubkey2[0] = 0x02; + assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey2)); + // Test correct prefix 3, but wrong length !33 + byte[] nonCanonicalPubkey3 = new byte[32]; nonCanonicalPubkey3[0] = 0x03; + assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey3)); + } + + @Test + public void testIsPubKeyCanonicalWrongPrefix() { + // Test wrong prefix 4, right length 65 + byte[] nonCanonicalPubkey4 = new byte[65]; + assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey4)); + // Test wrong prefix 2, right length 33 + byte[] nonCanonicalPubkey5 = new byte[33]; + assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey5)); + // Test wrong prefix 3, right length 33 + byte[] nonCanonicalPubkey6 = new byte[33]; + assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey6)); + } + + @Test + public void keyRecovery() throws Exception { + ECKey key = new ECKey(); + String message = "Hello World!"; + byte[] hash = HashUtil.sha256(message.getBytes()); + ECKey.ECDSASignature sig = key.doSign(hash); + key = ECKey.fromPublicOnly(key.getPubKeyPoint()); + boolean found = false; + for (int i = 0; i < 4; i++) { + ECKey key2 = ECKey.recoverFromSignature(i, sig, hash, true); + checkNotNull(key2); + if (key.equals(key2)) { + found = true; + break; + } + } + assertTrue(found); + } + + @Test + public void testSignedBitcoinMessageToKey() throws SignatureException { + ECKey key = ECKey.signedBitcoinMessageToKey("This is an example of a signed message.", bitcoinSigBase64); + assertNotNull(key); + assertArrayEquals(pubKey, key.getPubKey()); + } + + @Test + public void testSignedMessageToKey() throws SignatureException { + byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes()); + ECKey key = ECKey.signatureToKey(messageHash, ethereumSigBase64); + assertNotNull(key); + assertArrayEquals(pubKey, key.getPubKey()); + } + + + @Test + public void testGetPrivKeyBytes() { + ECKey key = new ECKey(); + assertNotNull(key.getPrivKeyBytes()); + assertEquals(32, key.getPrivKeyBytes().length); + } + + @Test + public void testEqualsObject() { + ECKey key0 = new ECKey(); + ECKey key1 = ECKey.fromPrivate(privateKey); + ECKey key2 = ECKey.fromPrivate(privateKey); + + assertFalse(key0.equals(key1)); + assertTrue(key1.equals(key1)); + assertTrue(key1.equals(key2)); + } +} diff --git a/ethereumj-core/src/test/java/org/ethereum/net/MessagesTest.java b/ethereumj-core/src/test/java/org/ethereum/net/MessagesTest.java index a45f1243..33fb3377 100644 --- a/ethereumj-core/src/test/java/org/ethereum/net/MessagesTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/net/MessagesTest.java @@ -1,7 +1,6 @@ package org.ethereum.net; -import junit.framework.Assert; -import org.bouncycastle.util.encoders.Hex; +import org.spongycastle.util.encoders.Hex; import org.ethereum.net.message.*; import org.ethereum.net.rlp.RLPList; import org.ethereum.net.vo.BlockData; @@ -11,17 +10,10 @@ import org.ethereum.util.Utils; import org.junit.Test; import java.net.UnknownHostException; -import java.util.LinkedList; import java.util.List; -import java.util.Queue; import static org.junit.Assert.*; -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 07/04/14 12:57 - */ public class MessagesTest { /* HELLO_MESSAGE */ @@ -46,12 +38,12 @@ public class MessagesTest { System.out.println(helloMessage); - Assert.assertEquals(12, helloMessage.getProtocolVersion()); - Assert.assertEquals(0, helloMessage.getNetworkId()); - Assert.assertEquals("Ethereum(++)/ZeroGox/v0.5.1/ncurses/Linux/g++", helloMessage.getClientId()); - Assert.assertEquals(7, helloMessage.getCapabilities()); - Assert.assertEquals(30303, helloMessage.getPeerPort()); - Assert.assertEquals( + assertEquals(12, helloMessage.getProtocolVersion()); + assertEquals(0, helloMessage.getNetworkId()); + assertEquals("Ethereum(++)/ZeroGox/v0.5.1/ncurses/Linux/g++", helloMessage.getClientId()); + assertEquals(7, helloMessage.getCapabilities()); + assertEquals(30303, helloMessage.getPeerPort()); + assertEquals( "D8833B83560E0B12170E9169DC43784223A59842DE2359E6D03DB34C30A966C2DE3B4B2552FB0D7595A185D558F2E669B595674F5217C996EE148884828BE0FD", Utils.toHexString(helloMessage.getPeerId()).toUpperCase() ); } @@ -68,12 +60,12 @@ public class MessagesTest { helloMessage.parseRLP(); System.out.println(helloMessage); - Assert.assertEquals(11, helloMessage.getProtocolVersion()); - Assert.assertEquals(0, helloMessage.getNetworkId()); - Assert.assertEquals("Ethereum(++)/v0.4.3/ETH_BUILD_TYPE/ETH_BUILD_PLATFORM", helloMessage.getClientId()); - Assert.assertEquals(7, helloMessage.getCapabilities()); - Assert.assertEquals(30303, helloMessage.getPeerPort()); - Assert.assertEquals( + assertEquals(11, helloMessage.getProtocolVersion()); + assertEquals(0, helloMessage.getNetworkId()); + assertEquals("Ethereum(++)/v0.4.3/ETH_BUILD_TYPE/ETH_BUILD_PLATFORM", helloMessage.getClientId()); + assertEquals(7, helloMessage.getCapabilities()); + assertEquals(30303, helloMessage.getPeerPort()); + assertEquals( "E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1", Utils.toHexString(helloMessage.getPeerId()).toUpperCase() ); } @@ -92,7 +84,7 @@ public class MessagesTest { DisconnectMessage disconnectMessage = new DisconnectMessage(rlpList); System.out.println(disconnectMessage); - Assert.assertEquals(disconnectMessage.getReason(), + assertEquals(disconnectMessage.getReason(), DisconnectMessage.REASON_DISCONNECT_REQUESTED); } @@ -107,7 +99,7 @@ public class MessagesTest { DisconnectMessage disconnectMessage = new DisconnectMessage(rlpList); System.out.println(disconnectMessage); - Assert.assertEquals(disconnectMessage.getReason(), + assertEquals(disconnectMessage.getReason(), DisconnectMessage.REASON_TCP_ERROR); } @@ -125,13 +117,13 @@ public class MessagesTest { PeersMessage peersMessage= new PeersMessage(rlpList); System.out.println(peersMessage); - Assert.assertEquals(9, peersMessage.getPeers().size()); + assertEquals(9, peersMessage.getPeers().size()); PeerData peerData = peersMessage.getPeers().get(3); - Assert.assertEquals("/85.65.126.45", peerData.getInetAddress().toString()); - Assert.assertEquals(30303, peerData.getPort()); - Assert.assertEquals("82A8A5831D3B4FB76CF130CDC8A2B162A85D005D82A1DCC9B73239035EADE6347EDE2FFC86571ABE348EA38699CE886AA3D425FE58182C433434AB4CFD7B5B88", + assertEquals("/85.65.126.45", peerData.getInetAddress().toString()); + assertEquals(30303, peerData.getPort()); + assertEquals("82A8A5831D3B4FB76CF130CDC8A2B162A85D005D82A1DCC9B73239035EADE6347EDE2FFC86571ABE348EA38699CE886AA3D425FE58182C433434AB4CFD7B5B88", Utils.toHexString( peerData.getPeerId() ).toUpperCase()); } @@ -147,20 +139,20 @@ public class MessagesTest { PeersMessage peersMessage= new PeersMessage(rlpList); System.out.println(peersMessage); - Assert.assertEquals(77, peersMessage.getPeers().size()); + assertEquals(77, peersMessage.getPeers().size()); PeerData peerData = peersMessage.getPeers().get(7); - Assert.assertEquals("/191.234.57.55", peerData.getInetAddress().toString()); - Assert.assertEquals(30303, peerData.getPort()); - Assert.assertEquals("21780C55B47DB4B11467B5F55B0B555E0887CE36FBD975E224B1C70EAC7AB8E8C2DB37F0A48B90FFDD5A379ADA99B6A0F6429C4A53C25558191A682636AEF4F2", + assertEquals("/191.234.57.55", peerData.getInetAddress().toString()); + assertEquals(30303, peerData.getPort()); + assertEquals("21780C55B47DB4B11467B5F55B0B555E0887CE36FBD975E224B1C70EAC7AB8E8C2DB37F0A48B90FFDD5A379ADA99B6A0F6429C4A53C25558191A682636AEF4F2", Utils.toHexString( peerData.getPeerId() ).toUpperCase()); peerData = peersMessage.getPeers().get(75); - Assert.assertEquals("/86.124.82.254", peerData.getInetAddress().toString()); - Assert.assertEquals(30303, peerData.getPort()); - Assert.assertEquals("F6155F1A60143B7D9D5D1A440D7D52FE6809F69E0C6F1E0024457E0D71DD88ADE3B13AAA940C89AC0610952B48BD832C42E343A13E61FFDB06010CFFC345E053", + assertEquals("/86.124.82.254", peerData.getInetAddress().toString()); + assertEquals(30303, peerData.getPort()); + assertEquals("F6155F1A60143B7D9D5D1A440D7D52FE6809F69E0C6F1E0024457E0D71DD88ADE3B13AAA940C89AC0610952B48BD832C42E343A13E61FFDB06010CFFC345E053", Utils.toHexString( peerData.getPeerId() ).toUpperCase()); } @@ -200,42 +192,42 @@ public class MessagesTest { TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList); System.out.println(transactionsMessage); - Assert.assertEquals(1, transactionsMessage.getTransactions().size()); + assertEquals(1, transactionsMessage.getTransactions().size()); TransactionData tx = transactionsMessage.getTransactions().get(0); - Assert.assertEquals("558A3797E0DD3FBFAF761F1ADD6749C7D5DB313FDAC5CBA59F40E28AF7BBACD1", + assertEquals("558A3797E0DD3FBFAF761F1ADD6749C7D5DB313FDAC5CBA59F40E28AF7BBACD1", Utils.toHexString( tx.getHash() ).toUpperCase()); - Assert.assertEquals("04", + assertEquals("04", Utils.toHexString( tx.getNonce() ).toUpperCase()); - Assert.assertEquals("1BC16D674EC80000", + assertEquals("1BC16D674EC80000", Utils.toHexString( tx.getValue() ).toUpperCase()); - Assert.assertEquals("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826", + assertEquals("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826", Utils.toHexString( tx.getReceiveAddress() ).toUpperCase()); - Assert.assertEquals("09184E72A000", + assertEquals("09184E72A000", Utils.toHexString( tx.getGasPrice() ).toUpperCase()); - Assert.assertEquals("64", + assertEquals("64", Utils.toHexString( tx.getGas() ).toUpperCase()); - Assert.assertEquals("NULL", + assertEquals("NULL", Utils.toHexString( tx.getData() ).toUpperCase()); - Assert.assertEquals("NULL", + assertEquals("NULL", Utils.toHexString( tx.getInit() ).toUpperCase()); - Assert.assertEquals("1B", + assertEquals("1B", Utils.toHexString( new byte[] {tx.getSignatureV()} ).toUpperCase()); - Assert.assertEquals("5E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54", + assertEquals("5E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54", Utils.toHexString( tx.getSignatureR() ).toUpperCase()); - Assert.assertEquals("0FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467", + assertEquals("0FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467", Utils.toHexString( tx.getSignatureS() ).toUpperCase()); } @@ -253,79 +245,79 @@ public class MessagesTest { TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList); System.out.println(transactionsMessage); - Assert.assertEquals(3, transactionsMessage.getTransactions().size()); + assertEquals(3, transactionsMessage.getTransactions().size()); TransactionData tx = transactionsMessage.getTransactions().get(0); - Assert.assertEquals("4B7D9670A92BF120D5B43400543B69304A14D767CF836A7F6ABFF4EDDE092895", + assertEquals("4B7D9670A92BF120D5B43400543B69304A14D767CF836A7F6ABFF4EDDE092895", Utils.toHexString( tx.getHash() ).toUpperCase()); - Assert.assertEquals("NULL", + assertEquals("NULL", Utils.toHexString( tx.getNonce() ).toUpperCase()); - Assert.assertEquals("NULL", + assertEquals("NULL", Utils.toHexString( tx.getValue() ).toUpperCase()); - Assert.assertEquals("0000000000000000000000000000000000000000", + assertEquals("0000000000000000000000000000000000000000", Utils.toHexString( tx.getReceiveAddress() ).toUpperCase()); - Assert.assertEquals("09184E72A000", + assertEquals("09184E72A000", Utils.toHexString( tx.getGasPrice() ).toUpperCase()); - Assert.assertEquals("2710", + assertEquals("2710", Utils.toHexString( tx.getGas() ).toUpperCase()); - Assert.assertEquals("606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C58", + assertEquals("606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C58", Utils.toHexString( tx.getData() ).toUpperCase()); - Assert.assertEquals("33606957", + assertEquals("33606957", Utils.toHexString( tx.getInit() ).toUpperCase()); - Assert.assertEquals("1C", + assertEquals("1C", Utils.toHexString( new byte[] {tx.getSignatureV()} ).toUpperCase()); - Assert.assertEquals("7F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4", + assertEquals("7F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4", Utils.toHexString( tx.getSignatureR() ).toUpperCase()); - Assert.assertEquals("6D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC", + assertEquals("6D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC", Utils.toHexString( tx.getSignatureS() ).toUpperCase()); tx = transactionsMessage.getTransactions().get(2); - Assert.assertEquals("B0251A1BB20B44459DB5B5444AB53EDD9E12C46D0BA07FA401A797BEB967D53C", + assertEquals("B0251A1BB20B44459DB5B5444AB53EDD9E12C46D0BA07FA401A797BEB967D53C", Utils.toHexString( tx.getHash() ).toUpperCase()); - Assert.assertEquals("02", + assertEquals("02", Utils.toHexString( tx.getNonce() ).toUpperCase()); - Assert.assertEquals("NULL", + assertEquals("NULL", Utils.toHexString( tx.getValue() ).toUpperCase()); - Assert.assertEquals("CCDEAC59D35627B7DE09332E819D5159E7BB7250", + assertEquals("CCDEAC59D35627B7DE09332E819D5159E7BB7250", Utils.toHexString( tx.getReceiveAddress() ).toUpperCase()); - Assert.assertEquals("09184E72A000", + assertEquals("09184E72A000", Utils.toHexString( tx.getGasPrice() ).toUpperCase()); - Assert.assertEquals("2710", + assertEquals("2710", Utils.toHexString( tx.getGas() ).toUpperCase()); - Assert.assertEquals("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D0ACEEE7E5AB874E22CCF8D1A649F59106D74E8", + assertEquals("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D0ACEEE7E5AB874E22CCF8D1A649F59106D74E8", Utils.toHexString( tx.getData() ).toUpperCase()); - Assert.assertEquals("NULL", + assertEquals("NULL", Utils.toHexString( tx.getInit() ).toUpperCase()); - Assert.assertEquals("1B", + assertEquals("1B", Utils.toHexString( new byte[] {tx.getSignatureV()} ).toUpperCase()); - Assert.assertEquals("D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9", + assertEquals("D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9", Utils.toHexString( tx.getSignatureR() ).toUpperCase()); - Assert.assertEquals("1E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931B", + assertEquals("1E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931B", Utils.toHexString(tx.getSignatureS()).toUpperCase()); } @@ -347,7 +339,7 @@ public class MessagesTest { List list = blocksMessage.getBlockDataList(); System.out.println(blocksMessage); - Assert.assertEquals(1, list.size()); + assertEquals(1, list.size()); BlockData block = list.get(0); @@ -393,7 +385,7 @@ public class MessagesTest { System.out.println(blocksMessage); - Assert.assertEquals(32, list.size()); + assertEquals(32, list.size()); BlockData block = list.get(31); @@ -474,7 +466,7 @@ public class MessagesTest { NotInChainMessage notInChainMessage = new NotInChainMessage(rlpList); System.out.println(notInChainMessage); - Assert.assertEquals("E5E441F0877116011CCDECE2501A50B40C40418377037E16D0282B2B5E347138", + assertEquals("E5E441F0877116011CCDECE2501A50B40C40418377037E16D0282B2B5E347138", Utils.toHexString(notInChainMessage.getHash()).toUpperCase()); } diff --git a/ethereumj-core/src/test/java/org/ethereum/net/RLPTest.java b/ethereumj-core/src/test/java/org/ethereum/net/RLPTest.java index 3baf20a1..475e190d 100644 --- a/ethereumj-core/src/test/java/org/ethereum/net/RLPTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/net/RLPTest.java @@ -1,6 +1,7 @@ package org.ethereum.net; -import org.bouncycastle.util.encoders.Hex; +import org.spongycastle.util.encoders.Hex; +import org.ethereum.crypto.HashUtil; import org.ethereum.net.rlp.RLPList; import org.ethereum.util.Utils; import org.junit.Assert; @@ -15,11 +16,6 @@ import java.util.Queue; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 07/04/14 12:57 - */ public class RLPTest { @Test @@ -235,7 +231,7 @@ public class RLPTest { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; prevHash = RLP.encodeElement(prevHash); - /* 2 */ byte[] uncleList = Utils.sha3(RLP.encodeList(new byte[]{})); + /* 2 */ byte[] uncleList = HashUtil.sha3(RLP.encodeList(new byte[]{})); /* 3 */ byte[] coinbase = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/ethereumj-core/src/test/java/org/ethereum/serpent/TestCompile.java b/ethereumj-core/src/test/java/org/ethereum/serpent/TestCompile.java index 3997827a..4dcd0830 100644 --- a/ethereumj-core/src/test/java/org/ethereum/serpent/TestCompile.java +++ b/ethereumj-core/src/test/java/org/ethereum/serpent/TestCompile.java @@ -1,31 +1,21 @@ package org.ethereum.serpent; -import junit.framework.Assert; import org.antlr.runtime.ANTLRStringStream; import org.antlr.runtime.CharStream; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; import org.antlr.stringtemplate.StringTemplateGroup; import org.antlr.stringtemplate.language.AngleBracketTemplateLexer; -import org.bouncycastle.util.encoders.Hex; import org.ethereum.util.Utils; import org.junit.Test; import java.io.FileNotFoundException; import java.io.FileReader; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.Queue; -/** -* www.ethereumJ.com -* User: Roman Mandeleil -* Created on: 27/04/14 14:35 -*/ +import static org.junit.Assert.*; + public class TestCompile { - /* bin_expr ['+', 2, 1, ['<1>', '<0>', 'ADD']], V ['-', 2, 1, ['<1>', '<0>', 'SUB']], V @@ -40,9 +30,7 @@ public class TestCompile { @Test /* Test one symbol */ public void test0() throws FileNotFoundException, RecognitionException { - CharStream stream = - new ANTLRStringStream("" + - "A"); + CharStream stream = new ANTLRStringStream("" + "A"); SerpentLexer lex = new SerpentLexer(stream); CommonTokenStream tokens = new CommonTokenStream(lex); @@ -58,12 +46,9 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A", retVal.getTemplate().toString()); - + assertEquals("A", retVal.getTemplate().toString()); } - - @Test /* Test ADD 1*/ public void test1() throws FileNotFoundException, RecognitionException { @@ -85,8 +70,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B ADD", retVal.getTemplate().toString()); - + assertEquals("A B ADD", retVal.getTemplate().toString()); } @Test /* Test ADD 2*/ @@ -110,8 +94,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B ADD C1 ADD", retVal.getTemplate().toString()); - + assertEquals("A B ADD C1 ADD", retVal.getTemplate().toString()); } @Test /* Test SUB 1*/ @@ -135,8 +118,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B SUB", retVal.getTemplate().toString()); - + assertEquals("A B SUB", retVal.getTemplate().toString()); } @Test /* Test MUL 1*/ @@ -150,7 +132,6 @@ public class TestCompile { CommonTokenStream tokens = new CommonTokenStream(lex); SerpentParser parser = new SerpentParser(tokens); - String userDir = System.getProperty("user.dir"); String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg"; @@ -160,8 +141,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B MUL", retVal.getTemplate().toString()); - + assertEquals("A B MUL", retVal.getTemplate().toString()); } @@ -176,7 +156,6 @@ public class TestCompile { CommonTokenStream tokens = new CommonTokenStream(lex); SerpentParser parser = new SerpentParser(tokens); - String userDir = System.getProperty("user.dir"); String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg"; @@ -186,7 +165,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B DIV", retVal.getTemplate().toString()); + assertEquals("A B DIV", retVal.getTemplate().toString()); } @@ -211,7 +190,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B EXP", retVal.getTemplate().toString()); + assertEquals("A B EXP", retVal.getTemplate().toString()); } @@ -236,7 +215,9 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B MOD", retVal.getTemplate().toString()); + + + assertEquals("A B MOD", retVal.getTemplate().toString()); } @Test /* Test SDIV 1*/ @@ -260,7 +241,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B SDIV", retVal.getTemplate().toString()); + assertEquals("A B SDIV", retVal.getTemplate().toString()); } @@ -285,7 +266,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B SMOD", retVal.getTemplate().toString()); + assertEquals("A B SMOD", retVal.getTemplate().toString()); } @@ -311,7 +292,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B DIV C SUB D ADD ET MUL", retVal.getTemplate().toString()); + assertEquals("A B DIV C SUB D ADD ET MUL", retVal.getTemplate().toString()); } @@ -336,7 +317,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("A B DIV C SUB D ADD ET MUL ET2 MOD RO EXP RO2 ADD COOL SDIV HOT SMOD", + assertEquals("A B DIV C SUB D ADD ET MUL ET2 MOD RO EXP RO2 ADD COOL SDIV HOT SMOD", retVal.getTemplate().toString()); } @@ -372,7 +353,7 @@ public class TestCompile { SerpentParser.cond_expr_return retVal = parser.cond_expr(); - Assert.assertEquals("A B ADD B A ADD EQ", + assertEquals("A B ADD B A ADD EQ", retVal.getTemplate().toString()); } @@ -398,7 +379,7 @@ public class TestCompile { SerpentParser.cond_expr_return retVal = parser.cond_expr(); - Assert.assertEquals("A C ADD C A ADD LT", + assertEquals("A C ADD C A ADD LT", retVal.getTemplate().toString()); } @@ -424,7 +405,7 @@ public class TestCompile { SerpentParser.cond_expr_return retVal = parser.cond_expr(); - Assert.assertEquals("A C ADD C A ADD GT NOT", + assertEquals("A C ADD C A ADD GT NOT", retVal.getTemplate().toString()); } @@ -451,7 +432,7 @@ public class TestCompile { SerpentParser.cond_expr_return retVal = parser.cond_expr(); - Assert.assertEquals("A C ADD C A ADD GT", + assertEquals("A C ADD C A ADD GT", retVal.getTemplate().toString()); } @@ -478,7 +459,7 @@ public class TestCompile { SerpentParser.cond_expr_return retVal = parser.cond_expr(); - Assert.assertEquals("A C ADD C A ADD LT NOT", + assertEquals("A C ADD C A ADD LT NOT", retVal.getTemplate().toString()); } @@ -504,7 +485,7 @@ public class TestCompile { SerpentParser.unr_expr_return retVal = parser.unr_expr(); - Assert.assertEquals("A NOT", + assertEquals("A NOT", retVal.getTemplate().toString()); } @@ -531,7 +512,7 @@ public class TestCompile { SerpentParser.unr_expr_return retVal = parser.unr_expr(); - Assert.assertEquals("A NOT NOT", + assertEquals("A NOT NOT", retVal.getTemplate().toString()); } @@ -557,7 +538,7 @@ public class TestCompile { SerpentParser.unr_expr_return retVal = parser.unr_expr(); - Assert.assertEquals("A NOT NOT", + assertEquals("A NOT NOT", retVal.getTemplate().toString()); } @@ -583,7 +564,7 @@ public class TestCompile { SerpentParser.unr_expr_return retVal = parser.unr_expr(); - Assert.assertEquals("A NOT", + assertEquals("A NOT", retVal.getTemplate().toString()); } @@ -610,7 +591,7 @@ public class TestCompile { SerpentParser.program_return retVal = parser.program(); - Assert.assertEquals("10 0 MSTORE 20 32 MSTORE 30 64 MSTORE", + assertEquals("10 0 MSTORE 20 32 MSTORE 30 64 MSTORE", retVal.getTemplate().toString().trim()); } @@ -636,7 +617,7 @@ public class TestCompile { SerpentParser.program_return retVal = parser.program(); - Assert.assertEquals("10 0 MSTORE 20 32 MSTORE 30 0 MSTORE 40 32 MSTORE", + assertEquals("10 0 MSTORE 20 32 MSTORE 30 0 MSTORE 40 32 MSTORE", retVal.getTemplate().toString().trim()); } @@ -662,7 +643,7 @@ public class TestCompile { SerpentParser.if_else_stmt_return retVal = parser.if_else_stmt(); - Assert.assertEquals("", + assertEquals("", retVal.getTemplate().toString().trim()); } @@ -688,7 +669,7 @@ public class TestCompile { SerpentParser.storage_load_return retVal = parser.storage_load(); - Assert.assertEquals("0 SLOAD", + assertEquals("0 SLOAD", retVal.getTemplate().toString().trim()); } @@ -713,7 +694,7 @@ public class TestCompile { SerpentParser.storage_load_return retVal = parser.storage_load(); - Assert.assertEquals("100 SLOAD", + assertEquals("100 SLOAD", retVal.getTemplate().toString().trim()); } @@ -738,7 +719,7 @@ public class TestCompile { SerpentParser.storage_save_return retVal = parser.storage_save(); - Assert.assertEquals("200 100 SSTORE", + assertEquals("200 100 SSTORE", retVal.getTemplate().toString().trim()); } @@ -763,7 +744,7 @@ public class TestCompile { SerpentParser.storage_save_return retVal = parser.storage_save(); - Assert.assertEquals("200 3 4 ADD SSTORE", + assertEquals("200 3 4 ADD SSTORE", retVal.getTemplate().toString().trim()); } @@ -789,7 +770,7 @@ public class TestCompile { SerpentParser.storage_save_return retVal = parser.storage_save(); - Assert.assertEquals("200 100 ADD 100 SSTORE", // todo: have to optimize it somewhere in the future + assertEquals("200 100 ADD 100 SSTORE", // todo: have to optimize it somewhere in the future retVal.getTemplate().toString().trim()); } @@ -814,7 +795,7 @@ public class TestCompile { SerpentParser.msg_load_return retVal = parser.msg_load(); - Assert.assertEquals("0 32 MULL CALLDATALOAD", + assertEquals("0 32 MULL CALLDATALOAD", retVal.getTemplate().toString().trim()); } @@ -839,7 +820,7 @@ public class TestCompile { SerpentParser.msg_load_return retVal = parser.msg_load(); - Assert.assertEquals("10 20 ADD 32 MUL CALLDATALOAD", + assertEquals("10 20 ADD 32 MUL CALLDATALOAD", retVal.getTemplate().toString().trim()); } @@ -864,7 +845,7 @@ public class TestCompile { SerpentParser.bin_expr_return retVal = parser.bin_expr(); - Assert.assertEquals("0 32 MUL CALLDATALOAD 2 32 MUL CALLDATALOAD ADD", + assertEquals("0 32 MUL CALLDATALOAD 2 32 MUL CALLDATALOAD ADD", retVal.getTemplate().toString().trim()); } @@ -891,7 +872,7 @@ public class TestCompile { SerpentParser.storage_save_return retVal = parser.storage_save(); - Assert.assertEquals("1 32 MUL CALLDATALOAD 0 32 MUL CALLDATALOAD SSTORE", + assertEquals("1 32 MUL CALLDATALOAD 0 32 MUL CALLDATALOAD SSTORE", retVal.getTemplate().toString().trim()); } @@ -916,7 +897,7 @@ public class TestCompile { SerpentParser.unr_expr_return retVal = parser.unr_expr(); - Assert.assertEquals("0 32 MUL CALLDATALOAD SLOAD NOT", + assertEquals("0 32 MUL CALLDATALOAD SLOAD NOT", retVal.getTemplate().toString().trim()); } @@ -941,7 +922,7 @@ public class TestCompile { SerpentParser.test_1_return retVal = parser.test_1(); - Assert.assertEquals("20 0 MSTORE 20 32 MSTORE 32 MLOAD", + assertEquals("20 0 MSTORE 20 32 MSTORE 32 MLOAD", retVal.getTemplate().toString().trim()); } @@ -966,7 +947,7 @@ public class TestCompile { SerpentParser.test_1_return retVal = parser.test_1(); - Assert.assertEquals("20 0 MSTORE 20 32 MSTORE 20 64 MSTORE 64 MLOAD", + assertEquals("20 0 MSTORE 20 32 MSTORE 20 64 MSTORE 64 MLOAD", retVal.getTemplate().toString().trim()); } @@ -996,7 +977,7 @@ public class TestCompile { SerpentParser.if_else_stmt_return retVal = parser.if_else_stmt(); - Assert.assertEquals("", + assertEquals("", retVal.getTemplate().toString().trim()); } @@ -1038,7 +1019,7 @@ public class TestCompile { SerpentParser.gen_body_return retVal = parser.gen_body(); - Assert.assertEquals("", + assertEquals("", retVal.getTemplate().toString().trim()); } @@ -1065,16 +1046,7 @@ public class TestCompile { SerpentParser.hex_num_return retVal = parser.hex_num(); - Assert.assertEquals(Utils.hexStringToDecimalString(hexNum), + assertEquals(Utils.hexStringToDecimalString(hexNum), retVal.getTemplate().toString().trim()); - - - } - - - - - - } diff --git a/ethereumj-core/src/test/java/org/ethereum/transaction/TransactionTest.java b/ethereumj-core/src/test/java/org/ethereum/transaction/TransactionTest.java index 8d8025a2..97749698 100644 --- a/ethereumj-core/src/test/java/org/ethereum/transaction/TransactionTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/transaction/TransactionTest.java @@ -1,114 +1,44 @@ package org.ethereum.transaction; -import org.bouncycastle.asn1.sec.SECNamedCurves; -import org.bouncycastle.asn1.x9.X9ECParameters; -import org.bouncycastle.util.encoders.Hex; -import org.ethereum.util.Utils; -import org.junit.Test; - -import javax.crypto.Mac; -import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.math.BigInteger; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 20/04/14 14:21 - */ +import org.ethereum.crypto.ECKey; +import org.ethereum.crypto.HashUtil; +import org.junit.Test; +import org.spongycastle.util.encoders.Hex; + public class TransactionTest { - - @Test /* sign transaction https://tools.ietf.org/html/rfc6979 */ public void test1() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, IOException { //python taken exact data String txRLPRawData = "a9e880872386f26fc1000085e8d4a510008203e89413978aee95f38490e9769c39b2773ed763d9cd5f80"; + // String txRLPRawData = "f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480"; -// String txRLPRawData = "f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480"; - String cowPrivKey = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4"; + byte[] cowPrivKey = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4"); + ECKey key = ECKey.fromPrivate(cowPrivKey); byte[] data = Hex.decode(txRLPRawData); - byte[] privKey = Hex.decode(cowPrivKey); // step 1: serialize + RLP encode // step 2: hash = sha3(step1) - byte[] txHash = Utils.sha3(data); - - X9ECParameters curvParams = SECNamedCurves.getByName("secp256k1"); - -// z = hash_to_int(msghash) -// k = deterministic_generate_k(msghash,priv) - BigInteger txHashInt = new BigInteger(1, txHash ); - -/* - v = '\x01' * 32 - k = '\x00' * 32 - priv = encode_privkey(priv,'bin') - msghash = encode(hash_to_int(msghash),256,32) - k = hmac.new(k, v+'\x00'+priv+msghash, hashlib.sha256).digest() - v = hmac.new(k, v, hashlib.sha256).digest() - k = hmac.new(k, v+'\x01'+priv+msghash, hashlib.sha256).digest() - v = hmac.new(k, v, hashlib.sha256).digest() - return decode(hmac.new(k, v, hashlib.sha256).digest(),256) -*/ - byte[] v = { - 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, - 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, - 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, - 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 - }; - - byte[] k = { - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 - }; - - Mac hmac = Mac.getInstance("HMac-SHA256", "BC"); - - SecretKey secretKey = new SecretKeySpec(k, "HMac-SHA256"); - - hmac.init(secretKey); - hmac.reset(); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(v.length + 1 + privKey.length + txHash.length); - baos.write(v); - baos.write(new byte[]{00}); - baos.write(privKey); - baos.write(txHash); - - hmac.update(baos.toByteArray()); - byte[] k_ = hmac.doFinal(secretKey.getEncoded()); - - - System.out.println(Hex.toHexString(k_)); - - + byte[] txHash = HashUtil.sha3(data); + String signature = key.doSign(txHash).toBase64(); + System.out.println(signature); } @Test /* achieve public key of the sender */ public void test2(){ -// http://etherchain.org/#/tx/558a3797e0dd3fbfaf761f1add6749c7d5db313fdac5cba59f40e28af7bbacd1 -// f86b04881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a00064801ba05e3868194605f1647593b842725818ccfa6a38651a728715133a8e97cdcfac54a00ff91628d04b215ebccfd5f4fc34cc1b45df32f6b4609fbb0de42e8522264467 - -// [ 0x12, [ 0x4, 0x1BC16D674EC80000, 0xCD2A3D9F938E13CD947EC05ABC7FE734DF8DD826, 0x9184E72A000, 0x64, 0x0, -// 0x1B, 0x5E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54, 0xFF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467 ] ] -// sender: d4bfbf8d0f435c2ee2b4e3680018f1892fc1fba6 - String rawTX = "F86B04881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA05E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54A00FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467"; byte[] rawTxBytes = Hex.decode(rawTX); - String txHash = Hex.toHexString(Utils.sha3(rawTxBytes)); + String txHash = Hex.toHexString(HashUtil.sha3(rawTxBytes)); System.out.println(txHash); }