diff --git a/ethereumj-core/src/main/java/org/ethereum/geodb/IpGeoDB.java b/ethereumj-core/src/main/java/org/ethereum/geodb/IpGeoDB.java new file mode 100644 index 00000000..b691c989 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/geodb/IpGeoDB.java @@ -0,0 +1,49 @@ +package org.ethereum.geodb; + +import com.maxmind.geoip.Location; +import com.maxmind.geoip.LookupService; +import com.maxmind.geoip2.DatabaseReader; +import com.maxmind.geoip2.exception.GeoIp2Exception; +import com.maxmind.geoip2.model.CityResponse; + +import java.io.File; +import java.io.IOException; +import java.net.InetAddress; +import java.net.URISyntaxException; +import java.net.URL; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 24/04/14 20:11 + */ +public class IpGeoDB { + + static{ + try { + + URL geiIpDBFile = ClassLoader.getSystemResource("GeoLiteCity.dat"); + File file = new File(geiIpDBFile.toURI()); + cl = new LookupService(file); + + } catch (Throwable e) { + e.printStackTrace(); + } + } + + private static LookupService cl; + + + public static Location getLocationForIp(InetAddress ip){ + try { + return cl.getLocation(ip); + } catch (Throwable e) { + + // todo: think about this exception, maybe you can do something more reasonable + System.out.println(e.getMessage()); +// e.printStackTrace(); + } + + return null; + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ConnectionConsole.java b/ethereumj-core/src/main/java/org/ethereum/gui/ConnectionConsole.java new file mode 100644 index 00000000..f63853d8 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ConnectionConsole.java @@ -0,0 +1,103 @@ +package org.ethereum.gui; + +import org.ethereum.net.client.ClientPeer; +import org.fife.ui.rsyntaxtextarea.*; +import org.fife.ui.rtextarea.RTextScrollPane; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.io.IOException; +import java.util.TimerTask; + +/** + * A simple example showing how to modify the fonts and colors used in an + * RSyntaxTextArea. There are two methods to do this - via the Java API, and via + * an XML file. The latter method is preferred since it's more modular, and + * provides a way for your users to customize RSTA in your application.

+ * + * This example uses RSyntaxTextArea 2.0.1.

+ * + * Project Home: http://fifesoft.com/rsyntaxtextarea
+ * Downloads: https://sourceforge.net/projects/rsyntaxtextarea + */ +public class ConnectionConsole extends JFrame implements PeerListener{ + + private static final long serialVersionUID = 1L; + + private RSyntaxTextArea textArea; + + + public ConnectionConsole() { + + final ConnectionConsole thisConsole = this; + + java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png"); + Toolkit kit = Toolkit.getDefaultToolkit(); + Image img = kit.createImage(url); + this.setIconImage(img); + + JPanel cp = new JPanel(new BorderLayout()); + + textArea = new RSyntaxTextArea(16, 47); + textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_LISP); + textArea.setCodeFoldingEnabled(true); + textArea.setAntiAliasingEnabled(true); + RTextScrollPane sp = new RTextScrollPane(textArea); + cp.add(sp); + + setContentPane(cp); + setTitle("Connection Console"); +// setDefaultCloseOperation(EXIT_ON_CLOSE); + pack(); + setLocation(775, 390); + + this.addComponentListener(new ComponentAdapter() { + + @Override + public void componentShown(ComponentEvent e) { + + Thread t = new Thread() { + public void run() { +// new ClientPeer(thisConsole).connect("54.201.28.117", 30303); + new ClientPeer(thisConsole).connect("82.217.72.169", 30303); + } + }; + t.start(); + + + + } + + }); + + } + + @Override + public void console(final String output) { + + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + textArea.append(output); + textArea.append("\n"); + textArea.setCaretPosition(textArea.getText().length()); + } + }); + + + } + + public static void main(String[] args) { + // Start all Swing applications on the EDT. + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new ConnectionConsole().setVisible(true); + } + }); + + } + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/PeerListener.java b/ethereumj-core/src/main/java/org/ethereum/gui/PeerListener.java new file mode 100644 index 00000000..cf2c80fd --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/gui/PeerListener.java @@ -0,0 +1,11 @@ +package org.ethereum.gui; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 30/04/14 11:32 + */ +public interface PeerListener { + + public void console(String output); +} diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/PeersTableModel.java b/ethereumj-core/src/main/java/org/ethereum/gui/PeersTableModel.java new file mode 100644 index 00000000..8f27038f --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/gui/PeersTableModel.java @@ -0,0 +1,166 @@ +package org.ethereum.gui; + +import com.maxmind.geoip.Location; +import com.maxmind.geoip2.model.CityResponse; +import org.ethereum.geodb.IpGeoDB; +import org.ethereum.util.Utils; + +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import java.net.InetAddress; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 25/04/14 07:04 + */ +public class PeersTableModel extends AbstractTableModel { + + List peerInfoList = new ArrayList(); + + public PeersTableModel() { + + generateRandomData(); + } + + + + public String getColumnName(int column) { + + if (column == 0) return "Location"; + if (column == 1) return "IP"; + if (column == 2) return "Live"; + else return ""; + } + + public boolean isCellEditable(int row, int column) { + return false; + } + + public Class getColumnClass(int column) { + if (column == 0) return ImageIcon.class; + if (column == 1) return String.class; + if (column == 2) return ImageIcon.class; + else return String.class; + } + + public Object getValueAt(int row, int column) { + + PeerInfo peerInfo = peerInfoList.get(row); + + if (column == 0){ + + String countryCode = peerInfo.getLocation().countryCode; + URL flagURL = ClassLoader.getSystemResource("flags/" + countryCode + ".png"); + ImageIcon flagIcon = new ImageIcon(flagURL); + + + return flagIcon; + } + + if (column == 1) return peerInfo.getIp().getHostAddress(); + if (column == 2) { + + Random random = new Random(); + boolean isConnected = random.nextBoolean(); + + ImageIcon flagIcon = null; + if (peerInfo.connected){ + + flagIcon = Utils.getImageIcon("connected.png"); + } else { + + flagIcon = Utils.getImageIcon("disconnected.png"); + } + + + return flagIcon; + } + + else return ""; + } + + public int getRowCount() { + return this.peerInfoList.size(); + } + + public int getColumnCount() { + return 3; + } + + + + // todo: delete it when stabilized + private void generateRandomData(){ + + List ips = new ArrayList(); + ips.add("206.223.168.190"); + ips.add("94.210.200.192"); + ips.add("88.69.198.198"); + ips.add("62.78.198.208"); + ips.add("71.202.162.40"); + ips.add("78.55.236.218"); + ips.add("94.197.120.80"); + ips.add("85.65.126.45"); + + ips.add("110.77.217.185"); + ips.add("64.231.9.30"); + ips.add("162.243.203.121"); + ips.add("82.217.72.169"); + + ips.add("99.231.80.166"); + ips.add("131.104.252.4"); + ips.add("54.204.10.41"); + ips.add("54.201.28.117"); + ips.add("82.240.16.5"); + ips.add("74.79.23.119"); + + + for (String peer : ips){ + + try { + + InetAddress addr = InetAddress.getByName(peer); + Location cr = IpGeoDB.getLocationForIp(addr); + + peerInfoList.add(new PeerInfo(cr, addr)); + + } catch (UnknownHostException e) {e.printStackTrace(); } + } + } + + private class PeerInfo{ + + Location location; + InetAddress ip; + boolean connected; + + private PeerInfo(Location location, InetAddress ip) { + this.location = location; + this.ip = ip; + + Random random = new Random(); + connected = random.nextBoolean(); + } + + private InetAddress getIp() { + return ip; + } + + + private Location getLocation() { + return location; + } + + private boolean isConnected() { + return connected; + } + } +} + + diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java b/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java new file mode 100644 index 00000000..40be180c --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java @@ -0,0 +1,121 @@ +package org.ethereum.gui; + +import org.ethereum.serpent.SerpentCompiler; +import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory; +import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; +import org.fife.ui.rsyntaxtextarea.TokenMakerFactory; +import org.fife.ui.rtextarea.RTextScrollPane; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 24/04/14 11:32 + */ + + +public class SerpentEditor extends JFrame { + + private String codeSample = "\n\n\n" + + "" + + "if !contract.storage[msg.data[0]]:\n" + + " contract.storage[msg.data[0]] = msg.data[1]\n" + + " return(1)\n" + + "else:\n" + + " return(0)\n"; + + + private static final long serialVersionUID = 1L; + + public SerpentEditor() { + + final JPanel cp = new JPanel(new BorderLayout()); + final JFrame mainWindow = this; + + java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png"); + Toolkit kit = Toolkit.getDefaultToolkit(); + Image img = kit.createImage(url); + this.setIconImage(img); + this.setLocation(30, 80); + + AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory)TokenMakerFactory.getDefaultInstance(); + atmf.putMapping("text/serpent", "org.ethereum.gui.SerpentTokenMaker"); + + final RSyntaxTextArea codeArea = new RSyntaxTextArea(32, 80); + codeArea.setSyntaxEditingStyle("text/serpent"); + codeArea.setCodeFoldingEnabled(true); + codeArea.setAntiAliasingEnabled(true); + codeArea.setText(codeSample); + + RTextScrollPane sp = new RTextScrollPane(codeArea); + + sp.setFoldIndicatorEnabled(true); + cp.setLayout(new BorderLayout()); + + final JSplitPane splitPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT); + splitPanel.setOneTouchExpandable(true); + splitPanel.setDividerSize(5); + splitPanel.setContinuousLayout(true); + + cp.add(splitPanel, BorderLayout.CENTER); + splitPanel.add(sp); + + final JTextArea result = new JTextArea(); + result.setLineWrap(true); + result.setWrapStyleWord(true); + result.setVisible(false); + + splitPanel.add(result); + + JPanel controlsPanel = new JPanel(); + FlowLayout fl = new FlowLayout(FlowLayout.LEADING, 30, 5); + fl.setAlignment(FlowLayout.RIGHT); + controlsPanel.setLayout(fl); + + JButton buildButton = new JButton("Build"); + buildButton.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + + String asmResult = ""; + try { + asmResult = SerpentCompiler.compile(codeArea.getText()); + } catch (Throwable th) {th.printStackTrace();} + + splitPanel.setDividerLocation(0.7); + + result.setVisible(true); + result.setText(asmResult); + } + }); + + + controlsPanel.add(buildButton); + + cp.add(controlsPanel, BorderLayout.SOUTH); + + + setContentPane(cp); + setTitle("Serpent Editor"); +// setDefaultCloseOperation(EXIT_ON_CLOSE); + pack(); +// setLocationRelativeTo(null); + + } + + public static void main(String[] args) { + // Start all Swing applications on the EDT. + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new SerpentEditor().setVisible(true); + } + }); + } + + +} \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/SerpentTokenMaker.java b/ethereumj-core/src/main/java/org/ethereum/gui/SerpentTokenMaker.java new file mode 100644 index 00000000..f77c8f0b --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/gui/SerpentTokenMaker.java @@ -0,0 +1,508 @@ +package org.ethereum.gui; + +import javax.swing.text.Segment; + +import org.fife.ui.rsyntaxtextarea.*; + + + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 24/04/14 11:52 + */ + +public class SerpentTokenMaker extends AbstractTokenMaker { + +// http://fifesoft.com/rsyntaxtextarea/doc/CustomSyntaxHighlighting.html + + protected final String operators = ".@:*<>=?|!"; + + private int currentTokenStart; + private int currentTokenType; + + private boolean bracketVariable; // Whether a variable is of the format %{...} + + + /** + * Constructor. + */ + public SerpentTokenMaker() { + super(); // Initializes tokensToHighlight. + } + + + /** + * Checks the token to give it the exact ID it deserves before + * being passed up to the super method. + * + * @param segment Segment to get text from. + * @param start Start offset in segment of token. + * @param end End offset in segment of token. + * @param tokenType The token's type. + * @param startOffset The offset in the document at which the token occurs. + */ + @Override + public void addToken(Segment segment, int start, int end, int tokenType, int startOffset) { + + switch (tokenType) { + // Since reserved words, functions, and data types are all passed + // into here as "identifiers," we have to see what the token + // really is... + case Token.IDENTIFIER: + int value = wordsToHighlight.get(segment, start,end); + if (value!=-1) + tokenType = value; + break; + } + + super.addToken(segment, start, end, tokenType, startOffset); + + } + + + /** + * Returns the text to place at the beginning and end of a + * line to "comment" it in a this programming language. + * + * @return The start and end strings to add to a line to "comment" + * it out. + */ + @Override + public String[] getLineCommentStartAndEnd() { + return new String[] { "#", null }; + } + + + /** + * Returns whether tokens of the specified type should have "mark + * occurrences" enabled for the current programming language. + * + * @param type The token type. + * @return Whether tokens of this type should have "mark occurrences" + * enabled. + */ + @Override + public boolean getMarkOccurrencesOfTokenType(int type) { + return type==Token.IDENTIFIER || type==Token.VARIABLE; + } + + + /** + * Returns the words to highlight for Windows batch files. + * + * @return A TokenMap containing the words to highlight for + * Windows batch files. + * @see org.fife.ui.rsyntaxtextarea.AbstractTokenMaker#getWordsToHighlight + */ + @Override + public TokenMap getWordsToHighlight() { + + TokenMap tokenMap = new TokenMap(true); // Ignore case. + + int reservedWord = Token.RESERVED_WORD; + tokenMap.put("set", reservedWord); + tokenMap.put("if", reservedWord); + tokenMap.put("else", reservedWord); + tokenMap.put("elif", reservedWord); + tokenMap.put("seq", reservedWord); + tokenMap.put("while", reservedWord); + tokenMap.put("byte", reservedWord); + tokenMap.put("access", reservedWord); + tokenMap.put("arrset", reservedWord); + tokenMap.put("set_and_inc", reservedWord); + tokenMap.put("array", reservedWord); + tokenMap.put("getch", reservedWord); + tokenMap.put("setch", reservedWord); + tokenMap.put("string", reservedWord); + tokenMap.put("send", reservedWord); + tokenMap.put("create", reservedWord); + tokenMap.put("sha3", reservedWord); + tokenMap.put("sha3bytes", reservedWord); + tokenMap.put("sload", reservedWord); + tokenMap.put("sstore", reservedWord); + tokenMap.put("calldataload", reservedWord); + tokenMap.put("id", reservedWord); + tokenMap.put("return", reservedWord); + tokenMap.put("suicide", reservedWord); + + + tokenMap.put("stop", reservedWord); + + int function = Token.FUNCTION; + tokenMap.put("msg", function); + tokenMap.put("contract", function); + tokenMap.put("block", function); + tokenMap.put("tx", function); + + + return tokenMap; + + } + + + /** + * Returns a peerInfoList of tokens representing the given text. + * + * @param text The text to break into tokens. + * @param startTokenType The token with which to start tokenizing. + * @param startOffset The offset at which the line of tokens begins. + * @return A linked peerInfoList of tokens representing text. + */ + public Token getTokenList(Segment text, int startTokenType, final int startOffset) { + + resetTokenList(); + + char[] array = text.array; + int offset = text.offset; + int count = text.count; + int end = offset + count; + + // See, when we find a token, its starting position is always of the form: + // 'startOffset + (currentTokenStart-offset)'; but since startOffset and + // offset are constant, tokens' starting positions become: + // 'newStartOffset+currentTokenStart' for one less subtraction operation. + int newStartOffset = startOffset - offset; + + currentTokenStart = offset; + currentTokenType = startTokenType; + +//beginning: + for (int i=offset; i-1) { + addToken(text, currentTokenStart,i, Token.OPERATOR, newStartOffset+currentTokenStart); + currentTokenType = Token.NULL; + break; + } + else { + currentTokenType = Token.IDENTIFIER; + break; + } + + } // End of switch (c). + + break; + + case Token.WHITESPACE: + + switch (c) { + + case ' ': + case '\t': + break; // Still whitespace. + + case '"': + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.ERROR_STRING_DOUBLE; + break; + + case '%': + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.VARIABLE; + break; + + // The "separators". + case '(': + case ')': + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + addToken(text, i,i, Token.SEPARATOR, newStartOffset+i); + currentTokenType = Token.NULL; + break; + + // The "separators2". + case ',': + case ';': + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + addToken(text, i,i, Token.IDENTIFIER, newStartOffset+i); + currentTokenType = Token.NULL; + break; + + // Newer version of EOL comments, or a label + case ':': + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + currentTokenStart = i; + // If the previous (whitespace) token was the first token + // added, this is a new-style comment or a label + if (firstToken.getNextToken()==null) { + if (i-1) { + addToken(text, currentTokenStart,i, Token.OPERATOR, newStartOffset+currentTokenStart); + currentTokenType = Token.NULL; + break; + } + else { + currentTokenType = Token.IDENTIFIER; + } + + } // End of switch (c). + + break; + + default: // Should never happen + case Token.IDENTIFIER: + + switch (c) { + + case ' ': + case '\t': + // Check for REM comments. + if (i-currentTokenStart==3 && + (array[i-3]=='r' || array[i-3]=='R') && + (array[i-2]=='e' || array[i-2]=='E') && + (array[i-1]=='m' || array[i-1]=='M')) { + currentTokenType = Token.COMMENT_EOL; + break; + } + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.WHITESPACE; + break; + + case '"': + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.ERROR_STRING_DOUBLE; + break; + + case '%': + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.VARIABLE; + break; + + // Should be part of identifiers, but not at end of "REM". + case '\\': + // Check for REM comments. + if (i-currentTokenStart==3 && + (array[i-3]=='r' || array[i-3]=='R') && + (array[i-2]=='e' || array[i-2]=='E') && + (array[i-1]=='m' || array[i-1]=='M')) { + currentTokenType = Token.COMMENT_EOL; + } + break; + +// case '.': + case '_': + break; // Characters good for identifiers. + + // The "separators". + case '(': + case ')': + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + addToken(text, i,i, Token.SEPARATOR, newStartOffset+i); + currentTokenType = Token.NULL; + break; + + // The "separators2". + case ',': + case ';': + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + addToken(text, i,i, Token.IDENTIFIER, newStartOffset+i); + currentTokenType = Token.NULL; + break; + + default: + + // Just to speed things up a tad, as this will usually be the case. + if (RSyntaxUtilities.isLetterOrDigit(c) || c=='\\') { + break; + } + + int indexOf = operators.indexOf(c); + if (indexOf>-1) { + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + addToken(text, i,i, Token.OPERATOR, newStartOffset+i); + currentTokenType = Token.NULL; + break; + } + + // Otherwise, fall through and assume we're still okay as an IDENTIFIER... + + } // End of switch (c). + + break; + + case Token.COMMENT_EOL: + i = end - 1; + addToken(text, currentTokenStart,i, Token.COMMENT_EOL, newStartOffset+currentTokenStart); + // We need to set token type to null so at the bottom we don't add one more token. + currentTokenType = Token.NULL; + break; + + case Token.PREPROCESSOR: // Used for labels + i = end - 1; + addToken(text, currentTokenStart,i, Token.PREPROCESSOR, newStartOffset+currentTokenStart); + // We need to set token type to null so at the bottom we don't add one more token. + currentTokenType = Token.NULL; + break; + + case Token.ERROR_STRING_DOUBLE: + + if (c=='"') { + addToken(text, currentTokenStart,i, Token.LITERAL_STRING_DOUBLE_QUOTE, newStartOffset+currentTokenStart); + currentTokenStart = i + 1; + currentTokenType = Token.NULL; + } + // Otherwise, we're still an unclosed string... + + break; + + case Token.VARIABLE: + + if (i==currentTokenStart+1) { // first character after '%'. + bracketVariable = false; + switch (c) { + case '{': + bracketVariable = true; + break; + default: + if (RSyntaxUtilities.isLetter(c) || c==' ') { // No tab, just space; spaces are okay in variable names. + break; + } + else if (RSyntaxUtilities.isDigit(c)) { // Single-digit command-line argument ("%1"). + addToken(text, currentTokenStart,i, Token.VARIABLE, newStartOffset+currentTokenStart); + currentTokenType = Token.NULL; + break; + } + else { // Anything else, ???. + addToken(text, currentTokenStart,i-1, Token.VARIABLE, newStartOffset+currentTokenStart); // ??? + i--; + currentTokenType = Token.NULL; + break; + } + } // End of switch (c). + } + else { // Character other than first after the '%'. + if (bracketVariable==true) { + if (c=='}') { + addToken(text, currentTokenStart,i, Token.VARIABLE, newStartOffset+currentTokenStart); + currentTokenType = Token.NULL; + } + } + else { + if (c=='%') { + addToken(text, currentTokenStart,i, Token.VARIABLE, newStartOffset+currentTokenStart); + currentTokenType = Token.NULL; + } + } + break; + } + break; + + } // End of switch (currentTokenType). + + } // End of for (int i=offset; i + * + * This example uses RSyntaxTextArea 2.0.1.

+ * + * Project Home: http://fifesoft.com/rsyntaxtextarea
+ * Downloads: https://sourceforge.net/projects/rsyntaxtextarea + */ +public class SyntaxSchemeDemo extends JFrame implements ActionListener { + + private static final long serialVersionUID = 1L; + + private RSyntaxTextArea textArea; + + private static final String text = "public class ExampleSource {\n\n" + + " // Check out the crazy modified styles!\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Hello, world!\");\n" + " }\n\n" + + "}\n"; + + public SyntaxSchemeDemo() { + + java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png"); + Toolkit kit = Toolkit.getDefaultToolkit(); + Image img = kit.createImage(url); + this.setIconImage(img); + + JPanel cp = new JPanel(new BorderLayout()); + + textArea = new RSyntaxTextArea(20, 60); + textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); + textArea.setCodeFoldingEnabled(true); + textArea.setAntiAliasingEnabled(true); + RTextScrollPane sp = new RTextScrollPane(textArea); + cp.add(sp); + +// JPanel buttons = new JPanel(); +// buttons.setLayout(new FlowLayout()); +// buttons.add(new JButton("build")); +// +// cp.add(buttons, BorderLayout.SOUTH); + + textArea.setText(text); + + JMenuBar mb = new JMenuBar(); + JMenu menu = new JMenu("File"); + mb.add(menu); + JMenuItem changeStyleProgrammaticallyItem = new JMenuItem( + "Change Style Programmatically"); + changeStyleProgrammaticallyItem + .setActionCommand("ChangeProgrammatically"); + changeStyleProgrammaticallyItem.addActionListener(this); + menu.add(changeStyleProgrammaticallyItem); + JMenuItem changeStyleViaThemesItem = new JMenuItem( + "Change Style via Theme XML"); + changeStyleViaThemesItem.setActionCommand("ChangeViaThemes"); + changeStyleViaThemesItem.addActionListener(this); + menu.add(changeStyleViaThemesItem); +// setJMenuBar(mb); + + setContentPane(cp); + setTitle("Connection Console"); + setDefaultCloseOperation(EXIT_ON_CLOSE); + pack(); + setLocationRelativeTo(null); + + } + + /** + * Listens for the selection of a menu item and performs an action + * accordingly. + */ + public void actionPerformed(ActionEvent e) { + String command = e.getActionCommand(); + if ("ChangeProgrammatically".equals(command)) { + changeStyleProgrammatically(); + } else if ("ChangeViaThemes".equals(command)) { + changeStyleViaThemeXml(); + } + } + + /** + * Changes the styles used in the editor programmatically. + */ + private void changeStyleProgrammatically() { + + // Set the font for all token types. + setFont(textArea, new Font("Comic Sans MS", Font.PLAIN, 16)); + + // Change a few things here and there. + SyntaxScheme scheme = textArea.getSyntaxScheme(); + scheme.getStyle(Token.RESERVED_WORD).background = Color.pink; + scheme.getStyle(Token.DATA_TYPE).foreground = Color.blue; + scheme.getStyle(Token.LITERAL_STRING_DOUBLE_QUOTE).underline = true; + scheme.getStyle(Token.COMMENT_EOL).font = new Font("Georgia", + Font.ITALIC, 12); + + textArea.revalidate(); + + } + + /** + * Changes the styles used by the editor via an XML file specification. This + * method is preferred because of its ease and modularity. + */ + private void changeStyleViaThemeXml() { + try { + Theme theme = Theme.load(getClass().getResourceAsStream( + "/eclipse_theme.xml")); + theme.apply(textArea); + } catch (IOException ioe) { // Never happens + ioe.printStackTrace(); + } + } + + /** + * Set the font for all token types. + * + * @param textArea The text area to modify. + * @param font The font to use. + */ + public static void setFont(RSyntaxTextArea textArea, Font font) { + if (font != null) { + SyntaxScheme ss = textArea.getSyntaxScheme(); + ss = (SyntaxScheme) ss.clone(); + for (int i = 0; i < ss.getStyleCount(); i++) { + if (ss.getStyle(i) != null) { + ss.getStyle(i).font = font; + } + } + textArea.setSyntaxScheme(ss); + textArea.setFont(font); + } + } + + public static void main(String[] args) { + // Start all Swing applications on the EDT. + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new SyntaxSchemeDemo().setVisible(true); + } + }); + } + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java b/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java new file mode 100644 index 00000000..becd2806 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java @@ -0,0 +1,126 @@ +package org.ethereum.gui; + +import samples.PeersTableMain; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 30/04/14 06:29 + */ +public class ToolBar extends JFrame { + + public ToolBar() throws HeadlessException { + final JPanel cp = new JPanel(new FlowLayout()); + cp.setBackground(Color.WHITE); + + java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png"); + Toolkit kit = Toolkit.getDefaultToolkit(); + Image img = kit.createImage(url); + this.setIconImage(img); + this.setSize(350, 130); + this.setLocation(460, 25); + this.setAlwaysOnTop(true); + this.setResizable(false); + this.setBackground(Color.WHITE); + + setTitle("EthereumJ Studio"); + setDefaultCloseOperation(EXIT_ON_CLOSE); + + this.setContentPane(cp); + + + java.net.URL imageURL_1 = ClassLoader.getSystemResource("buttons/feedly.png"); + ImageIcon image_1 = new ImageIcon(imageURL_1); + + java.net.URL imageURL_2 = ClassLoader.getSystemResource("buttons/winamp.png"); + ImageIcon image_2 = new ImageIcon(imageURL_2); + + java.net.URL imageURL_3 = ClassLoader.getSystemResource("buttons/browser.png"); + ImageIcon image_3 = new ImageIcon(imageURL_3); + + + + JToggleButton editorToggle = new JToggleButton(""); + editorToggle.setIcon(image_1); + editorToggle.setContentAreaFilled(true); + editorToggle.setToolTipText("Serpent Editor"); + editorToggle.setBackground(Color.WHITE); + editorToggle.setBorderPainted(false); + editorToggle.setFocusPainted(false); + editorToggle.setCursor(new Cursor(Cursor.HAND_CURSOR)); + editorToggle.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new SerpentEditor().setVisible(true); + } + }); + } + }); + + JToggleButton logToggle = new JToggleButton(); + logToggle.setIcon(image_2); + logToggle.setToolTipText("Log Console"); + logToggle.setContentAreaFilled(true); + logToggle.setBackground(Color.WHITE); + logToggle.setBorderPainted(false); + logToggle.setFocusPainted(false); + logToggle.setCursor(new Cursor(Cursor.HAND_CURSOR)); + logToggle.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new ConnectionConsole().setVisible(true); + } + }); + } + }); + + JToggleButton peersToggle = new JToggleButton(); + peersToggle.setIcon(image_3); + peersToggle.setToolTipText("Peers"); + peersToggle.setContentAreaFilled(true); + peersToggle.setBackground(Color.WHITE); + peersToggle.setBorderPainted(false); + peersToggle.setFocusPainted(false); + peersToggle.setCursor(new Cursor(Cursor.HAND_CURSOR)); + peersToggle.addActionListener( new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + PeersTableMain mainFrame = new PeersTableMain(); + mainFrame.setVisible( true ); +// mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + + } + }); + + + cp.add(editorToggle); + cp.add(logToggle); + cp.add(peersToggle); + + + + + + } + + public static void main(String args[]){ + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new ToolBar().setVisible(true); + } + }); + + } + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java b/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java new file mode 100644 index 00000000..d66e8981 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java @@ -0,0 +1,42 @@ +package org.ethereum.manager; + +import com.maxmind.geoip.Location; +import com.maxmind.geoip2.model.CityResponse; +import com.maxmind.geoip2.record.Country; +import org.ethereum.geodb.IpGeoDB; +import org.ethereum.net.vo.PeerData; + +import java.util.*; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 21/04/14 20:35 + */ +public class MainData { + + private Set peers = Collections.synchronizedSet(new HashSet()); + + private List blocks = Collections.synchronizedList(new ArrayList()); + private List transactions = Collections.synchronizedList(new ArrayList()); + + public static MainData instance = new MainData(); + + public void addPeers(List newPeers){ + this.peers.addAll(newPeers); + + + for (PeerData peerData : this.peers){ + + Location location = IpGeoDB.getLocationForIp(peerData.getInetAddress()); + if (location != null) + System.out.println("Hello: " + " [" + peerData.getInetAddress().toString() + + "] " + location.countryName); + + } + } + + public void addBlocks(List blocks){} + public void addTransactions(List transactions){} + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/MessageDeserializer.java b/ethereumj-core/src/main/java/org/ethereum/net/MessageDeserializer.java new file mode 100644 index 00000000..597f1ebb --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/MessageDeserializer.java @@ -0,0 +1,121 @@ +package org.ethereum.net; + +/** + * www.openchain.info + * User: Roman Mandeleil + * Created on: 04/04/14 00:51 + */ +public class MessageDeserializer { + + + /** + * Get exactly one message payload + */ + public static void deserialize(byte [] msgData, int level, int startPos, int endPos){ + + if (msgData == null || msgData.length == 0) return ; + int pos = startPos; + + while(pos < endPos){ + + // It's a list with a payload more than 55 bytes + // data[0] - 0xF7 = how many next bytes allocated + // for the length of the list + if ((msgData[pos] & 0xFF) >= 0xF7){ + + byte lenghtOfLenght = (byte) (msgData[pos] - 0xF7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += msgData[pos + i] << (8 * pow); + pow--; + } + + // now we can parse an item for data[1]..data[length] + System.out.println("-- level: [" + level + "] Found big list length: " + length); + + deserialize(msgData, level + 1, pos + lenghtOfLenght + 1, pos + lenghtOfLenght + length); + + pos += lenghtOfLenght + length + 1 ; + continue; + } + + + // It's a list with a payload less than 55 bytes + if ((msgData[pos] & 0xFF) >= 0xC0 && (msgData[pos] & 0xFF) < 0xF7){ + + byte length = (byte) (msgData[pos] - 0xC0); + + System.out.println("-- level: [" + level + "] Found small list length: " + length); + + deserialize(msgData, level + 1, pos + 1, pos + length + 1); + + pos += 1 + length; + continue; + } + + + // It's an item with a payload more than 55 bytes + // data[0] - 0xB7 = how much next bytes allocated for + // the length of the string + if ((msgData[pos] & 0xFF) >= 0xB7 && (msgData[pos] & 0xFF) < 0xC0) { + + byte lenghtOfLenght = (byte) (msgData[pos] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += msgData[pos + i] << (8 * pow); + pow--; + } + + + // now we can parse an item for data[1]..data[length] + System.out.println("-- level: [" + level + "] Found big item length: " + length); + pos += lenghtOfLenght + length + 1 ; + + continue; + } + + + // It's an item less than 55 bytes long, + // data[0] - 0x80 == lenght of the item + if ((msgData[pos] & 0xFF) > 0x80 && (msgData[pos] & 0xFF) < 0xB7) { + + byte length = (byte) (msgData[pos] - 0x80); + + System.out.println("-- level: [" + level + "] Found small item length: " + length); + pos += 1 + length; + + continue; + } + + // null item + if ((msgData[pos] & 0xFF) == 0x80){ + System.out.println("-- level: [" + level + "] Found null item: "); + pos += 1; + continue; + } + + // single byte item + if ((msgData[pos] & 0xFF) < 0x80) { + System.out.println("-- level: [" + level + "] Found single item: "); + pos += 1; + continue; + } + + + + } + + + + + } + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/RLP.java b/ethereumj-core/src/main/java/org/ethereum/net/RLP.java new file mode 100644 index 00000000..62c598c2 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/RLP.java @@ -0,0 +1,1102 @@ +package org.ethereum.net; + +import org.bouncycastle.util.encoders.Hex; +import org.ethereum.net.rlp.RLPItem; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.util.Utils; + +import java.io.UnsupportedEncodingException; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.*; + +/** + + */ +public class RLP { + + + public static byte decodeOneByteItem(byte[] data, int index){ + + // null item + if ((data[index] & 0xFF) == 0x80){ + return (byte) (data[index] - 0x80); + } + + // single byte item + if ((data[index] & 0xFF) < 0x80){ + return (byte) (data[index]); + } + + // single byte item + if ((data[index] & 0xFF) == 0x81){ + return (byte) (data[index + 1]); + } + + + return 0; + } + + public static String decodeStringItem(byte[] data, int index){ + + String value = null; + + if ((data[index] & 0xFF) >= 0xB7 && (data[index] & 0xFF) < 0xC0) { + + byte lenghtOfLenght = (byte) (data[index] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += data[index+ i] << (8 * pow); + pow--; + } + + value = new String(data, index + lenghtOfLenght + 1, length); + + }else if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) { + + byte length = (byte) ((data[index] & 0xFF) - 0x80); + + value = new String(data, index + 1, length); + + } else{ + throw new Error("wrong decode attempt"); + } + + return value; + } + + + public static int decodeInt(byte[] data, int index){ + + int value = 0; + + if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) { + + byte length = (byte) (data[index] - 0x80); + byte pow = (byte) (length - 1); + + + for (int i = 1; i <= length; ++i){ + + value += data[index + i] << (8 * pow); + pow--; + } + } else{ + + throw new Error("wrong decode attempt"); + + } + + return value; + } + + public static short decodeShort(byte[] data, int index){ + + short value = 0; + + if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) { + + byte length = (byte) (data[index] - 0x80); + + value = ByteBuffer.wrap(data, index, length).getShort(); + + } else{ + + value = data[index]; + } + + return value; + } + + public static short decodeLong(byte[] data, int index){ + + short value = 0; + + if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) { + + byte length = (byte) (data[index] - 0x80); + byte pow = (byte) (length - 1); + + + for (int i = 1; i <= length; ++i){ + + value += data[index + i] << (8 * pow); + pow--; + } + } else{ + + throw new Error("wrong decode attempt"); + + } + + return value; + } + + + public static byte[] decodeItemBytes(byte[] data, int index){ + + byte[] value = null; + + if ((data[index] & 0xFF) >= 0xB7 && (data[index] & 0xFF) < 0xC0) { + + byte lenghtOfLenght = (byte) (data[index] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += data[index+ i] << (8 * pow); + pow--; + } + + + byte[] valueBytes = new byte[length]; + System.arraycopy(data, index, valueBytes, 0, length); + + value = valueBytes; + + } else if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) { + + byte length = (byte) (data[index] - 0x80); + + byte[] valueBytes = new byte[length]; + System.arraycopy(data, index, valueBytes, 0, length); + + value = valueBytes; + + } else { + + throw new Error("wrong decode attempt"); + + } + + return value; + } + + public static BigInteger decodeBigInteger(byte[] data, int index){ + + BigInteger value = null; + + if ((data[index] & 0xFF) >= 0xB7 && (data[index] & 0xFF) < 0xC0) { + + byte lenghtOfLenght = (byte) (data[index] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += data[index+ i] << (8 * pow); + pow--; + } + + + byte[] valueBytes = new byte[length]; + System.arraycopy(data, index, valueBytes, 0, length); + + value = new BigInteger(valueBytes); + + } else if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) { + + byte length = (byte) (data[index] - 0x80); + + byte[] valueBytes = new byte[length]; + System.arraycopy(data, index, valueBytes, 0, length); + + value = new BigInteger(valueBytes); + + } else { + + throw new Error("wrong decode attempt"); + + } + + return value; + } + + public static byte[] decodeByteArray(byte[] data, int index){ + + byte[] value = null; + + if ((data[index] & 0xFF) >= 0xB7 && (data[index] & 0xFF) < 0xC0) { + + byte lenghtOfLenght = (byte) (data[index] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += data[index+ i] << (8 * pow); + pow--; + } + + + byte[] valueBytes = new byte[length]; + System.arraycopy(data, index, valueBytes, 0, length); + + value = valueBytes; + + } else if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) { + + byte length = (byte) (data[index] - 0x80); + + byte[] valueBytes = new byte[length]; + System.arraycopy(data, index, valueBytes, 0, length); + + value = valueBytes; + + } else { + + throw new Error("wrong decode attempt"); + + } + + return value; + } + + + public static int nextItemLength(byte[] data, int index){ + + + if (index >= data.length) return -1; + + if ((data[index] & 0xFF) >= 0xF7){ + byte lenghtOfLenght = (byte) (data[index] - 0xF7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += (data[index + i] & 0xFF) << (8 * pow); + pow--; + } + + return length; + + + } + + if ((data[index] & 0xFF) >= 0xC0 && (data[index] & 0xFF) < 0xF7){ + + byte length = (byte) ((data[index] & 0xFF) - 0xC0); + return length; + } + + + if ((data[index] & 0xFF) >= 0xB7 && (data[index] & 0xFF) < 0xC0) { + + byte lenghtOfLenght = (byte) (data[index] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += (data[index + i] & 0xFF) << (8 * pow); + pow--; + } + + return length ; + + + } + + if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) { + + byte length = (byte) ((data[index] & 0xFF) - 0x80); + return length; + } + + + if ((data[index] & 0xFF) == 0x80){ + + return 1; + } + + if ((data[index] & 0xFF) < 0x80) { + + return 1; + } + + return -1; + } + + + public static byte[] decodeIP4Bytes(byte[] data, int index){ + + int length = (data[index] & 0xFF) - 0xC0; + int offset = 1; + + byte aByte = decodeOneByteItem(data, index + offset); + + if ((data[index + offset] & 0xFF) > 0x80) offset = offset + 2; else offset = offset + 1; + byte bByte = decodeOneByteItem(data, index + offset); + + if ((data[index + offset] & 0xFF) > 0x80) offset = offset + 2; else offset = offset + 1; + byte cByte = decodeOneByteItem(data, index + offset); + + if ((data[index + offset] & 0xFF) > 0x80) offset = offset + 2; else offset = offset + 1; + byte dByte = decodeOneByteItem(data, index + offset); + + byte[] ip = new byte[4]; + ip[0] = aByte; + ip[1] = bByte; + ip[2] = cByte; + ip[3] = dByte; + + return ip; + } + + public static int getFirstListElement(byte[] payload, int pos) { + + if (pos >= payload.length) return -1; + + if ((payload[pos] & 0xFF) >= 0xF7){ + + byte lenghtOfLenght = (byte) (payload[pos] - 0xF7); + + return pos + lenghtOfLenght + 1 ; + } + + if ((payload[pos] & 0xFF) >= 0xC0 && (payload[pos] & 0xFF) < 0xF7){ + + byte length = (byte) ((payload[pos] & 0xFF) - 0xC0); + return pos + 1; + } + + + if ((payload[pos] & 0xFF) >= 0xB7 && (payload[pos] & 0xFF) < 0xC0) { + + byte lenghtOfLenght = (byte) (payload[pos] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += (payload[pos + i] & 0xFF) << (8 * pow); + pow--; + } + + return pos + lenghtOfLenght + 1 ; + } + + return -1; + } + + + + + + + public static int getNextElementIndex(byte[] payload, int pos) { + + if (pos >= payload.length) return -1; + + if ((payload[pos] & 0xFF) >= 0xF7){ + byte lenghtOfLenght = (byte) (payload[pos] - 0xF7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += (payload[pos + i] & 0xFF) << (8 * pow); + pow--; + } + + return pos + lenghtOfLenght + length + 1 ; + + + } + + if ((payload[pos] & 0xFF) >= 0xC0 && (payload[pos] & 0xFF) < 0xF7){ + + byte length = (byte) ((payload[pos] & 0xFF) - 0xC0); + return pos + 1 + length; + } + + + if ((payload[pos] & 0xFF) >= 0xB7 && (payload[pos] & 0xFF) < 0xC0) { + + byte lenghtOfLenght = (byte) (payload[pos] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += (payload[pos + i] & 0xFF) << (8 * pow); + pow--; + } + + return pos + lenghtOfLenght + length + 1 ; + } + + if ((payload[pos] & 0xFF) > 0x80 && (payload[pos] & 0xFF) < 0xB7) { + + byte length = (byte) ((payload[pos] & 0xFF) - 0x80); + return pos + 1 + length; + } + + + if ((payload[pos] & 0xFF) == 0x80){ + + return pos + 1; + } + + if ((payload[pos] & 0xFF) < 0x80) { + + return pos + 1; + } + + + + return -1; + } + + + /** + * Get exactly one message payload + */ + public static void fullTraverse(byte [] msgData, int level, int startPos, int endPos, + int levelToIndex, Queue index) { + + try{ + + if (msgData == null || msgData.length == 0) return ; + int pos = startPos; + + while(pos < endPos){ + + if (level == levelToIndex) index.add(new Integer(pos)); + + // It's a list with a payload more than 55 bytes + // data[0] - 0xF7 = how many next bytes allocated + // for the length of the list + if ((msgData[pos] & 0xFF) >= 0xF7){ + + byte lenghtOfLenght = (byte) (msgData[pos] - 0xF7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += (msgData[pos + i] & 0xFF) << (8 * pow); + pow--; + } + + // now we can parse an item for data[1]..data[length] + System.out.println("-- level: [" + level + "] Found big list length: " + length); + + fullTraverse(msgData, level + 1, pos + lenghtOfLenght + 1, pos + lenghtOfLenght + length, + levelToIndex, index); + + pos += lenghtOfLenght + length + 1 ; + continue; + } + + + // It's a list with a payload less than 55 bytes + if ((msgData[pos] & 0xFF) >= 0xC0 && (msgData[pos] & 0xFF) < 0xF7){ + + byte length = (byte) ((msgData[pos] & 0xFF) - 0xC0); + + System.out.println("-- level: [" + level + "] Found small list length: " + length); + + fullTraverse(msgData, level + 1, pos + 1, pos + length + 1, levelToIndex, index); + + pos += 1 + length; + continue; + } + + + // It's an item with a payload more than 55 bytes + // data[0] - 0xB7 = how much next bytes allocated for + // the length of the string + if ((msgData[pos] & 0xFF) >= 0xB7 && (msgData[pos] & 0xFF) < 0xC0) { + + byte lenghtOfLenght = (byte) (msgData[pos] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += (msgData[pos + i] & 0xFF) << (8 * pow); + pow--; + } + + + // now we can parse an item for data[1]..data[length] + System.out.println("-- level: [" + level + "] Found big item length: " + length); + pos += lenghtOfLenght + length + 1 ; + + continue; + } + + + // It's an item less than 55 bytes long, + // data[0] - 0x80 == lenght of the item + if ((msgData[pos] & 0xFF) > 0x80 && (msgData[pos] & 0xFF) < 0xB7) { + + byte length = (byte) ((msgData[pos] & 0xFF) - 0x80); + + System.out.println("-- level: [" + level + "] Found small item length: " + length); + pos += 1 + length; + + continue; + } + + // null item + if ((msgData[pos] & 0xFF) == 0x80){ + System.out.println("-- level: [" + level + "] Found null item: "); + pos += 1; + continue; + } + + // single byte item + if ((msgData[pos] & 0xFF) < 0x80) { + System.out.println("-- level: [" + level + "] Found single item: "); + pos += 1; + continue; + } + } + + + } catch(Throwable th){ + + throw new Error("wire packet not parsed correctly", th.fillInStackTrace()); + + } + + + + } + + + + + + /** + * Parse wire byte[] message into RLP elements + * + * @param msgData - raw RLP data + * @param rlpList - outcome of recursive RLP structure + */ + public static void parseObjects(byte [] msgData, RLPList rlpList){ + + RLP.fullTraverse2(msgData, 0, 0, msgData.length, 1, rlpList); + } + + /** + * Get exactly one message payload + */ + public static void fullTraverse2(byte [] msgData, int level, int startPos, int endPos, + int levelToIndex, RLPList rlpList) { + + try{ + + if (msgData == null || msgData.length == 0) return ; + int pos = startPos; + + while(pos < endPos){ + + // It's a list with a payload more than 55 bytes + // data[0] - 0xF7 = how many next bytes allocated + // for the length of the list + if ((msgData[pos] & 0xFF) >= 0xF7){ + + byte lenghtOfLenght = (byte) (msgData[pos] - 0xF7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += (msgData[pos + i] & 0xFF) << (8 * pow); + pow--; + } + + + byte[] rlpData = new byte[lenghtOfLenght + length + 1]; + System.arraycopy(msgData, pos, rlpData, 0, lenghtOfLenght + length + 1); + + RLPList newLevelList = new RLPList(); + newLevelList.setRLPData(rlpData); + + +// todo: this done to get some data for testing should be delete +// byte[] subList = Arrays.copyOfRange(msgData, pos, pos + lenghtOfLenght + length + 1); +// System.out.println(Utils.toHexString(subList)); + + + fullTraverse2(msgData, level + 1, pos + lenghtOfLenght + 1, pos + lenghtOfLenght + length + 1, + levelToIndex, newLevelList); + rlpList.addItem(newLevelList); + + pos += lenghtOfLenght + length + 1; + continue; + } + + + // It's a list with a payload less than 55 bytes + if ((msgData[pos] & 0xFF) >= 0xC0 && (msgData[pos] & 0xFF) < 0xF7){ + + byte length = (byte) ((msgData[pos] & 0xFF) - 0xC0); + + byte[] rlpData = new byte[length + 1]; + System.arraycopy(msgData, pos, rlpData, 0, length + 1); + + RLPList newLevelList = new RLPList(); + newLevelList.setRLPData(rlpData); + + if (length > 0) + fullTraverse2(msgData, level + 1, pos + 1, pos + length + 1, levelToIndex, newLevelList); + rlpList.addItem(newLevelList); + + pos += 1 + length; + continue; + } + + + // It's an item with a payload more than 55 bytes + // data[0] - 0xB7 = how much next bytes allocated for + // the length of the string + if ((msgData[pos] & 0xFF) >= 0xB7 && (msgData[pos] & 0xFF) < 0xC0) { + + byte lenghtOfLenght = (byte) (msgData[pos] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + int length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += (msgData[pos + i] & 0xFF) << (8 * pow); + pow--; + } + + + // now we can parse an item for data[1]..data[length] + byte[] item = new byte[length]; + System.arraycopy(msgData, pos + lenghtOfLenght + 1, item, 0, length); + + byte[] rlpPrefix = new byte[lenghtOfLenght + 1]; + System.arraycopy(msgData, pos, rlpPrefix, 0, lenghtOfLenght + 1); + + RLPItem rlpItem= new RLPItem(item); + rlpList.addItem(rlpItem); + pos += lenghtOfLenght + length + 1 ; + + + continue; + } + + + // It's an item less than 55 bytes long, + // data[0] - 0x80 == length of the item + if ((msgData[pos] & 0xFF) > 0x80 && (msgData[pos] & 0xFF) < 0xB7) { + + byte length = (byte) ((msgData[pos] & 0xFF) - 0x80); + + + byte[] item = new byte[length]; + System.arraycopy(msgData, pos + 1, item, 0, length); + + byte[] rlpPrefix = new byte[2]; + System.arraycopy(msgData, pos, rlpPrefix, 0, 2); + + RLPItem rlpItem= new RLPItem(item); + rlpList.addItem(rlpItem); + pos += 1 + length; + + continue; + } + + // null item + if ((msgData[pos] & 0xFF) == 0x80){ + + byte[] item = new byte[0]; + RLPItem rlpItem= new RLPItem(item); + rlpList.addItem(rlpItem); + pos += 1; + continue; + } + + // single byte item + if ((msgData[pos] & 0xFF) < 0x80) { + + byte[] item = {(byte)(msgData[pos] & 0xFF)}; + + RLPItem rlpItem= new RLPItem(item); + rlpList.addItem(rlpItem); + pos += 1; + continue; + } + } + + + } catch(Throwable th){ + + throw new Error("wire packet not parsed correctly", th.fillInStackTrace()); + + } + + } + + + +/* + def rlp_encode(input): + if isinstance(input,str): + if len(input) == 1 and chr(input) < 128: return input + else: return encode_length(len(input),128) + input + elif isinstance(input,list): + output = '' + for item in input: output += rlp_encode(item) + return encode_length(len(output),192) + output + +def encode_length(L,offset): + if L < 56: + return chr(L + offset) + elif L < 256**8: + BL = to_binary(L) + return chr(len(BL) + offset + 55) + BL + else: + raise Exception("input too long") + + def to_binary(x): + return '' if x == 0 else to_binary(int(x / 256)) + chr(x % 256) +*/ + + private static void test1(Object... item){ + + } + + private static String rlpEncode(Object item){ + + if (item instanceof String){ + + String str = ((String)item); + int length = str.length(); + if (length == 1 && str.charAt(0) < 128 ) return str; + else return encodeLenght(str.length(), 128) + str; + } else if(item instanceof List) { + + List itemList = (List) item; + StringBuilder output = new StringBuilder(); + + for (Object oneItem : itemList) output.append(rlpEncode(oneItem)); + return encodeLenght(output.toString().length(), 192) + output.toString(); + } + + throw new Error("unsupported type" + item.getClass()); + } + + + + private static String encodeLenght(int L, int offset) { + + if (L < 56) + return "" + (char) (L + offset); + else if + (L < (256 ^ 8)) { + + String BL = toBinary(L); + return "" + (char) (BL.length() + offset + 55) + BL; + } + else + throw new Error("input too long"); + + } + + + public static byte getCommandCode(byte[] data){ + + byte command = 0; + + int index = getFirstListElement(data, 0); + + command = data[index]; + + command = ((int)(command & 0xFF) == 0x80) ? 0 : command; + + + return command; + } + + + public static Object decode(char[] data){ + + if (data == null || data.length == 0) return null; + + + + + + if (data[0] >= 0xF7){ /* It's a list with a payload more than 55 bytes + data[0] - 0xF7 = how many next bytes allocated + for the length of the list */; + + + byte lenghtOfLenght = (byte) (data[0] - 0xF7); + byte pow = (byte) (lenghtOfLenght - 1); + + long length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += data[i] << (8 * pow); + pow--; + } + + System.out.println(length); + + + // now we can parse an item for data[1]..data[length] + } + + if (data[0] >= 0xC0 && data[0] < 0xF7) /* It's a list with a payload less than 55 bytes*/; + + + + if (data[0] >= 0xB7 && data[0] < 0xC0) {/* It's an item with a payload more than 55 bytes + data[0] - 0xB7 = how much next bytes allocated for + the length of the string */; + + byte lenghtOfLenght = (byte) (data[0] - 0xB7); + byte pow = (byte) (lenghtOfLenght - 1); + + long length = 0; + + for (int i = 1; i <= lenghtOfLenght; ++i){ + + length += data[i] << (8 * pow); + pow--; + } + + + // now we can parse an item for data[1]..data[length] + + } + + + if (data[0] >= 0x80 && data[0] < 0xB7) {/* It's an item less than 55 bytes long, + data[0] - 0x80 == lenght of the item */; + + } + + if (data[0] == 0x80) /* null item */; + if (data[0] < 0x80) /* single byte item */; + + + + return null; + } + + + private static String toBinary(int x){ + + if (x == 0) return ""; + else return toBinary(x >> 8) + ((char)(x & 0x00FF)); + + } + + + + public static byte[] encodeByte(byte singleByte){ + + if ((singleByte & 0xFF) == 0){ + + return new byte[]{(byte) 0x80}; + } else if ((singleByte & 0xFF) < 0x7F){ + + return new byte[]{singleByte}; + } else { + + return new byte[]{(byte) 0x81, singleByte}; + } + } + + public static byte[] encodeShort(short singleShort){ + + if (singleShort <= 0xFF) + + return encodeByte((byte)singleShort); + else{ + + return new byte[]{(byte) 0x82, + (byte) (singleShort >> 8 & 0xFF), + (byte) (singleShort >> 0 & 0xFF) + }; + + } + } + + public static byte[] encodeString(String srcString){ + + return encodeElement(srcString.getBytes()); + } + + public static byte[] encodeBigInteger(BigInteger srcBigInteger){ + + return encodeElement(srcBigInteger.toByteArray()); + } + + public static byte[] encodeElement(byte[] srcData){ + + if (srcData.length <= 0x37){ + + // length = 8X + byte length = (byte) (0x80 + srcData.length); + + byte[] data = Arrays.copyOf(srcData, srcData.length + 1); + System.arraycopy(data, 0, data, 1, srcData.length); + data[0] = length; + + return data; + + } else { + + // length of length = BX + // prefix = [BX, [length]] + int tmpLenght = srcData.length; + byte byteNum = 0; + while (tmpLenght != 0){ + + ++byteNum; + tmpLenght = tmpLenght >> 8; + } + + byte[] lenBytes = new byte[byteNum]; + for (int i = 0; i < byteNum; ++i){ + lenBytes[0] = (byte)((srcData.length >> (8 * i)) & 0xFF); + } + + // first byte = F7 + bytes.length + byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); + System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); + data[0] = (byte)(0xB7 + byteNum); + System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); + + return data; + } + + } + + + public static byte[] encodeList(byte[]... elements){ + + int totalLength = 0; + for (int i = 0; i < elements.length; ++i){ + + totalLength += elements[i].length; + } + + byte[] data; + int copyPos = 0; + if (totalLength <= 0x37){ + + data = new byte[1 + totalLength]; + data[0] = (byte)(0xC0 + totalLength); + copyPos = 1; + + } else { + + // length of length = BX + // prefix = [BX, [length]] + int tmpLenght = totalLength; + byte byteNum = 0; + while (tmpLenght != 0){ + + ++byteNum; + tmpLenght = tmpLenght >> 8; + } + + tmpLenght = totalLength; + byte[] lenBytes = new byte[byteNum]; + for (int i = 0; i < byteNum; ++i){ + lenBytes[i] = (byte)((tmpLenght >> (8 * i)) & 0xFF); + } + + // first byte = F7 + bytes.length + data = new byte[1 + lenBytes.length + totalLength]; + data[0] = (byte)(0xF7 + byteNum); + System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); + + copyPos = lenBytes.length + 1; + } + + + for (int i = 0; i < elements.length; ++i){ + + System.arraycopy(elements[i], 0, data, copyPos, elements[i].length); + copyPos += elements[i].length; + } + + return data; + } + + + + + + public static void main(String args[]){ + + char[] data = { 0xF9, 20, 100 }; + + decode(data); + + + + + } + + + public static void main2(String args[]) throws UnsupportedEncodingException { + + + List moreInnerList = new ArrayList(); + moreInnerList.add("aa"); + + List innerList = new ArrayList(); + innerList.add(moreInnerList); + + List list = new ArrayList (); + list.add("dogy"); +// list.add("dogy"); +// list.add("dogy"); +// list.add(innerList); + list.add("cat"); + + String result = rlpEncode( list ); + + byte[] bytes = result.getBytes(); + + for (char oneChar : result.toCharArray()){ + + byte oneByte = (byte) oneChar; + + System.out.print(Integer.toHexString ((int) oneByte & 0x00FF) + " "); + } + System.out.println(); + + System.out.println(result); + + +// System.out.println('\u0080'); +// System.out.println(toBinary(252)); + } + + + + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/client/ClientPeer.java b/ethereumj-core/src/main/java/org/ethereum/net/client/ClientPeer.java new file mode 100644 index 00000000..65d50d6b --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/ClientPeer.java @@ -0,0 +1,76 @@ +package org.ethereum.net.client; + +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 io.netty.handler.timeout.ReadTimeoutHandler; +import org.ethereum.gui.PeerListener; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 10/04/14 12:28 + */ +public class ClientPeer { + + PeerListener peerListener; + + public ClientPeer() { + } + + public ClientPeer(PeerListener peerListener) { + this.peerListener = peerListener; + } + + public void connect(String host, int port){ + + EventLoopGroup workerGroup = new NioEventLoopGroup(); + + try { + + Bootstrap b = new Bootstrap(); + b.group(workerGroup); + b.channel(NioSocketChannel.class); + + b.option(ChannelOption.SO_KEEPALIVE, true); + + final EthereumProtocolHandler handler; + if (peerListener != null){ + handler = new EthereumProtocolHandler(peerListener); + peerListener.console("connecting to: " + host + ":" + port); + } + else + handler = new EthereumProtocolHandler(); + + b.handler(new ChannelInitializer() { + @Override + public void initChannel(NioSocketChannel ch) throws Exception { + + ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(15)); + ch.pipeline().addLast(new EthereumFrameDecoder()); + ch.pipeline().addLast(handler); + } + }); + + // Start the client. + ChannelFuture f = b.connect(host, port).sync(); // (5) + + // Wait until the connection is closed. + f.channel().closeFuture().sync(); + + + } catch (InterruptedException ie){ + + System.out.println("-- ClientPeer: catch (InterruptedException ie) --"); + ie.printStackTrace(); + } finally { + workerGroup.shutdownGracefully(); + } + + + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumFrameDecoder.java b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumFrameDecoder.java new file mode 100644 index 00000000..fafbb959 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumFrameDecoder.java @@ -0,0 +1,55 @@ +package org.ethereum.net.client; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelOutboundBuffer; +import io.netty.handler.codec.ByteToMessageDecoder; +import io.netty.handler.codec.ReplayingDecoder; + +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.List; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 13/04/14 21:51 + */ +public class EthereumFrameDecoder extends ByteToMessageDecoder { + + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { + + // No header for Eth. message + if (in.readableBytes() < 8) return; + + long magicBytes = in.readUnsignedInt(); + long msgSize = in.readUnsignedInt(); + + if (!((magicBytes >> 24 & 0xFF) == 0x22 && + (magicBytes >> 16 & 0xFF) == 0x40 && + (magicBytes >> 8 & 0xFF) == 0x08 && + (magicBytes & 0xFF) == 0x91 )){ + + System.out.println("Not ethereum packet"); + ctx.close(); + } + + + // Don't have the full packet yet + if (msgSize > in.readableBytes()) { + + in.resetReaderIndex(); + return; + } + + byte[] decoded = new byte[(int)msgSize]; + in.readBytes(decoded); + + out.add(decoded); + + // Chop the achieved data. + in.markReaderIndex(); + } +} 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 new file mode 100644 index 00000000..23c08940 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java @@ -0,0 +1,413 @@ +package org.ethereum.net.client; + + +import io.netty.buffer.ByteBuf; +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.ethereum.gui.PeerListener; +import org.ethereum.manager.MainData; +import org.ethereum.net.RLP; +import org.ethereum.net.message.*; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.net.vo.BlockData; +import org.ethereum.util.Utils; + +import java.util.*; + + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 10/04/14 08:19 + */ +public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { + + final Timer timer = new Timer(); + private final static byte[] MAGIC_PREFIX = {(byte)0x22, (byte)0x40, (byte)0x08, (byte)0x91}; + + private final static byte[] HELLO_MESSAGE = StaticMessages.HELLO_MESSAGE.getPayload(); + private final static byte[] HELLO_MESSAGE_LEN = calcPacketLength(HELLO_MESSAGE); + + private long lastPongTime = 0; + private boolean tearDown = false; + + + // hello data + private boolean handShaked = false; + private byte protocolVersion; + private byte networkId; + + private String clientId; + private byte capabilities; + private short peerPort; + private byte[] peerId; + + PeerListener peerListener; + + public EthereumProtocolHandler() { } + + public EthereumProtocolHandler(PeerListener peerListener) { + this.peerListener = peerListener; + } + + @Override + public void channelActive(final ChannelHandlerContext ctx) { + + // TODO: send hello + // TODO: send ping schedule another ping + + // TODO: ByteBuf vs Stream vs new byte ??? + + + final ByteBuf buffer = ctx.alloc().buffer(HELLO_MESSAGE.length + 8); + + buffer.writeBytes(MAGIC_PREFIX); + buffer.writeBytes(HELLO_MESSAGE_LEN); + buffer.writeBytes(HELLO_MESSAGE); + ctx.writeAndFlush(buffer); + + + // sample for pinging in background + timer.scheduleAtFixedRate(new TimerTask() { + + public void run() { + + if (lastPongTime == 0) lastPongTime = System.currentTimeMillis(); + if (tearDown) this.cancel(); + + long currTime = System.currentTimeMillis(); + if (currTime - lastPongTime > 30000){ + + System.out.println("No ping answer for [30 sec]"); + throw new Error("No ping return for 30 [sec]"); + + + // TODO: shutdown the handler + } + + System.out.println("[Send: PING]"); + if (peerListener != null) peerListener.console("[Send: PING]"); + + sendPing(ctx); + } + }, 2000, 5000); + + timer.scheduleAtFixedRate(new TimerTask() { + + public void run() { + + System.out.println("[Send: GET_PEERS]"); + sendGetPeers(ctx); + } + }, 2000, 60000); + + timer.scheduleAtFixedRate(new TimerTask() { + + public void run() { + + System.out.println("[Send: GET_TRANSACTIONS]"); + sendGetTransactions(ctx); + } + }, 2000, 30000); + + timer.schedule(new TimerTask() { + + public void run() { + + System.out.println("[Send: GET_CHAIN]"); + sendGetChain(ctx); + } + }, 10000); + +/* + timer.schedule(new TimerTask() { + + public void run() { + + System.out.println("[Send: TX]"); + sendTx(ctx); + } + }, 10000); +*/ + + } + + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + + + byte[] payload = (byte[]) msg; + + System.out.print("msg: "); + Utils.printHexStringForByteArray(payload); + + byte command = RLP.getCommandCode(payload); + + // got HELLO + if ((int) (command & 0xFF) == 0x00) { + + System.out.println("[Recv: HELLO]" ); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + HelloMessage helloMessage = new HelloMessage(rlpList); + this.protocolVersion = helloMessage.getProtocolVersion(); + this.networkId = helloMessage.getNetworkId(); + this.clientId = helloMessage.getClientId(); + this.capabilities = helloMessage.getCapabilities(); + this.peerPort = helloMessage.getPeerPort(); + this.peerId = helloMessage.getPeerId(); + + System.out.println(helloMessage.toString()); + if (peerListener != null) peerListener.console(helloMessage.toString()); + + } + + + // got DISCONNECT + if ((int) (command & 0xFF) == 0x01) { + + System.out.println("[Recv: DISCONNECT]"); + if (peerListener != null) peerListener.console("[Recv: DISCONNECT]"); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + DisconnectMessage disconnectMessage = new DisconnectMessage(rlpList); + + System.out.println(disconnectMessage); + if (peerListener != null) peerListener.console(disconnectMessage.toString()); + + } + + // got PING send pong + if ((int) (command & 0xFF) == 0x02) { + + System.out.println("[Recv: PING]"); + if (peerListener != null) peerListener.console("[Recv: PING]"); + + sendPong(ctx); + } + + // got PONG mark it + if ((int) (command & 0xFF) == 0x03) { + + System.out.println("[Recv: PONG]" ); + if (peerListener != null) peerListener.console("[Recv: PONG]"); + + this.lastPongTime = System.currentTimeMillis(); + } + + // got GETPEERS send peers + if ((int) (command & 0xFF) == 0x10) { + + System.out.println("[Recv: GETPEERS]" ); + if (peerListener != null) peerListener.console("[Recv: GETPEERS]"); + + + String answer = "22 40 08 91 00 00 00 50 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[] answerBytes = Utils.hexStringToByteArr(answer); + + ByteBuf buffer = ctx.alloc().buffer(answerBytes.length); + buffer.writeBytes(answerBytes); + ctx.writeAndFlush(buffer); + + // send getpeers + answer = "22 40 08 91 00 00 00 02 C1 10 "; + + answerBytes = Utils.hexStringToByteArr(answer); + + buffer = ctx.alloc().buffer(answerBytes.length); + buffer.writeBytes(answerBytes); + ctx.writeAndFlush(buffer); + } + + // got PEERS + if ((int) (command & 0xFF) == 0x11) { + + System.out.println("[Recv: PEERS]"); + if (peerListener != null) peerListener.console("[Recv: PEERS]"); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + PeersMessage peersMessage = new PeersMessage(rlpList); + + MainData.instance.addPeers(peersMessage.getPeers()); + + System.out.println(peersMessage); + if (peerListener != null) peerListener.console(peersMessage.toString()); + } + + // got TRANSACTIONS + if ((int) (command & 0xFF) == 0x12) { + + System.out.println("Recv: TRANSACTIONS]"); + if (peerListener != null) peerListener.console("Recv: TRANSACTIONS]"); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList); + MainData.instance.addTransactions(transactionsMessage.getTransactions()); + + // todo: if you got transactions send it to your peers + System.out.println(transactionsMessage); + if (peerListener != null) peerListener.console(transactionsMessage.toString()); + + } + + // got BLOCKS + if ((int) (command & 0xFF) == 0x13) { + System.out.println("[Recv: BLOCKS]"); + if (peerListener != null) peerListener.console("[Recv: BLOCKS]"); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + BlocksMessage blocksMessage = new BlocksMessage(rlpList); + List list = blocksMessage.getBlockDataList(); + + MainData.instance.addBlocks(list); + System.out.println(blocksMessage); + if (peerListener != null) peerListener.console(blocksMessage.toString()); + } + + // got GETCHAIN + if ((int) (command & 0xFF) == 0x14) { + System.out.println("[Recv: GET_CHAIN]"); + if (peerListener != null) peerListener.console("[Recv: GET_CHAIN]"); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + GetChainMessage getChainMessage = new GetChainMessage(rlpList); + + System.out.println(getChainMessage); + if (peerListener != null) peerListener.console(getChainMessage.toString()); + } + + // got NOTINCHAIN + if ((int) (command & 0xFF) == 0x15) { + System.out.println("[Recv: NOT_IN_CHAIN]"); + if (peerListener != null) peerListener.console("[Recv: NOT_IN_CHAIN]"); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + NotInChainMessage notInChainMessage = new NotInChainMessage(rlpList); + + System.out.println(notInChainMessage); + if (peerListener != null) peerListener.console(notInChainMessage.toString()); + } + + // got GETTRANSACTIONS + if ((int) (command & 0xFF) == 0x16) { + System.out.println("[Recv: GET_TRANSACTIONS]"); + if (peerListener != null) peerListener.console("[Recv: GET_TRANSACTIONS]"); + + // todo: send the queue of the transactions + + } + + } + + @Override + public void handlerAdded(ChannelHandlerContext ctx) throws Exception { + // limit the size of recieving buffer to 1024 + ctx.channel().config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(32368)); + ctx.channel().config().setOption(ChannelOption.SO_RCVBUF, 32368); + } + + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + + this.tearDown = true; + System.out.println("Lost connection to the server"); + cause.printStackTrace(); + ctx.close().sync(); + timer.cancel(); + } + + private void sendMsg(Message msg, ChannelHandlerContext ctx){ + + byte[] data = msg.getPayload(); + + final ByteBuf buffer = ctx.alloc().buffer(data.length + 8); + byte[] packetLen = calcPacketLength(data); + + buffer.writeBytes(MAGIC_PREFIX); + buffer.writeBytes(packetLen); + ctx.writeAndFlush(buffer); + } + + + private void sendPing(ChannelHandlerContext ctx){ + + ByteBuf buffer = ctx.alloc().buffer(StaticMessages.PING.length); + buffer.writeBytes(StaticMessages.PING); + ctx.writeAndFlush(buffer); + } + + + private void sendPong(ChannelHandlerContext ctx){ + + System.out.println("[Send: PONG]"); + ByteBuf buffer = ctx.alloc().buffer(StaticMessages.PONG.length); + buffer.writeBytes(StaticMessages.PONG); + ctx.writeAndFlush(buffer); + } + + private void sendGetPeers(ChannelHandlerContext ctx){ + + ByteBuf buffer = ctx.alloc().buffer(StaticMessages.GET_PEERS.length); + buffer.writeBytes(StaticMessages.GET_PEERS); + ctx.writeAndFlush(buffer); + } + + private void sendGetTransactions(ChannelHandlerContext ctx){ + + ByteBuf buffer = ctx.alloc().buffer(StaticMessages.GET_TRANSACTIONS.length); + buffer.writeBytes(StaticMessages.GET_TRANSACTIONS); + ctx.writeAndFlush(buffer); + } + + private void sendGetChain(ChannelHandlerContext ctx){ + + ByteBuf buffer = ctx.alloc().buffer(StaticMessages.GET_CHAIN.length); + buffer.writeBytes(StaticMessages.GET_CHAIN); + ctx.writeAndFlush(buffer); + } + + private void sendTx(ChannelHandlerContext ctx){ + + byte[] TX_MSG = + Hex.decode("2240089100000070F86E12F86B80881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA0C52C114D4F5A3BA904A9B3036E5E118FE0DBB987FE3955DA20F2CD8F6C21AB9CA06BA4C2874299A55AD947DBC98A25EE895AABF6B625C26C435E84BFD70EDF2F69"); + + ByteBuf buffer = ctx.alloc().buffer(TX_MSG.length); + buffer.writeBytes(TX_MSG); + ctx.writeAndFlush(buffer); + } + + + private static byte[] calcPacketLength(byte[] msg){ + + int msgLen = msg.length; + + byte[] len = { + (byte)((msgLen >> 24) & 0xFF), + (byte)((msgLen >> 16) & 0xFF), + (byte)((msgLen >> 8) & 0xFF), + (byte)((msgLen ) & 0xFF)}; + + + return len; + } + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/BlocksMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/BlocksMessage.java new file mode 100644 index 00000000..7d4b093c --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/BlocksMessage.java @@ -0,0 +1,79 @@ +package org.ethereum.net.message; + +import org.ethereum.net.RLP; +import org.ethereum.net.rlp.RLPItem; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.net.vo.BlockData; +import org.ethereum.net.vo.TransactionData; + +import java.util.ArrayList; +import java.util.List; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 06/04/14 14:56 + */ +public class BlocksMessage extends Message { + + private final byte commandCode = 0x13; + + private List blockDataList = new ArrayList(); + + + public BlocksMessage(RLPList rawData) { + super(rawData); + } + + + + public void parseRLP() { + + RLPList paramsList = (RLPList) rawData.getElement(0); + + if (((RLPItem)(paramsList).getElement(0)).getData()[0] != commandCode){ + + throw new Error("BlocksMessage: parsing for mal data"); + } + + for (int i = 1; i < paramsList.size(); ++i){ + + RLPList rlpData = ((RLPList)paramsList.getElement(i)); + BlockData blockData = new BlockData(rlpData); + this.blockDataList.add(blockData); + } + + parsed = true; + } + + + @Override + public byte[] getPayload() { + return null; + } + + + public List getBlockDataList() { + if (!parsed) parseRLP(); + return blockDataList; + } + + public String toString(){ + + StringBuffer sb = new StringBuffer(); + for (BlockData blockData : this.getBlockDataList()){ + sb.append(" ").append( blockData.toString() ).append("\n"); + + List transactions = blockData.getTransactionsList(); + for (TransactionData transactionData : transactions){ + + sb.append("[").append(transactionData).append("]\n"); + } + } + + return "Blocks Message [\n" + + sb.toString() + + " ]"; + + } +} \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/DisconnectMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/DisconnectMessage.java new file mode 100644 index 00000000..db187178 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/DisconnectMessage.java @@ -0,0 +1,72 @@ +package org.ethereum.net.message; + +import org.ethereum.net.rlp.RLPItem; +import org.ethereum.net.rlp.RLPList; + + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 06/04/14 14:56 + */ +public class DisconnectMessage extends Message { + + private final byte commandCode = 0x1; + private byte reason; + + public static byte REASON_DISCONNECT_REQUESTED = 0x00; + public static byte REASON_TCP_ERROR = 0x01; + public static byte REASON_BAD_PROTOCOL = 0x02; + public static byte REASON_USELESS_PEER = 0x03; + public static byte REASON_TOO_MANY_PEERS = 0x04; + public static byte REASON_ALREADY_CONNECTED = 0x05; + public static byte REASON_WRONG_GENESIS = 0x06; + public static byte REASON_INCOMPATIBLE_PROTOCOL = 0x07; + public static byte REASON_PEER_QUITING = 0x08; + + + public DisconnectMessage(RLPList rawData) { + super(rawData); + } + + @Override + public void parseRLP() { + + RLPList paramsList = (RLPList) rawData.getElement(0); + + if (((RLPItem)(paramsList).getElement(0)).getData()[0] != commandCode){ + + throw new Error("Disconnect: parsing for mal data"); + } + + byte[] reasonB = ((RLPItem)paramsList.getElement(1)).getData(); + if (reasonB == null){ + + this.reason = 0; + } else { + + this.reason = reasonB[0]; + } + + this.parsed = true; + // todo: what to do when mal data ? + } + + + @Override + public byte[] getPayload() { + return null; + } + + public byte getReason() { + if (!parsed) parseRLP(); + return reason; + } + + public String toString(){ + + if (!parsed) parseRLP(); + return "Disconnect Message [ reason=" + reason + " ]"; + + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/GetChainMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/GetChainMessage.java new file mode 100644 index 00000000..2e877c1f --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/GetChainMessage.java @@ -0,0 +1,85 @@ +package org.ethereum.net.message; + +import org.ethereum.net.RLP; +import org.ethereum.net.rlp.RLPItem; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.util.Utils; + +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 06/04/14 14:56 + */ +public class GetChainMessage extends Message { + + private final byte commandCode = 0x14; + List blockHashList = new ArrayList(); + BigInteger blockNum; + + + public GetChainMessage(RLPList rawData) { + super(rawData); + } + + @Override + public void parseRLP() { + + RLPList paramsList = (RLPList) rawData.getElement(0); + + if (((RLPItem)(paramsList).getElement(0)).getData()[0] != commandCode){ + + throw new Error("GetChain: parsing for mal data"); + } + + + int size = paramsList.size(); + for (int i = 1; i < size - 1; ++i){ + + blockHashList.add(((RLPItem) paramsList.getElement(i)).getData()); + } + + // the last element is the num of requested blocks + byte[] blockNumB = ((RLPItem)paramsList.getElement(size - 1)).getData(); + this.blockNum = new BigInteger(blockNumB); + + this.parsed = true; + // todo: what to do when mal data ? + } + + @Override + public byte[] getPayload() { + return null; + } + + public List getBlockHashList() { + if (!parsed) parseRLP(); + return blockHashList; + } + + public BigInteger getBlockNum() { + if (!parsed) parseRLP(); + return blockNum; + } + + + public String toString(){ + + if (!parsed) parseRLP(); + + StringBuffer sb = new StringBuffer(); + for (byte[] blockHash : blockHashList){ + + sb.append("").append(Utils.toHexString(blockHash)).append(", "); + } + + sb.append(" blockNum=").append(blockNum); + + return "GetChain Message [" + sb.toString() + " ]"; + + } +} 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 new file mode 100644 index 00000000..afb6e7e5 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java @@ -0,0 +1,146 @@ +package org.ethereum.net.message; + +import org.bouncycastle.util.encoders.Hex; +import org.ethereum.net.RLP; +import org.ethereum.net.rlp.RLPItem; +import org.ethereum.net.rlp.RLPList; + +import java.nio.ByteBuffer; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 06/04/14 14:56 + */ +public class HelloMessage extends Message { + + private final byte commandCode = 0x00; + + private byte protocolVersion; + private byte networkId; + private String clientId; + private byte capabilities; + private short peerPort; + private byte[] peerId; + + + public HelloMessage(RLPList rawData) { + + super(rawData); + } + + + public HelloMessage(byte protocolVersion, byte networkId, String clientId, byte capabilities, short peerPort, byte[] peerId) { + this.protocolVersion = protocolVersion; + this.networkId = networkId; + this.clientId = clientId; + this.capabilities = capabilities; + this.peerPort = peerPort; + this.peerId = peerId; + } + + + @Override + public void parseRLP() { + + RLPList paramsList = (RLPList) rawData.getElement(0); + + // the message does no distinguish between the 0 and null so here I check command code for null + // todo: find out if it can be 00 + if (((RLPItem)(paramsList).getElement(0)).getData() != null){ + + throw new Error("HelloMessage: parsing for mal data"); + } + + + this.protocolVersion = ((RLPItem) paramsList.getElement(1)).getData()[0]; + + byte[] networkIdBytes = ((RLPItem) paramsList.getElement(2)).getData(); + this.networkId = networkIdBytes == null ? 0 : networkIdBytes[0] ; + + this.clientId = new String(((RLPItem) paramsList.getElement(3)).getData()); + this.capabilities = ((RLPItem) paramsList.getElement(4)).getData()[0]; + + ByteBuffer bb = ByteBuffer.wrap(((RLPItem) paramsList.getElement(5)).getData()); + this.peerPort = bb.getShort(); + + this.peerId = ((RLPItem) paramsList.getElement(6)).getData(); + + this.parsed = true; + // todo: what to do when mal data ? + } + + + public byte[] getPayload(){ + + byte[] command = RLP.encodeByte(this.commandCode); + byte[] protocolVersion = RLP.encodeByte(this.protocolVersion); + byte[] networkId = RLP.encodeByte(this.networkId); + byte[] clientId = RLP.encodeString(this.clientId); + byte[] capabilities = RLP.encodeByte(this.capabilities); + byte[] peerPort = RLP.encodeShort(this.peerPort); + byte[] peerId = RLP.encodeElement(this.peerId); + + byte[] data = RLP.encodeList(command, protocolVersion, networkId, + clientId, capabilities, peerPort, peerId); + + return data; + } + + + public byte getCommandCode() { + + if (!parsed) parseRLP(); + return commandCode; + } + + public byte getProtocolVersion() { + + if (!parsed) parseRLP(); + return protocolVersion; + } + + public byte getNetworkId() { + + if (!parsed) parseRLP(); + return networkId; + } + + public String getClientId() { + + if (!parsed) parseRLP(); + return clientId; + } + + public byte getCapabilities() { + + if (!parsed) parseRLP(); + return capabilities; + } + + public short getPeerPort() { + + if (!parsed) parseRLP(); + return peerPort; + } + + public byte[] getPeerId() { + + if (!parsed) parseRLP(); + return peerId; + } + + public String toString(){ + + return "Hello Message [ command=" + this.commandCode + " " + + " protocolVersion=" + this.protocolVersion + " " + + " networkId=" + this.networkId + " " + + " clientId= " + this.clientId + " " + + " capabilities= " + this.capabilities + " " + + " peerPort= " + this.peerPort + " " + + " peerId= " + Hex.toHexString(this.peerId) + " " + + "]"; + + } +} + diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java b/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java new file mode 100644 index 00000000..7827c6fb --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java @@ -0,0 +1,27 @@ +package org.ethereum.net.message; + +import org.ethereum.net.rlp.RLPList; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 06/04/14 14:58 + */ +public abstract class Message { + + RLPList rawData; + boolean parsed = false; + + + public Message(){} + + public Message(RLPList rawData) { + this.rawData = rawData; + parsed = false; + } + + public abstract void parseRLP(); + + public abstract byte[] getPayload(); + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/NotInChainMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/NotInChainMessage.java new file mode 100644 index 00000000..cc5fd51e --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/NotInChainMessage.java @@ -0,0 +1,50 @@ +package org.ethereum.net.message; + +import org.ethereum.net.message.Message; +import org.ethereum.net.rlp.RLPItem; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.util.Utils; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 06/04/14 14:56 + */ +public class NotInChainMessage extends Message { + + private final byte commandCode = 0x15; + private byte[] hash; + + + public NotInChainMessage(RLPList rawData) { + super(rawData); + } + + @Override + public void parseRLP() { + RLPList paramsList = (RLPList) rawData.getElement(0); + + if ((((RLPItem)(paramsList).getElement(0)).getData()[0] & 0xFF) != commandCode){ + + throw new Error("NotInChain Message: parsing for mal data"); + } + + hash = ((RLPItem)paramsList.getElement(1)).getData(); + } + + @Override + public byte[] getPayload() { + return null; + } + + public byte[] getHash() { + return hash; + } + + public String toString(){ + + if (!parsed) parseRLP(); + + return "NotInChain Message [" + Utils.toHexString(hash) + "]"; + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/PeersMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/PeersMessage.java new file mode 100644 index 00000000..dc147ee6 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/PeersMessage.java @@ -0,0 +1,120 @@ +package org.ethereum.net.message; + +import org.ethereum.net.RLP; +import org.ethereum.net.message.Message; +import org.ethereum.net.rlp.RLPItem; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.net.vo.PeerData; + +import java.math.BigInteger; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 06/04/14 14:56 + */ +public class PeersMessage extends Message { + + private final byte commandCode = 0x11; + + RLPList rawData; + boolean parsed = false; + + + List peers = new ArrayList(); + + public PeersMessage(){} + + public PeersMessage(RLPList rawData) { + this.rawData = rawData; + parsed = false; + } + + + @Override + public void parseRLP() { + + RLPList paramsList = (RLPList) rawData.getElement(0); + + if ((((RLPItem)(paramsList).getElement(0)).getData()[0] & 0xFF) != commandCode){ + + throw new Error("PeersMessage: parsing for mal data"); + } + + + for (int i = 1; i < paramsList.size(); ++i){ + + RLPList peerParams = (RLPList)paramsList.getElement(i); + + RLPItem ip_a = (RLPItem)((RLPList) peerParams.getElement(0)).getElement(0); + RLPItem ip_b = (RLPItem)((RLPList) peerParams.getElement(0)).getElement(1); + RLPItem ip_c = (RLPItem)((RLPList) peerParams.getElement(0)).getElement(2); + RLPItem ip_d = (RLPItem)((RLPList) peerParams.getElement(0)).getElement(3); + byte ipA = ip_a.getData() == null ? 0 : ip_a.getData()[0]; + byte ipB = ip_b.getData() == null ? 0 : ip_b.getData()[0]; + byte ipC = ip_c.getData() == null ? 0 : ip_c.getData()[0]; + byte ipD = ip_d.getData() == null ? 0 : ip_d.getData()[0]; + + byte[] ip = new byte[]{ipA, ipB, ipC, ipD}; + + byte[] shortData = ((RLPItem) peerParams.getElement(1)).getData(); + + short peerPort = 0; + if (shortData.length == 1) + + peerPort = shortData[0]; + else{ + + ByteBuffer bb = ByteBuffer.wrap(shortData, 0, shortData.length); + peerPort = bb.getShort(); + } + + byte[] peerId = ((RLPItem) peerParams.getElement(2)).getData(); + + PeerData peer = new PeerData(ip, peerPort, peerId); + peers.add(peer); + } + + this.parsed = true; + // todo: what to do when mal data ? + + } + + @Override + public byte[] getPayload() { + return null; + } + + + public List getPeers() { + + if (!parsed){ + parseRLP(); + } + return peers; + } + + public String toString(){ + + if (!parsed){ + parseRLP(); + } + + StringBuffer sb = new StringBuffer(); + + for (PeerData peerData : peers){ + + sb.append("[").append(peerData).append("] \n "); + } + + return "Peers Message [\n " + sb.toString() + "]"; + + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java b/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java new file mode 100644 index 00000000..7b6e69fb --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java @@ -0,0 +1,81 @@ +package org.ethereum.net.message; + +import org.ethereum.util.Utils; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 13/04/14 20:19 + */ +public class StaticMessages { + + public static final byte[] PING = {(byte)0x22, (byte)0x40, (byte)0x08, (byte)0x91, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, + (byte)0xC1, (byte)0x02 }; + + public static final byte[] PONG = {(byte)0x22, (byte)0x40, (byte)0x08, (byte)0x91, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, + (byte)0xC1, (byte)0x03 }; + + public static final byte[] GET_PEERS = {(byte)0x22, (byte)0x40, (byte)0x08, (byte)0x91, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, + (byte)0xC1, (byte)0x10 }; + + public static final byte[] GET_TRANSACTIONS = {(byte)0x22, (byte)0x40, (byte)0x08, (byte)0x91, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, + (byte)0xC1, (byte)0x16 }; + + + public static final byte[] DISCONNECT_00 = {(byte)0x22, (byte)0x40, (byte)0x08, (byte)0x91, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x03, + (byte)0xC2, (byte)0x01, (byte)0x00}; + + public static final byte[] DISCONNECT_01 = {(byte) 0x22, (byte) 0x40, (byte) 0x08, (byte) 0x91, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, + (byte) 0xC2, (byte) 0x01, (byte) 0x01}; + + public static final byte[] DISCONNECT_02 = {(byte) 0x22, (byte) 0x40, (byte) 0x08, (byte) 0x91, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, + (byte) 0xC2, (byte) 0x01, (byte) 0x02}; + + public static final byte[] DISCONNECT_03 = {(byte) 0x22, (byte) 0x40, (byte) 0x08, (byte) 0x91, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, + (byte) 0xC2, (byte) 0x01, (byte) 0x03}; + + public static final byte[] DISCONNECT_08 = {(byte) 0x22, (byte) 0x40, (byte) 0x08, (byte) 0x91, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, + (byte) 0xC2, (byte) 0x01, (byte) 0x08}; + + + public static final byte[] GET_CHAIN = { + + (byte) 0x22, (byte) 0x40, (byte) 0x08, (byte) 0x91, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x27, + (byte) 0xF8, (byte) 0x25, (byte) 0x14, (byte) 0xA0, (byte) 0xAB, (byte) 0x6B, (byte) 0x9A, (byte) 0x56, (byte) 0x13, + (byte) 0x97, (byte) 0x0F, (byte) 0xAA, (byte) 0x77, (byte) 0x1B, (byte) 0x12, (byte) 0xD4, (byte) 0x49, + (byte) 0xB2, (byte) 0xE9, (byte) 0xBB, (byte) 0x92, (byte) 0x5A, (byte) 0xB7, (byte) 0xA3, (byte) 0x69, + (byte) 0xF0, (byte) 0xA4, (byte) 0xB8, (byte) 0x6B, (byte) 0x28, (byte) 0x6E, (byte) 0x9D, (byte) 0x54, + (byte) 0x00, (byte) 0x99, (byte) 0xCF, (byte) 0x82, (byte) 0x01, (byte) 0x00, + }; + + static { + String peerId = "CE 73 F1 F1 F1 F1 6C 1B 3F DA 7B 18 EF 7B A3 CE " + + "17 B6 F1 F1 F1 F1 41 D3 C6 C6 54 B7 AE 88 B2 39 " + + "40 7F F1 F1 F1 F1 19 02 5D 78 57 27 ED 01 7B 6A " + + "DD 21 F1 F1 F1 F1 00 00 01 E3 21 DB C3 18 24 BA "; + + byte[] peerIdBytes = Utils.hexStringToByteArr(peerId); + + + HELLO_MESSAGE = new HelloMessage((byte)0x0C, (byte)0x00, "EthereumJ [v0.0.1] pure java [by Roman Mandeleil]", + (byte)0b00000111, (short)30303, peerIdBytes); + +/* + HELLO_MESSAGE = new HelloMessage((byte)0x0B, (byte)0x00, "EthereumJ [v0.0.1] pure java [by Roman Mandeleil]", + (byte)0b00000111, (short)30303, peerIdBytes); +*/ + + } + + + public static final HelloMessage HELLO_MESSAGE; +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/TransactionsMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/TransactionsMessage.java new file mode 100644 index 00000000..1a77801c --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/TransactionsMessage.java @@ -0,0 +1,73 @@ +package org.ethereum.net.message; + +import org.ethereum.net.rlp.RLPItem; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.net.vo.TransactionData; + +import java.util.ArrayList; +import java.util.List; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 06/04/14 14:56 + */ +public class TransactionsMessage extends Message { + + private final byte commandCode = 0x12; + private List transactions = new ArrayList(); + + public TransactionsMessage() { + } + + public TransactionsMessage(RLPList rawData) { + super(rawData); + } + + @Override + public void parseRLP() { + + RLPList paramsList = (RLPList) rawData.getElement(0); + + if ((((RLPItem)(paramsList).getElement(0)).getData()[0] & 0xFF) != commandCode){ + + throw new Error("TransactionMessage: parsing for mal data"); + } + + transactions = new ArrayList(); + int size = paramsList.getList().size(); + for (int i = 1; i < size; ++i){ + + RLPList rlpTxData = (RLPList) paramsList.getElement(i); + TransactionData tx = new TransactionData(rlpTxData); + transactions.add(tx); + } + + parsed = true; + } + + public List getTransactions() { + + if (!parsed) parseRLP(); + return transactions; + } + + @Override + public byte[] getPayload() { + return null; + } + + public String toString(){ + + if(!parsed)parseRLP(); + + StringBuffer sb = new StringBuffer(); + + for (TransactionData transactionData : transactions){ + + sb.append(" ").append(transactionData).append("\n"); + } + + return "Transactions Message [\n" + sb.toString() + " ]"; + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPElement.java b/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPElement.java new file mode 100644 index 00000000..dfb2ec17 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPElement.java @@ -0,0 +1,10 @@ +package org.ethereum.net.rlp; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 21/04/14 16:28 + */ +public interface RLPElement { + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPItem.java b/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPItem.java new file mode 100644 index 00000000..037a70f9 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPItem.java @@ -0,0 +1,24 @@ +package org.ethereum.net.rlp; + +import org.bouncycastle.util.Arrays; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 21/04/14 16:26 + */ +public class RLPItem implements RLPElement{ + + byte[] data; + + public RLPItem(byte[] data) { + this.data = data; + } + + public byte[] getData() { + + if (data.length == 0) return null; + return data; + } + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPList.java b/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPList.java new file mode 100644 index 00000000..d82ab166 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPList.java @@ -0,0 +1,77 @@ +package org.ethereum.net.rlp; + +import org.bouncycastle.util.Arrays; +import org.bouncycastle.util.encoders.Hex; +import org.ethereum.util.Utils; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 21/04/14 16:26 + */ +public class RLPList implements RLPElement{ + + byte[] rlpData; + List list; + + + public RLPList() { + this.list = new ArrayList(); + } + + public void addItem(RLPElement element){ + + list.add(element); + } + + public RLPElement getElement(int index){ + + return list.get(index); + } + + public int size(){ + return list.size(); + } + + public List getList(){ + return list; + } + + public void setRLPData(byte[] rlpData){ + this.rlpData = rlpData; + } + + + public byte[] getRLPData(){ + + return rlpData; + } + + + public static void recursivePrint(RLPElement element){ + + if (element == null) throw new Error("RLPElement object can't be null"); + if (element instanceof RLPList){ + + RLPList rlpList = (RLPList)element; + System.out.print("["); + for (RLPElement singleElement : rlpList.getList()){ + + recursivePrint(singleElement); + } + System.out.print("]"); + } else { + + String hex = Utils.toHexString(((RLPItem) element).getData()); + + System.out.print(hex + ", "); + + } + + } +} 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 new file mode 100644 index 00000000..22d9f237 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/vo/BlockData.java @@ -0,0 +1,179 @@ +package org.ethereum.net.vo; + +import org.ethereum.net.rlp.RLPElement; +import org.ethereum.net.rlp.RLPItem; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.util.Utils; + +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 13/04/14 19:34 + */ +public class BlockData { + + RLPList rawData; + boolean parsed = false; + + private byte[] hash; + private byte[] parentHash; + private byte[] unclesHash; + private byte[] coinbase; + private byte[] stateHash; + private byte[] txListHash; + private byte[] difficulty; + + private long timestamp; + private byte[] extraData; + private byte[] nonce; + + List transactionsList = new ArrayList(); + List uncleList = new ArrayList(); + + public BlockData(RLPList rawData) { + this.rawData = rawData; + this.parsed = false; + } + + public BlockData(byte[] parentHash, byte[] unclesHash, byte[] coinbase, byte[] stateHash, byte[] txListHash, byte[] difficulty, long timestamp, byte[] extraData, byte[] nonce, List transactionsList, List uncleList) { + this.parentHash = parentHash; + this.unclesHash = unclesHash; + this.coinbase = coinbase; + this.stateHash = stateHash; + this.txListHash = txListHash; + this.difficulty = difficulty; + this.timestamp = timestamp; + this.extraData = extraData; + this.nonce = nonce; + this.transactionsList = transactionsList; + this.uncleList = uncleList; + this.parsed = true; + + } + + + // [parent_hash, uncles_hash, coinbase, state_root, tx_list_hash, difficulty, timestamp, extradata, nonce] + private void parseRLP(){ + + this.hash = Utils.sha3(rawData.getRLPData()); + + List params = ((RLPList) rawData.getElement(0)).getList(); + + this.parentHash = ((RLPItem) params.get(0)).getData(); + this.unclesHash = ((RLPItem) params.get(1)).getData(); + this.coinbase = ((RLPItem) params.get(2)).getData(); + this.stateHash = ((RLPItem) params.get(3)).getData(); + this.txListHash = ((RLPItem) params.get(4)).getData(); + this.difficulty = ((RLPItem) params.get(5)).getData(); + + byte[] tsBytes = ((RLPItem) params.get(6)).getData(); + this.timestamp = (new BigInteger(tsBytes)).longValue(); + this.extraData = ((RLPItem) params.get(7)).getData(); + this.nonce = ((RLPItem) params.get(8)).getData(); + + + // parse transactions + List transactions = ((RLPList) rawData.getElement(1)).getList(); + + for (RLPElement rlpTx : transactions){ + + TransactionData tx = new TransactionData((RLPList)rlpTx); + this.transactionsList.add(tx); + } + + // parse uncles + List uncleBlocks = ((RLPList) rawData.getElement(2)).getList(); + for (RLPElement rawUncle : uncleBlocks){ + + BlockData blockData = new BlockData((RLPList)rawUncle); + this.uncleList.add(blockData); + } + + this.parsed = true; + } + + public byte[] getHash(){ + + if (!parsed) parseRLP(); + return hash; + } + + public byte[] getParentHash() { + if (!parsed) parseRLP(); + return parentHash; + } + + public byte[] getUnclesHash() { + if (!parsed) parseRLP(); + return unclesHash; + } + + public byte[] getCoinbase() { + if (!parsed) parseRLP(); + return coinbase; + } + + public byte[] getStateHash() { + if (!parsed) parseRLP(); + return stateHash; + } + + public byte[] getTxListHash() { + if (!parsed) parseRLP(); + return txListHash; + } + + public byte[] getDifficulty() { + if (!parsed) parseRLP(); + return difficulty; + } + + public long getTimestamp() { + if (!parsed) parseRLP(); + return timestamp; + } + + public byte[] getExtraData() { + if (!parsed) parseRLP(); + return extraData; + } + + public byte[] getNonce() { + if (!parsed) parseRLP(); + return nonce; + } + + public List getTransactionsList() { + if (!parsed) parseRLP(); + return transactionsList; + } + + public List getUncleList() { + if (!parsed) parseRLP(); + return uncleList; + } + + // [parent_hash, uncles_hash, coinbase, state_root, tx_list_hash, difficulty, timestamp, extradata, nonce] + + @Override + public String toString() { + if (!parsed) parseRLP(); + + return "BlockData [" + " hash=" + Utils.toHexString(hash) + + " parentHash=" + Utils.toHexString(parentHash) + + ", unclesHash=" + Utils.toHexString(unclesHash) + + ", coinbase=" + Utils.toHexString(coinbase) + + ", stateHash=" + Utils.toHexString(stateHash) + + ", txListHash=" + Utils.toHexString(txListHash) + + ", difficulty=" + Utils.toHexString(difficulty) + + ", timestamp=" + timestamp + + ", extraData=" + Utils.toHexString(extraData) + + ", nonce=" + Utils.toHexString(nonce) + + ']'; + } +} 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 new file mode 100644 index 00000000..9203f3cd --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/vo/PeerData.java @@ -0,0 +1,97 @@ +package org.ethereum.net.vo; + +import org.bouncycastle.util.encoders.Hex; +import org.ethereum.net.rlp.RLPList; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Arrays; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 13/04/14 17:36 + */ +public class PeerData { + + RLPList rawData; + boolean parsed = false; + + byte[] ip; + short port; + byte[] peerId; + + transient boolean isOnline = false; + transient long lastCheckTime = 0; + + public PeerData(RLPList rlpList){ + rawData = rlpList; + parsed = false; + } + + public PeerData(byte[] ip, short port, byte[] peerId) { + this.ip = ip; + this.port = port; + this.peerId = peerId; + parsed = true; + } + + public InetAddress getInetAddress(){ + + InetAddress addr = null; + + try { + addr = InetAddress.getByAddress(ip); + } catch (UnknownHostException e) { + e.printStackTrace(); + throw new Error("malformed ip"); + } + + return addr; + } + + public byte[] getIp() { + return ip; + } + + public short getPort() { + return port; + } + + public byte[] getPeerId() { + return peerId; + } + + public boolean isOnline() { + return isOnline; + } + + public void setOnline(boolean online) { + isOnline = online; + } + + public long getLastCheckTime() { + return lastCheckTime; + } + + public void setLastCheckTime(long lastCheckTime) { + this.lastCheckTime = lastCheckTime; + } + + + @Override + public String toString() { + return "Peer: [ ip=" + getInetAddress()+ ", port=" + getPort() + ", peerId=" + Hex.toHexString( getPeerId() ) + "]"; + } + + @Override + public boolean equals(Object obj) { + PeerData peerData2 = (PeerData)obj; + return this.getInetAddress().equals(peerData2.getInetAddress()); + } + + @Override + public int hashCode() { + return getInetAddress().hashCode(); + } +} 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 new file mode 100644 index 00000000..7205a485 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/net/vo/TransactionData.java @@ -0,0 +1,187 @@ +package org.ethereum.net.vo; + +import org.ethereum.net.rlp.RLPItem; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.util.Utils; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 21/04/14 09:19 + */ +public class TransactionData { + + RLPList rawData; + boolean parsed = false; + + +// creation contract tx or simple send tx +// [ nonce, value, receiveAddress, gasPrice, gasDeposit, data, signatureV, signatureR, signatureS ] +// or +// [ nonce, endowment, 0, gasPrice, gasDeposit (for init), body, init, signatureV, signatureR, signatureS ] + + byte[] hash; + byte[] nonce; + byte[] value; + + // In creation transaction the receive address is - 0 + byte[] receiveAddress; + byte[] gasPrice; + byte[] gas; + + // Contract creation [data] will hold the contract + // for other transaction [data] can hold data + byte[] data; + byte[] init; + + + // Signature + byte signatureV; + byte[] signatureR; + byte[] signatureS; + + + public TransactionData(RLPList rawData) { + this.rawData = rawData; + parsed = false; + } + + public TransactionData(byte[] nonce, byte[] value, byte[] recieveAddress, byte[] gasPrice, byte[] gas, byte[] data, byte signatureV, byte[] signatureR, byte[] signatureS) { + this.nonce = nonce; + this.value = value; + this.receiveAddress = recieveAddress; + this.gasPrice = gasPrice; + this.gas = gas; + this.data = data; + this.signatureV = signatureV; + this.signatureR = signatureR; + this.signatureS = signatureS; + parsed = true; + } + + + public void rlpParse(){ + + if (rawData.size() == 9){ // Simple transaction + + this.hash = Utils.sha3(rawData.getRLPData()); + this.nonce = ((RLPItem) rawData.getElement(0)).getData(); + this.value = ((RLPItem) rawData.getElement(1)).getData(); + this.receiveAddress = ((RLPItem) rawData.getElement(2)).getData(); + this.gasPrice = ((RLPItem) rawData.getElement(3)).getData(); + this.gas = ((RLPItem) rawData.getElement(4)).getData(); + this.data = ((RLPItem) rawData.getElement(5)).getData(); + this.signatureV = ((RLPItem) rawData.getElement(6)).getData()[0]; + this.signatureR = ((RLPItem) rawData.getElement(7)).getData(); + this.signatureS = ((RLPItem) rawData.getElement(8)).getData(); + + } else if (rawData.size() == 10){ // Contract creation transaction + + this.hash = Utils.sha3(rawData.getRLPData()); + this.nonce = ((RLPItem) rawData.getElement(0)).getData(); + this.value = ((RLPItem) rawData.getElement(1)).getData(); + this.receiveAddress = ((RLPItem) rawData.getElement(2)).getData(); + this.gasPrice = ((RLPItem) rawData.getElement(3)).getData(); + this.gas = ((RLPItem) rawData.getElement(4)).getData(); + this.data = ((RLPItem) rawData.getElement(5)).getData(); + this.init = ((RLPItem) rawData.getElement(6)).getData(); + this.signatureV = ((RLPItem) rawData.getElement(7)).getData()[0]; + this.signatureR = ((RLPItem) rawData.getElement(8)).getData(); + this.signatureS = ((RLPItem) rawData.getElement(9)).getData(); + + } else throw new Error("Wrong tx data element list size"); + + this.parsed = true; + } + + + public RLPList getRawData() { + return rawData; + } + + public boolean isParsed() { + return parsed; + } + + public byte[] getHash() { + if (!parsed) rlpParse(); + return hash; + } + + public byte[] getNonce() { + + if (!parsed) rlpParse(); + return nonce; + } + + public byte[] getValue() { + + if (!parsed) rlpParse(); + return value; + } + + public byte[] getReceiveAddress() { + + if (!parsed) rlpParse(); + return receiveAddress; + } + + public byte[] getGasPrice() { + + if (!parsed) rlpParse(); + return gasPrice; + } + + public byte[] getGas() { + + if (!parsed) rlpParse(); + return gas; + } + + public byte[] getData() { + + if (!parsed) rlpParse(); + return data; + } + + public byte[] getInit() { + + if (!parsed) rlpParse(); + return init; + } + + public byte getSignatureV() { + + if (!parsed) rlpParse(); + return signatureV; + } + + public byte[] getSignatureR() { + + if (!parsed) rlpParse(); + return signatureR; + } + + public byte[] getSignatureS() { + + if (!parsed) rlpParse(); + return signatureS; + } + + @Override + public String toString() { + if (!parsed) rlpParse(); + return "TransactionData [" + " hash=" + Utils.toHexString(hash) + + " nonce=" + Utils.toHexString(nonce) + + ", value=" + Utils.toHexString(value) + + ", receiveAddress=" + Utils.toHexString(receiveAddress) + + ", gasPrice=" + Utils.toHexString(gasPrice) + + ", gas=" + Utils.toHexString(gas) + + ", data=" + Utils.toHexString(data) + + ", init=" + Utils.toHexString(init) + + ", signatureV=" + signatureV + + ", signatureR=" + Utils.toHexString(signatureR) + + ", signatureS=" + Utils.toHexString(signatureS) + + ']'; + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/serpent/GenParser.java b/ethereumj-core/src/main/java/org/ethereum/serpent/GenParser.java new file mode 100644 index 00000000..2900e531 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/serpent/GenParser.java @@ -0,0 +1,19 @@ +package org.ethereum.serpent; + +/** + * 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\\org\\ethereum\\serpent\\Serpent.g"}); +// org.antlr.Tool.main(new String[]{userDir + "\\src\\main\\java\\samples\\antlr\\PyEsque.g"}); + + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/serpent/Serpent.g b/ethereumj-core/src/main/java/org/ethereum/serpent/Serpent.g new file mode 100644 index 00000000..18a9943f --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/serpent/Serpent.g @@ -0,0 +1,248 @@ +/******************************************************************************* + * Ethereum high level language grammar definition + *******************************************************************************/ +grammar Serpent; + +options { + //language = Java; + //output = AST; + output = template; +} + +@header { + + /* (!!!) Do not update this file manually , + * It was auto generated from the Serpent.g + * grammar file. + */ + package org.ethereum.serpent; + import org.ethereum.util.Utils; +} + +@lexer::header { + + /* (!!!) Do not update this file manually , + * It was auto generated from the Serpent.g + * grammar file. + */ + package org.ethereum.serpent; +} + + +@members { + private java.util.ArrayList globals = new java.util.ArrayList(); + private int labelIndex = 0; +} + + + +program + : gen_body + { + String conVars = ""; + + if (globals.size() > 0){ + + conVars = "0 " + (globals.size() * 32 - 1) + " MSTORE8"; + } + } + -> concat(left={conVars}, right={$gen_body.st}) + ; + +test_1 + : + ( + set_var -> concat(left={$test_1.st}, right={$set_var.st}) + | get_var -> concat(left={$test_1.st}, right={$get_var.st}) )* + ; + +/* +test_2 + : + ( + set_var -> concat(left={$test_2.st}, right={$set_var.st}) + )* + + ( + if_stmt -> concat(left={$test_2.st}, right={$if_stmt.st}) + | if_else_stmt -> concat(left={$test_2.st}, right={$if_else_stmt.st}) + ) + ; +*/ + + + +gen_body + : + ( + set_var -> concat(left={$gen_body.st}, right={$set_var.st}) + | storage_save -> concat(left={$gen_body.st}, right={$storage_save.st}) + | return_stmt -> concat(left={$gen_body.st}, right={$return_stmt.st}) + )* ( if_else_stmt -> concat(left={$gen_body.st}, right={$if_else_stmt.st}))? + + ; + + + + +// [if a==10:\n b=20 \n] +// [10, 0, 'MLOAD', 'EQ', 'NOT', 'REF_0', 'JUMPI', 20, 32, 'MSTORE', 'LABEL_0'] +if_stmt + : + 'if' unr_expr ':' gen_body +// (!!!)RECURSION ON if_stmt ( 'elif' cond_expr ':' elif_body=set_var )* + -> ifStmt(cond={$unr_expr.st}, body={$gen_body.st}, index={labelIndex++}) + ; + + +// [if a==10:\n b=20 \nelse: \n b=30] +// [10, 0, 'MLOAD', 'EQ', 'NOT', 'REF_1', 'JUMPI', 20, 32, 'MSTORE', 'REF_0', 'JUMP', 'LABEL_1', 30, 32, 'MSTORE', 'LABEL_0'] +// a 10 EQ NOT REF_01 JUMPI 30 0 MSTORE REF_0 JUMP LABEL_01 20 0 MSTORE LABEL_0 + +if_else_stmt + : + 'if' unr_expr ':' if_body=gen_body +// (!!!)RECURSION ON if_stmt ( 'elif' unr_expr ':' elif_body=set_var )* + 'else' ':' else_body=gen_body -> ifElseStmt(cond={$unr_expr.st}, if_body={$if_body.st}, + else_body={$else_body.st}, if_index={labelIndex++}, else_index={labelIndex++}) ; + + + + +// [multi_set_var] (a=set_var->compile(left={$program.st}, right={$a.st}))* +set_var + : + {int varIndex = -1;} + (a=var { // TODO: change it from atom to something else + + // check if that variable already defined + // if it didn't add it to list + // if it did use the index * 32 for memory address + varIndex = globals.indexOf($a.st.toString()); + if (varIndex == -1 ) {globals.add($a.st.toString()); varIndex = globals.size() - 1; } + } + + '=' b=bin_expr) -> set_var(param_a={$b.st}, param_b={32 * varIndex}) + ; + + get_var + : + {int varIndex = -1;} + (a=var { + + // If there is no such var throw exception + varIndex = globals.indexOf($a.st.toString()); + if (varIndex == -1 ) { + Error err = new Error("var undefined: " + $a.st.toString()); + throw err; + } + ;} + + -> get_var(varIndex={32 * varIndex}) + ) + ; + + +unr_expr + : + {boolean negative = false;} + ('!' {negative = !negative;} )* a=cond_expr -> not(param={negative? $a.st : $a.st + " NOT"}) + + ; + + +cond_expr + : a=bin_expr + ( + '==' b=bin_expr -> equals(left={$a.st},right={$b.st}) | + '<' b=bin_expr -> lessThan(left={$a.st},right={$b.st}) | + '<=' b=bin_expr -> lessEqThan(left={$a.st},right={$b.st}) | + '>=' b=bin_expr -> greatEqThan(left={$a.st},right={$b.st}) | + '>' b=bin_expr -> greatThan(left={$a.st},right={$b.st}) + + | -> {$a.st} + ) + ; + +storage_save + : 'contract.storage['index=bin_expr']' '=' assignment=bin_expr -> ssave(index={$index.st}, data={$assignment.st}) + ; + +bin_expr + : (a=atom -> {$a.st}) + (( '+' b=atom -> add(left={$bin_expr.st}, right={$b.st}) | + '-' b=atom -> sub(left={$bin_expr.st}, right={$b.st}) | + '*' b=atom -> mul(left={$bin_expr.st}, right={$b.st}) | + '/' b=atom -> div(left={$bin_expr.st}, right={$b.st}) | + '^' b=atom -> exp(left={$bin_expr.st}, right={$b.st}) | + '%' b=atom -> mod(left={$bin_expr.st}, right={$b.st}) | + '#/' b=atom -> sdiv(left={$bin_expr.st}, right={$b.st}) | + '#%' b=atom -> smod(left={$bin_expr.st}, right={$b.st}) + )*) + ; + + // "if !a==10:\n b=20 \nelse: \n b=30" + +atom + : + storage_load -> iconst(value={$storage_load.st}) + | msg_sender -> iconst(value={$msg_sender.st}) + | msg_datasize -> iconst(value={$msg_datasize.st}) + | msg_load -> iconst(value={$msg_load.st}) + | get_var -> iconst(value={$get_var.st}) + | INTEGER -> iconst(value={$INTEGER.text}) + | hex_num -> iconst(value={$hex_num.st}) + + ; + +hex_num + : + HEX_NUMBER + { + String dec_num = Utils.hexStringToDecimalString($HEX_NUMBER.text); + } + -> iconst(value={dec_num}) + ; + +var + : IDENT -> refVar(id={$IDENT.text} ) + ; + +storage_load + : 'contract.storage['bin_expr']' -> sload(index={$bin_expr.st}) + ; + +msg_load + : 'msg.data['bin_expr']' -> calldataload(index={$bin_expr.st}) + ; + +msg_sender + : 'msg.sender' -> msdSender() + ; + +msg_datasize + : 'msg.datasize' -> msgDatasize() + ; + +return_stmt + : 'return('bin_expr')' -> returnStmt(index={$bin_expr.st}) + ; + + +fragment LETTER : ('a'..'z' | 'A'..'Z') ; +fragment DIGIT : '0'..'9'; +INTEGER : DIGIT+ ; +IDENT : LETTER (LETTER | DIGIT)*; + +fragment HEX_DIGIT : ('0'..'9' | 'a'..'f' | 'A'..'F'); +HEX_NUMBER : ('0x' | '0X' )HEX_DIGIT+; + +WS : (' ' | '\t' | '\n' | '\r' | '\f')+ {$channel = HIDDEN;}; +COMMENT : '//' .* ('\n'|'\r') {$channel = HIDDEN;}; + + + + + + + diff --git a/ethereumj-core/src/main/java/org/ethereum/serpent/Serpent2Asm.stg b/ethereumj-core/src/main/java/org/ethereum/serpent/Serpent2Asm.stg new file mode 100644 index 00000000..da01f973 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/serpent/Serpent2Asm.stg @@ -0,0 +1,116 @@ +group Serpent2Asm; +/** https://github.com/rollxx/antlr-php-runtime/blob/master/examples/cminus/Bytecode.stg */ + + +// [10, 0, 'MLOAD', 'EQ', 'NOT', 'REF_0', 'JUMPI', 20, 32, 'MSTORE', 'LABEL_0'] +ifStmt(cond, body, index) ::=<< + NOT REF_ JUMPI LABEL_ +>> + +// [10, 0, MLOAD, EQ, NOT, REF_1, JUMPI, 20, 32, MSTORE, REF_0, JUMP, LABEL_1, 30, 32, MSTORE, LABEL_0] +ifElseStmt(cond, if_body, else_body, if_index, else_index) ::=<< + NOT REF_ JUMPI REF_ JUMP LABEL_ LABEL_ +>> + + +set_var(param_a, param_b) ::= << + MSTORE +>> + +get_var(varIndex) ::= << + MLOAD +>> + + +compile(left, right) ::= << + +>> + +add(left,right) ::= << + ADD +>> + +sub(left,right) ::= << + SUB +>> + +mul(left,right) ::= << + MUL +>> + +div(left,right) ::= << + DIV +>> + +exp(left,right) ::= << + EXP +>> + +mod(left,right) ::= << + MOD +>> + +sdiv(left,right) ::= << + SDIV +>> + +smod(left,right) ::= << + SMOD +>> + +equals(left,right) ::= << + EQ +>> + +lessThan(left,right) ::= << + LT +>> + +lessEqThan(left,right) ::= << + GT NOT +>> + +greatThan(left,right) ::= << + GT +>> + +greatEqThan(left,right) ::= << + LT NOT +>> + +not(param) ::= << + NOT +>> + +sload(index) ::= << + SLOAD +>> + +ssave(index, data) ::= << + SSTORE +>> + +calldataload(index) ::=<< + 32 MUL CALLDATALOAD +>> + +msdSender() ::=<< +CALLER +>> + +msgDatasize() ::=<< +32 CALLDATASIZE DIV +>> + +returnStmt(index) ::= << + MSIZE SWAP MSIZE MSTORE 32 SWAP RETURN +>> + + +concat(left, right) ::= << + +>> + + +refVar(id) ::= "" +iconst(value) ::= "" diff --git a/ethereumj-core/src/main/java/org/ethereum/serpent/SerpentCompiler.java b/ethereumj-core/src/main/java/org/ethereum/serpent/SerpentCompiler.java new file mode 100644 index 00000000..f4830de3 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/serpent/SerpentCompiler.java @@ -0,0 +1,43 @@ +package org.ethereum.serpent; + +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 java.io.FileNotFoundException; +import java.io.FileReader; + +/** + * www.ethereumJ.com + * User: Roman Mandeleil + * Created on: 29/04/14 12:34 + */ +public class SerpentCompiler{ + + public static String compile(String code) throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream(code); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.program_return retVal = parser.program(); + + + + return retVal.getTemplate().toString().trim(); + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/serpent/SerpentLexer.java b/ethereumj-core/src/main/java/org/ethereum/serpent/SerpentLexer.java new file mode 100644 index 00000000..3aca9bc7 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/serpent/SerpentLexer.java @@ -0,0 +1,1312 @@ +// $ANTLR 3.5.2 E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g 2014-05-02 09:10:52 + + + /* (!!!) Do not update this file manually , + * It was auto generated from the Serpent.g + * grammar file. + */ + package org.ethereum.serpent; + + +import org.antlr.runtime.*; +import java.util.Stack; +import java.util.List; +import java.util.ArrayList; + +@SuppressWarnings("all") +public class SerpentLexer extends Lexer { + public static final int EOF=-1; + 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 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 COMMENT=4; + public static final int DIGIT=5; + public static final int HEX_DIGIT=6; + public static final int HEX_NUMBER=7; + public static final int IDENT=8; + public static final int INTEGER=9; + public static final int LETTER=10; + public static final int WS=11; + + // delegates + // delegators + public Lexer[] getDelegates() { + return new Lexer[] {}; + } + + public SerpentLexer() {} + public SerpentLexer(CharStream input) { + this(input, new RecognizerSharedState()); + } + public SerpentLexer(CharStream input, RecognizerSharedState state) { + super(input,state); + } + @Override public String getGrammarFileName() { return "E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g"; } + + // $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\\org\\ethereum\\serpent\\Serpent.g:11:7: ( '!' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.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\\org\\ethereum\\serpent\\Serpent.g:12:7: ( '#%' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.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\\org\\ethereum\\serpent\\Serpent.g:13:7: ( '#/' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.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\\org\\ethereum\\serpent\\Serpent.g:14:7: ( '%' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:14: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\\org\\ethereum\\serpent\\Serpent.g:15:7: ( ')' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:15: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\\org\\ethereum\\serpent\\Serpent.g:16:7: ( '*' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:16: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\\org\\ethereum\\serpent\\Serpent.g:17:7: ( '+' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.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\\org\\ethereum\\serpent\\Serpent.g:18:7: ( '-' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:18: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\\org\\ethereum\\serpent\\Serpent.g:19:7: ( '/' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:19: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\\org\\ethereum\\serpent\\Serpent.g:20:7: ( ':' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:20: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\\org\\ethereum\\serpent\\Serpent.g:21:7: ( '<' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:21: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\\org\\ethereum\\serpent\\Serpent.g:22:7: ( '<=' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:22: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\\org\\ethereum\\serpent\\Serpent.g:23:7: ( '=' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:23: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\\org\\ethereum\\serpent\\Serpent.g:24:7: ( '==' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:24: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\\org\\ethereum\\serpent\\Serpent.g:25:7: ( '>' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:25: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\\org\\ethereum\\serpent\\Serpent.g:26:7: ( '>=' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:26: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\\org\\ethereum\\serpent\\Serpent.g:27:7: ( ']' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:27: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\\org\\ethereum\\serpent\\Serpent.g:28:7: ( '^' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:28: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\\org\\ethereum\\serpent\\Serpent.g:29:7: ( 'contract.storage[' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:29:9: 'contract.storage[' + { + match("contract.storage["); + + } + + 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\\org\\ethereum\\serpent\\Serpent.g:30:7: ( 'else' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:30:9: 'else' + { + match("else"); + + } + + 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\\org\\ethereum\\serpent\\Serpent.g:31:7: ( 'if' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:31:9: 'if' + { + match("if"); + + } + + 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\\org\\ethereum\\serpent\\Serpent.g:32:7: ( 'msg.data[' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:32:9: 'msg.data[' + { + match("msg.data["); + + } + + 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\\org\\ethereum\\serpent\\Serpent.g:33:7: ( 'msg.datasize' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:33:9: 'msg.datasize' + { + match("msg.datasize"); + + } + + 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\\org\\ethereum\\serpent\\Serpent.g:34:7: ( 'msg.sender' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:34:9: 'msg.sender' + { + match("msg.sender"); + + } + + 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\\org\\ethereum\\serpent\\Serpent.g:35:7: ( 'return(' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:35:9: 'return(' + { + match("return("); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + // do for sure before leaving + } + } + // $ANTLR end "T__36" + + // $ANTLR start "LETTER" + public final void mLETTER() throws RecognitionException { + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:232:17: ( ( 'a' .. 'z' | 'A' .. 'Z' ) ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.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\\org\\ethereum\\serpent\\Serpent.g:233:16: ( '0' .. '9' ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.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\\org\\ethereum\\serpent\\Serpent.g:234:9: ( ( DIGIT )+ ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:234:11: ( DIGIT )+ + { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:234:11: ( DIGIT )+ + int cnt1=0; + loop1: + while (true) { + int alt1=2; + int LA1_0 = input.LA(1); + if ( ((LA1_0 >= '0' && LA1_0 <= '9')) ) { + alt1=1; + } + + switch (alt1) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.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 ( cnt1 >= 1 ) break loop1; + EarlyExitException eee = new EarlyExitException(1, input); + throw eee; + } + cnt1++; + } + + } + + 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\\org\\ethereum\\serpent\\Serpent.g:235:7: ( LETTER ( LETTER | DIGIT )* ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:235:9: LETTER ( LETTER | DIGIT )* + { + mLETTER(); + + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:235:16: ( LETTER | DIGIT )* + loop2: + while (true) { + int alt2=2; + int LA2_0 = input.LA(1); + if ( ((LA2_0 >= '0' && LA2_0 <= '9')||(LA2_0 >= 'A' && LA2_0 <= 'Z')||(LA2_0 >= 'a' && LA2_0 <= 'z')) ) { + alt2=1; + } + + switch (alt2) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.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 loop2; + } + } + + } + + state.type = _type; + state.channel = _channel; + } + finally { + // do for sure before leaving + } + } + // $ANTLR end "IDENT" + + // $ANTLR start "HEX_DIGIT" + public final void mHEX_DIGIT() throws RecognitionException { + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:237:20: ( ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' ) ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g: + { + if ( (input.LA(1) >= '0' && input.LA(1) <= '9')||(input.LA(1) >= 'A' && input.LA(1) <= 'F')||(input.LA(1) >= 'a' && input.LA(1) <= 'f') ) { + input.consume(); + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse; + } + } + + } + finally { + // do for sure before leaving + } + } + // $ANTLR end "HEX_DIGIT" + + // $ANTLR start "HEX_NUMBER" + public final void mHEX_NUMBER() throws RecognitionException { + try { + int _type = HEX_NUMBER; + int _channel = DEFAULT_TOKEN_CHANNEL; + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:238:12: ( ( '0x' | '0X' ) ( HEX_DIGIT )+ ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:238:14: ( '0x' | '0X' ) ( HEX_DIGIT )+ + { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:238:14: ( '0x' | '0X' ) + int alt3=2; + int LA3_0 = input.LA(1); + if ( (LA3_0=='0') ) { + int LA3_1 = input.LA(2); + if ( (LA3_1=='x') ) { + alt3=1; + } + else if ( (LA3_1=='X') ) { + alt3=2; + } + + else { + int nvaeMark = input.mark(); + try { + input.consume(); + NoViableAltException nvae = + new NoViableAltException("", 3, 1, input); + throw nvae; + } finally { + input.rewind(nvaeMark); + } + } + + } + + else { + NoViableAltException nvae = + new NoViableAltException("", 3, 0, input); + throw nvae; + } + + switch (alt3) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:238:15: '0x' + { + match("0x"); + + } + break; + case 2 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:238:22: '0X' + { + match("0X"); + + } + break; + + } + + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:238:28: ( HEX_DIGIT )+ + int cnt4=0; + loop4: + while (true) { + int alt4=2; + int LA4_0 = input.LA(1); + if ( ((LA4_0 >= '0' && LA4_0 <= '9')||(LA4_0 >= 'A' && LA4_0 <= 'F')||(LA4_0 >= 'a' && LA4_0 <= 'f')) ) { + alt4=1; + } + + switch (alt4) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g: + { + if ( (input.LA(1) >= '0' && input.LA(1) <= '9')||(input.LA(1) >= 'A' && input.LA(1) <= 'F')||(input.LA(1) >= 'a' && input.LA(1) <= 'f') ) { + input.consume(); + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse; + } + } + break; + + default : + if ( cnt4 >= 1 ) break loop4; + EarlyExitException eee = new EarlyExitException(4, input); + throw eee; + } + cnt4++; + } + + } + + state.type = _type; + state.channel = _channel; + } + finally { + // do for sure before leaving + } + } + // $ANTLR end "HEX_NUMBER" + + // $ANTLR start "WS" + public final void mWS() throws RecognitionException { + try { + int _type = WS; + int _channel = DEFAULT_TOKEN_CHANNEL; + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:240:4: ( ( ' ' | '\\t' | '\\n' | '\\r' | '\\f' )+ ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:240:6: ( ' ' | '\\t' | '\\n' | '\\r' | '\\f' )+ + { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:240: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\\org\\ethereum\\serpent\\Serpent.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\\org\\ethereum\\serpent\\Serpent.g:241:9: ( '//' ( . )* ( '\\n' | '\\r' ) ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:241:11: '//' ( . )* ( '\\n' | '\\r' ) + { + match("//"); + + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:241: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\\org\\ethereum\\serpent\\Serpent.g:241: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\\org\\ethereum\\serpent\\Serpent.g:1:8: ( T__12 | 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 | INTEGER | IDENT | HEX_NUMBER | WS | COMMENT ) + int alt7=30; + alt7 = dfa7.predict(input); + switch (alt7) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:10: T__12 + { + mT__12(); + + } + break; + case 2 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:16: T__13 + { + mT__13(); + + } + break; + case 3 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:22: T__14 + { + mT__14(); + + } + break; + case 4 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:28: T__15 + { + mT__15(); + + } + break; + case 5 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:34: T__16 + { + mT__16(); + + } + break; + case 6 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:40: T__17 + { + mT__17(); + + } + break; + case 7 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:46: T__18 + { + mT__18(); + + } + break; + case 8 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:52: T__19 + { + mT__19(); + + } + break; + case 9 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:58: T__20 + { + mT__20(); + + } + break; + case 10 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:64: T__21 + { + mT__21(); + + } + break; + case 11 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:70: T__22 + { + mT__22(); + + } + break; + case 12 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:76: T__23 + { + mT__23(); + + } + break; + case 13 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:82: T__24 + { + mT__24(); + + } + break; + case 14 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:88: T__25 + { + mT__25(); + + } + break; + case 15 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:94: T__26 + { + mT__26(); + + } + break; + case 16 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:100: T__27 + { + mT__27(); + + } + break; + case 17 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:106: T__28 + { + mT__28(); + + } + break; + case 18 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:112: T__29 + { + mT__29(); + + } + break; + case 19 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:118: T__30 + { + mT__30(); + + } + break; + case 20 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:124: T__31 + { + mT__31(); + + } + break; + case 21 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:130: T__32 + { + mT__32(); + + } + break; + case 22 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:136: T__33 + { + mT__33(); + + } + break; + case 23 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:142: T__34 + { + mT__34(); + + } + break; + case 24 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:148: T__35 + { + mT__35(); + + } + break; + case 25 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:154: T__36 + { + mT__36(); + + } + break; + case 26 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:160: INTEGER + { + mINTEGER(); + + } + break; + case 27 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:168: IDENT + { + mIDENT(); + + } + break; + case 28 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:174: HEX_NUMBER + { + mHEX_NUMBER(); + + } + break; + case 29 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:185: WS + { + mWS(); + + } + break; + case 30 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:1:188: COMMENT + { + mCOMMENT(); + + } + break; + + } + } + + + protected DFA7 dfa7 = new DFA7(this); + static final String DFA7_eotS = + "\10\uffff\1\33\1\uffff\1\35\1\37\1\41\2\uffff\5\25\1\26\15\uffff\2\25"+ + "\1\52\2\25\1\uffff\2\25\1\uffff\3\25\1\62\1\uffff\2\25\3\uffff\2\25\1"+ + "\uffff\2\25\2\uffff\1\25\4\uffff"; + static final String DFA7_eofS = + "\101\uffff"; + static final String DFA7_minS = + "\1\11\1\uffff\1\45\5\uffff\1\57\1\uffff\3\75\2\uffff\1\157\1\154\1\146"+ + "\1\163\1\145\1\130\15\uffff\1\156\1\163\1\60\1\147\1\164\1\uffff\1\164"+ + "\1\145\1\uffff\1\56\1\165\1\162\1\60\1\144\1\162\1\141\1\uffff\1\141\1"+ + "\uffff\1\156\1\143\1\164\1\50\1\164\1\141\1\uffff\1\56\1\133\3\uffff"; + static final String DFA7_maxS = + "\1\172\1\uffff\1\57\5\uffff\1\57\1\uffff\3\75\2\uffff\1\157\1\154\1\146"+ + "\1\163\1\145\1\170\15\uffff\1\156\1\163\1\172\1\147\1\164\1\uffff\1\164"+ + "\1\145\1\uffff\1\56\1\165\1\162\1\172\1\163\1\162\1\141\1\uffff\1\141"+ + "\1\uffff\1\156\1\143\1\164\1\50\1\164\1\141\1\uffff\1\56\1\163\3\uffff"; + static final String DFA7_acceptS = + "\1\uffff\1\1\1\uffff\1\4\1\5\1\6\1\7\1\10\1\uffff\1\12\3\uffff\1\21\1"+ + "\22\6\uffff\1\33\1\32\1\35\1\2\1\3\1\36\1\11\1\14\1\13\1\16\1\15\1\20"+ + "\1\17\5\uffff\1\34\2\uffff\1\25\7\uffff\1\24\1\uffff\1\30\6\uffff\1\31"+ + "\2\uffff\1\23\1\26\1\27"; + static final String DFA7_specialS = + "\101\uffff}>"; + static final String[] DFA7_transitionS = { + "\2\27\1\uffff\2\27\22\uffff\1\27\1\1\1\uffff\1\2\1\uffff\1\3\3\uffff"+ + "\1\4\1\5\1\6\1\uffff\1\7\1\uffff\1\10\1\24\11\26\1\11\1\uffff\1\12\1"+ + "\13\1\14\2\uffff\32\25\2\uffff\1\15\1\16\2\uffff\2\25\1\17\1\25\1\20"+ + "\3\25\1\21\3\25\1\22\4\25\1\23\10\25", + "", + "\1\30\11\uffff\1\31", + "", + "", + "", + "", + "", + "\1\32", + "", + "\1\34", + "\1\36", + "\1\40", + "", + "", + "\1\42", + "\1\43", + "\1\44", + "\1\45", + "\1\46", + "\1\47\37\uffff\1\47", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "\1\50", + "\1\51", + "\12\25\7\uffff\32\25\6\uffff\32\25", + "\1\53", + "\1\54", + "", + "\1\55", + "\1\56", + "", + "\1\57", + "\1\60", + "\1\61", + "\12\25\7\uffff\32\25\6\uffff\32\25", + "\1\63\16\uffff\1\64", + "\1\65", + "\1\66", + "", + "\1\67", + "", + "\1\70", + "\1\71", + "\1\72", + "\1\73", + "\1\74", + "\1\75", + "", + "\1\76", + "\1\77\27\uffff\1\100", + "", + "", + "" + }; + + 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", "", "", "", "COMMENT", "DIGIT", "HEX_DIGIT", + "HEX_NUMBER", "IDENT", "INTEGER", "LETTER", "WS", "'!'", "'#%'", "'#/'", + "'%'", "')'", "'*'", "'+'", "'-'", "'/'", "':'", "'<'", "'<='", "'='", + "'=='", "'>'", "'>='", "']'", "'^'", "'contract.storage['", "'else'", + "'if'", "'msg.data['", "'msg.datasize'", "'msg.sender'", "'return('" + }; + public static final int EOF=-1; + 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 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 COMMENT=4; + public static final int DIGIT=5; + public static final int HEX_DIGIT=6; + public static final int HEX_NUMBER=7; + public static final int IDENT=8; + public static final int INTEGER=9; + public static final int LETTER=10; + public static final int WS=11; + + // delegates + public Parser[] getDelegates() { + return new Parser[] {}; + } + + // delegators + + + public SerpentParser(TokenStream input) { + this(input, new RecognizerSharedState()); + } + public SerpentParser(TokenStream input, RecognizerSharedState state) { + super(input, state); + } + + protected StringTemplateGroup templateLib = + new StringTemplateGroup("SerpentParserTemplates", 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 SerpentParser.tokenNames; } + @Override public String getGrammarFileName() { return "E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g"; } + + + private ArrayList globals = new ArrayList(); + private int labelIndex = 0; + + + 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\\org\\ethereum\\serpent\\Serpent.g:39:1: program : gen_body -> concat(left=conVarsright=$gen_body.st); + public final program_return program() throws RecognitionException { + program_return retval = new program_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope gen_body1 =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:40:2: ( gen_body -> concat(left=conVarsright=$gen_body.st)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:40:5: gen_body + { + pushFollow(FOLLOW_gen_body_in_program60); + gen_body1=gen_body(); + state._fsp--; + + + String conVars = ""; + + if (globals.size() > 0){ + + conVars = "0 " + (globals.size() * 32 - 1) + " MSTORE8"; + } + + // TEMPLATE REWRITE + // 49:8: -> concat(left=conVarsright=$gen_body.st) + { + retval.st = templateLib.getInstanceOf("concat",new STAttrMap().put("left", conVars).put("right", (gen_body1!=null?((StringTemplate)gen_body1.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 "program" + + + public static class test_1_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "test_1" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:52:1: test_1 : ( set_var -> concat(left=$test_1.stright=$set_var.st)| get_var -> concat(left=$test_1.stright=$get_var.st))* ; + public final test_1_return test_1() throws RecognitionException { + test_1_return retval = new test_1_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope set_var2 =null; + ParserRuleReturnScope get_var3 =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:53:2: ( ( set_var -> concat(left=$test_1.stright=$set_var.st)| get_var -> concat(left=$test_1.stright=$get_var.st))* ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:54:8: ( set_var -> concat(left=$test_1.stright=$set_var.st)| get_var -> concat(left=$test_1.stright=$get_var.st))* + { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:54:8: ( set_var -> concat(left=$test_1.stright=$set_var.st)| get_var -> concat(left=$test_1.stright=$get_var.st))* + loop1: + while (true) { + int alt1=3; + int LA1_0 = input.LA(1); + if ( (LA1_0==IDENT) ) { + int LA1_2 = input.LA(2); + if ( (LA1_2==24) ) { + alt1=1; + } + else if ( (LA1_2==EOF||LA1_2==IDENT) ) { + alt1=2; + } + + } + + switch (alt1) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:55:11: set_var + { + pushFollow(FOLLOW_set_var_in_test_1120); + set_var2=set_var(); + state._fsp--; + + // TEMPLATE REWRITE + // 55:19: -> concat(left=$test_1.stright=$set_var.st) + { + retval.st = templateLib.getInstanceOf("concat",new STAttrMap().put("left", retval.st).put("right", (set_var2!=null?((StringTemplate)set_var2.getTemplate()):null))); + } + + + + } + break; + case 2 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:56:11: get_var + { + pushFollow(FOLLOW_get_var_in_test_1146); + get_var3=get_var(); + state._fsp--; + + // TEMPLATE REWRITE + // 56:19: -> concat(left=$test_1.stright=$get_var.st) + { + retval.st = templateLib.getInstanceOf("concat",new STAttrMap().put("left", retval.st).put("right", (get_var3!=null?((StringTemplate)get_var3.getTemplate()):null))); + } + + + + } + break; + + default : + break loop1; + } + } + + } + + retval.stop = input.LT(-1); + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + // do for sure before leaving + } + return retval; + } + // $ANTLR end "test_1" + + + public static class gen_body_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "gen_body" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:75:1: gen_body : ( set_var -> concat(left=$gen_body.stright=$set_var.st)| storage_save -> concat(left=$gen_body.stright=$storage_save.st)| return_stmt -> concat(left=$gen_body.stright=$return_stmt.st))* ( if_else_stmt -> concat(left=$gen_body.stright=$if_else_stmt.st))? ; + public final gen_body_return gen_body() throws RecognitionException { + gen_body_return retval = new gen_body_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope set_var4 =null; + ParserRuleReturnScope storage_save5 =null; + ParserRuleReturnScope return_stmt6 =null; + ParserRuleReturnScope if_else_stmt7 =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:76:5: ( ( set_var -> concat(left=$gen_body.stright=$set_var.st)| storage_save -> concat(left=$gen_body.stright=$storage_save.st)| return_stmt -> concat(left=$gen_body.stright=$return_stmt.st))* ( if_else_stmt -> concat(left=$gen_body.stright=$if_else_stmt.st))? ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:77:8: ( set_var -> concat(left=$gen_body.stright=$set_var.st)| storage_save -> concat(left=$gen_body.stright=$storage_save.st)| return_stmt -> concat(left=$gen_body.stright=$return_stmt.st))* ( if_else_stmt -> concat(left=$gen_body.stright=$if_else_stmt.st))? + { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:77:8: ( set_var -> concat(left=$gen_body.stright=$set_var.st)| storage_save -> concat(left=$gen_body.stright=$storage_save.st)| return_stmt -> concat(left=$gen_body.stright=$return_stmt.st))* + loop2: + while (true) { + int alt2=4; + switch ( input.LA(1) ) { + case IDENT: + { + alt2=1; + } + break; + case 30: + { + alt2=2; + } + break; + case 36: + { + alt2=3; + } + break; + } + switch (alt2) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:78:9: set_var + { + pushFollow(FOLLOW_set_var_in_gen_body201); + set_var4=set_var(); + state._fsp--; + + // TEMPLATE REWRITE + // 78:17: -> concat(left=$gen_body.stright=$set_var.st) + { + retval.st = templateLib.getInstanceOf("concat",new STAttrMap().put("left", retval.st).put("right", (set_var4!=null?((StringTemplate)set_var4.getTemplate()):null))); + } + + + + } + break; + case 2 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:79:11: storage_save + { + pushFollow(FOLLOW_storage_save_in_gen_body227); + storage_save5=storage_save(); + state._fsp--; + + // TEMPLATE REWRITE + // 79:24: -> concat(left=$gen_body.stright=$storage_save.st) + { + retval.st = templateLib.getInstanceOf("concat",new STAttrMap().put("left", retval.st).put("right", (storage_save5!=null?((StringTemplate)storage_save5.getTemplate()):null))); + } + + + + } + break; + case 3 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:80:11: return_stmt + { + pushFollow(FOLLOW_return_stmt_in_gen_body253); + return_stmt6=return_stmt(); + state._fsp--; + + // TEMPLATE REWRITE + // 80:23: -> concat(left=$gen_body.stright=$return_stmt.st) + { + retval.st = templateLib.getInstanceOf("concat",new STAttrMap().put("left", retval.st).put("right", (return_stmt6!=null?((StringTemplate)return_stmt6.getTemplate()):null))); + } + + + + } + break; + + default : + break loop2; + } + } + + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:81:11: ( if_else_stmt -> concat(left=$gen_body.stright=$if_else_stmt.st))? + int alt3=2; + int LA3_0 = input.LA(1); + if ( (LA3_0==32) ) { + alt3=1; + } + switch (alt3) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:81:13: if_else_stmt + { + pushFollow(FOLLOW_if_else_stmt_in_gen_body281); + if_else_stmt7=if_else_stmt(); + state._fsp--; + + // TEMPLATE REWRITE + // 81:26: -> concat(left=$gen_body.stright=$if_else_stmt.st) + { + retval.st = templateLib.getInstanceOf("concat",new STAttrMap().put("left", retval.st).put("right", (if_else_stmt7!=null?((StringTemplate)if_else_stmt7.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 "gen_body" + + + public static class if_stmt_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "if_stmt" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:90:1: if_stmt : 'if' unr_expr ':' gen_body -> ifStmt(cond=$unr_expr.stbody=$gen_body.stindex=labelIndex++); + public final if_stmt_return if_stmt() throws RecognitionException { + if_stmt_return retval = new if_stmt_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope unr_expr8 =null; + ParserRuleReturnScope gen_body9 =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:91:5: ( 'if' unr_expr ':' gen_body -> ifStmt(cond=$unr_expr.stbody=$gen_body.stindex=labelIndex++)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:92:9: 'if' unr_expr ':' gen_body + { + match(input,32,FOLLOW_32_in_if_stmt328); + pushFollow(FOLLOW_unr_expr_in_if_stmt330); + unr_expr8=unr_expr(); + state._fsp--; + + match(input,21,FOLLOW_21_in_if_stmt332); + pushFollow(FOLLOW_gen_body_in_if_stmt334); + gen_body9=gen_body(); + state._fsp--; + + // TEMPLATE REWRITE + // 94:65: -> ifStmt(cond=$unr_expr.stbody=$gen_body.stindex=labelIndex++) + { + retval.st = templateLib.getInstanceOf("ifStmt",new STAttrMap().put("cond", (unr_expr8!=null?((StringTemplate)unr_expr8.getTemplate()):null)).put("body", (gen_body9!=null?((StringTemplate)gen_body9.getTemplate()):null)).put("index", labelIndex++)); + } + + + + } + + retval.stop = input.LT(-1); + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + // do for sure before leaving + } + return retval; + } + // $ANTLR end "if_stmt" + + + public static class if_else_stmt_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "if_else_stmt" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:102:1: if_else_stmt : 'if' unr_expr ':' if_body= gen_body 'else' ':' else_body= gen_body -> ifElseStmt(cond=$unr_expr.stif_body=$if_body.stelse_body=$else_body.stif_index=labelIndex++else_index=labelIndex++); + public final if_else_stmt_return if_else_stmt() throws RecognitionException { + if_else_stmt_return retval = new if_else_stmt_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope if_body =null; + ParserRuleReturnScope else_body =null; + ParserRuleReturnScope unr_expr10 =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:103:5: ( 'if' unr_expr ':' if_body= gen_body 'else' ':' else_body= gen_body -> ifElseStmt(cond=$unr_expr.stif_body=$if_body.stelse_body=$else_body.stif_index=labelIndex++else_index=labelIndex++)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:104:9: 'if' unr_expr ':' if_body= gen_body 'else' ':' else_body= gen_body + { + match(input,32,FOLLOW_32_in_if_else_stmt448); + pushFollow(FOLLOW_unr_expr_in_if_else_stmt450); + unr_expr10=unr_expr(); + state._fsp--; + + match(input,21,FOLLOW_21_in_if_else_stmt452); + pushFollow(FOLLOW_gen_body_in_if_else_stmt456); + if_body=gen_body(); + state._fsp--; + + match(input,31,FOLLOW_31_in_if_else_stmt467); + match(input,21,FOLLOW_21_in_if_else_stmt469); + pushFollow(FOLLOW_gen_body_in_if_else_stmt473); + else_body=gen_body(); + state._fsp--; + + // TEMPLATE REWRITE + // 106:42: -> ifElseStmt(cond=$unr_expr.stif_body=$if_body.stelse_body=$else_body.stif_index=labelIndex++else_index=labelIndex++) + { + retval.st = templateLib.getInstanceOf("ifElseStmt",new STAttrMap().put("cond", (unr_expr10!=null?((StringTemplate)unr_expr10.getTemplate()):null)).put("if_body", (if_body!=null?((StringTemplate)if_body.getTemplate()):null)).put("else_body", (else_body!=null?((StringTemplate)else_body.getTemplate()):null)).put("if_index", labelIndex++).put("else_index", labelIndex++)); + } + + + + } + + retval.stop = input.LT(-1); + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + // do for sure before leaving + } + return retval; + } + // $ANTLR end "if_else_stmt" + + + public static class set_var_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "set_var" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:113:1: set_var : (a= var '=' b= bin_expr ) -> set_var(param_a=$b.stparam_b=32 * varIndex); + public final set_var_return set_var() throws RecognitionException { + set_var_return retval = new set_var_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope a =null; + ParserRuleReturnScope b =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:114:5: ( (a= var '=' b= bin_expr ) -> set_var(param_a=$b.stparam_b=32 * varIndex)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:115:9: (a= var '=' b= bin_expr ) + { + int varIndex = -1; + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:116:9: (a= var '=' b= bin_expr ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:116:10: a= var '=' b= bin_expr + { + pushFollow(FOLLOW_var_in_set_var601); + a=var(); + state._fsp--; + + // TODO: change it from atom to something else + + // check if that variable already defined + // if it didn't add it to list + // if it did use the index * 32 for memory address + varIndex = globals.indexOf((a!=null?((StringTemplate)a.getTemplate()):null).toString()); + if (varIndex == -1 ) {globals.add((a!=null?((StringTemplate)a.getTemplate()):null).toString()); varIndex = globals.size() - 1; } + + match(input,24,FOLLOW_24_in_set_var614); + pushFollow(FOLLOW_bin_expr_in_set_var618); + b=bin_expr(); + state._fsp--; + + } + + // TEMPLATE REWRITE + // 125:25: -> set_var(param_a=$b.stparam_b=32 * varIndex) + { + retval.st = templateLib.getInstanceOf("set_var",new STAttrMap().put("param_a", (b!=null?((StringTemplate)b.getTemplate()):null)).put("param_b", 32 * varIndex)); + } + + + + } + + retval.stop = input.LT(-1); + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + // do for sure before leaving + } + return retval; + } + // $ANTLR end "set_var" + + + public static class get_var_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "get_var" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:128:2: get_var : (a= var -> get_var(varIndex=32 * varIndex)) ; + public final get_var_return get_var() throws RecognitionException { + get_var_return retval = new get_var_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope a =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:129:5: ( (a= var -> get_var(varIndex=32 * varIndex)) ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:130:8: (a= var -> get_var(varIndex=32 * varIndex)) + { + int varIndex = -1; + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:131:8: (a= var -> get_var(varIndex=32 * varIndex)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:131:9: a= var + { + pushFollow(FOLLOW_var_in_get_var670); + a=var(); + state._fsp--; + + + + // If there is no such var throw exception + varIndex = globals.indexOf((a!=null?((StringTemplate)a.getTemplate()):null).toString()); + if (varIndex == -1 ) { + Error err = new Error("var undefined: " + (a!=null?((StringTemplate)a.getTemplate()):null).toString()); + throw err; + } + ; + // TEMPLATE REWRITE + // 141:7: -> get_var(varIndex=32 * varIndex) + { + retval.st = templateLib.getInstanceOf("get_var",new STAttrMap().put("varIndex", 32 * varIndex)); + } + + + + } + + } + + retval.stop = input.LT(-1); + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + // do for sure before leaving + } + return retval; + } + // $ANTLR end "get_var" + + + public static class unr_expr_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "unr_expr" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:146:1: unr_expr : ( '!' )* a= cond_expr -> not(param=negative? $a.st : $a.st + \" NOT\"); + public final unr_expr_return unr_expr() throws RecognitionException { + unr_expr_return retval = new unr_expr_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope a =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:147:5: ( ( '!' )* a= cond_expr -> not(param=negative? $a.st : $a.st + \" NOT\")) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:148:9: ( '!' )* a= cond_expr + { + boolean negative = false; + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:149:9: ( '!' )* + loop4: + while (true) { + int alt4=2; + int LA4_0 = input.LA(1); + if ( (LA4_0==12) ) { + alt4=1; + } + + switch (alt4) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:149:10: '!' + { + match(input,12,FOLLOW_12_in_unr_expr732); + negative = !negative; + } + break; + + default : + break loop4; + } + } + + pushFollow(FOLLOW_cond_expr_in_unr_expr742); + a=cond_expr(); + state._fsp--; + + // TEMPLATE REWRITE + // 149:54: -> not(param=negative? $a.st : $a.st + \" NOT\") + { + retval.st = templateLib.getInstanceOf("not",new STAttrMap().put("param", negative? (a!=null?((StringTemplate)a.getTemplate()):null) : (a!=null?((StringTemplate)a.getTemplate()):null) + " NOT")); + } + + + + } + + retval.stop = input.LT(-1); + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + // do for sure before leaving + } + return retval; + } + // $ANTLR end "unr_expr" + + + public static class cond_expr_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "cond_expr" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:154:1: cond_expr : a= bin_expr ( '==' b= bin_expr -> equals(left=$a.stright=$b.st)| '<' b= bin_expr -> lessThan(left=$a.stright=$b.st)| '<=' b= bin_expr -> lessEqThan(left=$a.stright=$b.st)| '>=' b= bin_expr -> greatEqThan(left=$a.stright=$b.st)| '>' b= bin_expr -> greatThan(left=$a.stright=$b.st)| -> {$a.st}) ; + public final cond_expr_return cond_expr() throws RecognitionException { + cond_expr_return retval = new cond_expr_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope a =null; + ParserRuleReturnScope b =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:155:5: (a= bin_expr ( '==' b= bin_expr -> equals(left=$a.stright=$b.st)| '<' b= bin_expr -> lessThan(left=$a.stright=$b.st)| '<=' b= bin_expr -> lessEqThan(left=$a.stright=$b.st)| '>=' b= bin_expr -> greatEqThan(left=$a.stright=$b.st)| '>' b= bin_expr -> greatThan(left=$a.stright=$b.st)| -> {$a.st}) ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:155:9: a= bin_expr ( '==' b= bin_expr -> equals(left=$a.stright=$b.st)| '<' b= bin_expr -> lessThan(left=$a.stright=$b.st)| '<=' b= bin_expr -> lessEqThan(left=$a.stright=$b.st)| '>=' b= bin_expr -> greatEqThan(left=$a.stright=$b.st)| '>' b= bin_expr -> greatThan(left=$a.stright=$b.st)| -> {$a.st}) + { + pushFollow(FOLLOW_bin_expr_in_cond_expr774); + a=bin_expr(); + state._fsp--; + + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:156:9: ( '==' b= bin_expr -> equals(left=$a.stright=$b.st)| '<' b= bin_expr -> lessThan(left=$a.stright=$b.st)| '<=' b= bin_expr -> lessEqThan(left=$a.stright=$b.st)| '>=' b= bin_expr -> greatEqThan(left=$a.stright=$b.st)| '>' b= bin_expr -> greatThan(left=$a.stright=$b.st)| -> {$a.st}) + int alt5=6; + switch ( input.LA(1) ) { + case 25: + { + alt5=1; + } + break; + case 22: + { + alt5=2; + } + break; + case 23: + { + alt5=3; + } + break; + case 27: + { + alt5=4; + } + break; + case 26: + { + alt5=5; + } + break; + case 21: + { + alt5=6; + } + break; + default: + NoViableAltException nvae = + new NoViableAltException("", 5, 0, input); + throw nvae; + } + switch (alt5) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:157:18: '==' b= bin_expr + { + match(input,25,FOLLOW_25_in_cond_expr803); + pushFollow(FOLLOW_bin_expr_in_cond_expr807); + b=bin_expr(); + state._fsp--; + + // TEMPLATE REWRITE + // 157:34: -> 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\\org\\ethereum\\serpent\\Serpent.g:158:18: '<' b= bin_expr + { + match(input,22,FOLLOW_22_in_cond_expr843); + pushFollow(FOLLOW_bin_expr_in_cond_expr848); + b=bin_expr(); + state._fsp--; + + // TEMPLATE REWRITE + // 158:34: -> 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; + case 3 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:159:18: '<=' b= bin_expr + { + match(input,23,FOLLOW_23_in_cond_expr882); + pushFollow(FOLLOW_bin_expr_in_cond_expr887); + b=bin_expr(); + state._fsp--; + + // TEMPLATE REWRITE + // 159:35: -> lessEqThan(left=$a.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("lessEqThan",new STAttrMap().put("left", (a!=null?((StringTemplate)a.getTemplate()):null)).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + case 4 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:160:18: '>=' b= bin_expr + { + match(input,27,FOLLOW_27_in_cond_expr921); + pushFollow(FOLLOW_bin_expr_in_cond_expr926); + b=bin_expr(); + state._fsp--; + + // TEMPLATE REWRITE + // 160:35: -> greatEqThan(left=$a.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("greatEqThan",new STAttrMap().put("left", (a!=null?((StringTemplate)a.getTemplate()):null)).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + case 5 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:161:18: '>' b= bin_expr + { + match(input,26,FOLLOW_26_in_cond_expr960); + pushFollow(FOLLOW_bin_expr_in_cond_expr965); + b=bin_expr(); + state._fsp--; + + // TEMPLATE REWRITE + // 161:34: -> greatThan(left=$a.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("greatThan",new STAttrMap().put("left", (a!=null?((StringTemplate)a.getTemplate()):null)).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + case 6 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:163:13: + { + // TEMPLATE REWRITE + // 163: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 "cond_expr" + + + public static class storage_save_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "storage_save" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:167:1: storage_save : 'contract.storage[' index= bin_expr ']' '=' assignment= bin_expr -> ssave(index=$index.stdata=$assignment.st); + public final storage_save_return storage_save() throws RecognitionException { + storage_save_return retval = new storage_save_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope index =null; + ParserRuleReturnScope assignment =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:168:7: ( 'contract.storage[' index= bin_expr ']' '=' assignment= bin_expr -> ssave(index=$index.stdata=$assignment.st)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:168:9: 'contract.storage[' index= bin_expr ']' '=' assignment= bin_expr + { + match(input,30,FOLLOW_30_in_storage_save1024); + pushFollow(FOLLOW_bin_expr_in_storage_save1027); + index=bin_expr(); + state._fsp--; + + match(input,28,FOLLOW_28_in_storage_save1028); + match(input,24,FOLLOW_24_in_storage_save1030); + pushFollow(FOLLOW_bin_expr_in_storage_save1034); + assignment=bin_expr(); + state._fsp--; + + // TEMPLATE REWRITE + // 168:70: -> ssave(index=$index.stdata=$assignment.st) + { + retval.st = templateLib.getInstanceOf("ssave",new STAttrMap().put("index", (index!=null?((StringTemplate)index.getTemplate()):null)).put("data", (assignment!=null?((StringTemplate)assignment.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 "storage_save" + + + public static class bin_expr_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "bin_expr" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:171:1: bin_expr : (a= atom -> {$a.st}) ( ( '+' b= atom -> add(left=$bin_expr.stright=$b.st)| '-' b= atom -> sub(left=$bin_expr.stright=$b.st)| '*' b= atom -> mul(left=$bin_expr.stright=$b.st)| '/' b= atom -> div(left=$bin_expr.stright=$b.st)| '^' b= atom -> exp(left=$bin_expr.stright=$b.st)| '%' b= atom -> mod(left=$bin_expr.stright=$b.st)| '#/' b= atom -> sdiv(left=$bin_expr.stright=$b.st)| '#%' b= atom -> smod(left=$bin_expr.stright=$b.st))* ) ; + public final bin_expr_return bin_expr() throws RecognitionException { + bin_expr_return retval = new bin_expr_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope a =null; + ParserRuleReturnScope b =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:172:5: ( (a= atom -> {$a.st}) ( ( '+' b= atom -> add(left=$bin_expr.stright=$b.st)| '-' b= atom -> sub(left=$bin_expr.stright=$b.st)| '*' b= atom -> mul(left=$bin_expr.stright=$b.st)| '/' b= atom -> div(left=$bin_expr.stright=$b.st)| '^' b= atom -> exp(left=$bin_expr.stright=$b.st)| '%' b= atom -> mod(left=$bin_expr.stright=$b.st)| '#/' b= atom -> sdiv(left=$bin_expr.stright=$b.st)| '#%' b= atom -> smod(left=$bin_expr.stright=$b.st))* ) ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:172:9: (a= atom -> {$a.st}) ( ( '+' b= atom -> add(left=$bin_expr.stright=$b.st)| '-' b= atom -> sub(left=$bin_expr.stright=$b.st)| '*' b= atom -> mul(left=$bin_expr.stright=$b.st)| '/' b= atom -> div(left=$bin_expr.stright=$b.st)| '^' b= atom -> exp(left=$bin_expr.stright=$b.st)| '%' b= atom -> mod(left=$bin_expr.stright=$b.st)| '#/' b= atom -> sdiv(left=$bin_expr.stright=$b.st)| '#%' b= atom -> smod(left=$bin_expr.stright=$b.st))* ) + { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:172:9: (a= atom -> {$a.st}) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:172:10: a= atom + { + pushFollow(FOLLOW_atom_in_bin_expr1072); + a=atom(); + state._fsp--; + + // TEMPLATE REWRITE + // 172:17: -> {$a.st} + { + retval.st = (a!=null?((StringTemplate)a.getTemplate()):null); + } + + + + } + + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:173:9: ( ( '+' b= atom -> add(left=$bin_expr.stright=$b.st)| '-' b= atom -> sub(left=$bin_expr.stright=$b.st)| '*' b= atom -> mul(left=$bin_expr.stright=$b.st)| '/' b= atom -> div(left=$bin_expr.stright=$b.st)| '^' b= atom -> exp(left=$bin_expr.stright=$b.st)| '%' b= atom -> mod(left=$bin_expr.stright=$b.st)| '#/' b= atom -> sdiv(left=$bin_expr.stright=$b.st)| '#%' b= atom -> smod(left=$bin_expr.stright=$b.st))* ) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:173:10: ( '+' b= atom -> add(left=$bin_expr.stright=$b.st)| '-' b= atom -> sub(left=$bin_expr.stright=$b.st)| '*' b= atom -> mul(left=$bin_expr.stright=$b.st)| '/' b= atom -> div(left=$bin_expr.stright=$b.st)| '^' b= atom -> exp(left=$bin_expr.stright=$b.st)| '%' b= atom -> mod(left=$bin_expr.stright=$b.st)| '#/' b= atom -> sdiv(left=$bin_expr.stright=$b.st)| '#%' b= atom -> smod(left=$bin_expr.stright=$b.st))* + { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:173:10: ( '+' b= atom -> add(left=$bin_expr.stright=$b.st)| '-' b= atom -> sub(left=$bin_expr.stright=$b.st)| '*' b= atom -> mul(left=$bin_expr.stright=$b.st)| '/' b= atom -> div(left=$bin_expr.stright=$b.st)| '^' b= atom -> exp(left=$bin_expr.stright=$b.st)| '%' b= atom -> mod(left=$bin_expr.stright=$b.st)| '#/' b= atom -> sdiv(left=$bin_expr.stright=$b.st)| '#%' b= atom -> smod(left=$bin_expr.stright=$b.st))* + loop6: + while (true) { + int alt6=9; + switch ( input.LA(1) ) { + case 18: + { + alt6=1; + } + break; + case 19: + { + alt6=2; + } + break; + case 17: + { + alt6=3; + } + break; + case 20: + { + alt6=4; + } + break; + case 29: + { + alt6=5; + } + break; + case 15: + { + alt6=6; + } + break; + case 14: + { + alt6=7; + } + break; + case 13: + { + alt6=8; + } + break; + } + switch (alt6) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:173:12: '+' b= atom + { + match(input,18,FOLLOW_18_in_bin_expr1090); + pushFollow(FOLLOW_atom_in_bin_expr1095); + b=atom(); + state._fsp--; + + // TEMPLATE REWRITE + // 173:24: -> add(left=$bin_expr.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("add",new STAttrMap().put("left", retval.st).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + case 2 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:174:12: '-' b= atom + { + match(input,19,FOLLOW_19_in_bin_expr1126); + pushFollow(FOLLOW_atom_in_bin_expr1131); + b=atom(); + state._fsp--; + + // TEMPLATE REWRITE + // 174:24: -> sub(left=$bin_expr.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("sub",new STAttrMap().put("left", retval.st).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + case 3 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:175:12: '*' b= atom + { + match(input,17,FOLLOW_17_in_bin_expr1162); + pushFollow(FOLLOW_atom_in_bin_expr1167); + b=atom(); + state._fsp--; + + // TEMPLATE REWRITE + // 175:24: -> mul(left=$bin_expr.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("mul",new STAttrMap().put("left", retval.st).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + case 4 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:176:12: '/' b= atom + { + match(input,20,FOLLOW_20_in_bin_expr1198); + pushFollow(FOLLOW_atom_in_bin_expr1203); + b=atom(); + state._fsp--; + + // TEMPLATE REWRITE + // 176:24: -> div(left=$bin_expr.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("div",new STAttrMap().put("left", retval.st).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + case 5 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:177:12: '^' b= atom + { + match(input,29,FOLLOW_29_in_bin_expr1234); + pushFollow(FOLLOW_atom_in_bin_expr1239); + b=atom(); + state._fsp--; + + // TEMPLATE REWRITE + // 177:24: -> exp(left=$bin_expr.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("exp",new STAttrMap().put("left", retval.st).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + case 6 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:178:12: '%' b= atom + { + match(input,15,FOLLOW_15_in_bin_expr1270); + pushFollow(FOLLOW_atom_in_bin_expr1275); + b=atom(); + state._fsp--; + + // TEMPLATE REWRITE + // 178:24: -> mod(left=$bin_expr.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("mod",new STAttrMap().put("left", retval.st).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + case 7 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:179:12: '#/' b= atom + { + match(input,14,FOLLOW_14_in_bin_expr1306); + pushFollow(FOLLOW_atom_in_bin_expr1310); + b=atom(); + state._fsp--; + + // TEMPLATE REWRITE + // 179:24: -> sdiv(left=$bin_expr.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("sdiv",new STAttrMap().put("left", retval.st).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + case 8 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:180:12: '#%' b= atom + { + match(input,13,FOLLOW_13_in_bin_expr1340); + pushFollow(FOLLOW_atom_in_bin_expr1344); + b=atom(); + state._fsp--; + + // TEMPLATE REWRITE + // 180:24: -> smod(left=$bin_expr.stright=$b.st) + { + retval.st = templateLib.getInstanceOf("smod",new STAttrMap().put("left", retval.st).put("right", (b!=null?((StringTemplate)b.getTemplate()):null))); + } + + + + } + break; + + default : + break loop6; + } + } + + } + + } + + retval.stop = input.LT(-1); + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + // do for sure before leaving + } + return retval; + } + // $ANTLR end "bin_expr" + + + 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\\org\\ethereum\\serpent\\Serpent.g:186:1: atom : ( storage_load -> iconst(value=$storage_load.st)| msg_sender -> iconst(value=$msg_sender.st)| msg_datasize -> iconst(value=$msg_datasize.st)| msg_load -> iconst(value=$msg_load.st)| get_var -> iconst(value=$get_var.st)| INTEGER -> iconst(value=$INTEGER.text)| hex_num -> iconst(value=$hex_num.st)); + public final atom_return atom() throws RecognitionException { + atom_return retval = new atom_return(); + retval.start = input.LT(1); + + Token INTEGER16=null; + ParserRuleReturnScope storage_load11 =null; + ParserRuleReturnScope msg_sender12 =null; + ParserRuleReturnScope msg_datasize13 =null; + ParserRuleReturnScope msg_load14 =null; + ParserRuleReturnScope get_var15 =null; + ParserRuleReturnScope hex_num17 =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:187:5: ( storage_load -> iconst(value=$storage_load.st)| msg_sender -> iconst(value=$msg_sender.st)| msg_datasize -> iconst(value=$msg_datasize.st)| msg_load -> iconst(value=$msg_load.st)| get_var -> iconst(value=$get_var.st)| INTEGER -> iconst(value=$INTEGER.text)| hex_num -> iconst(value=$hex_num.st)) + int alt7=7; + switch ( input.LA(1) ) { + case 30: + { + alt7=1; + } + break; + case 35: + { + alt7=2; + } + break; + case 34: + { + alt7=3; + } + break; + case 33: + { + alt7=4; + } + break; + case IDENT: + { + alt7=5; + } + break; + case INTEGER: + { + alt7=6; + } + break; + case HEX_NUMBER: + { + alt7=7; + } + break; + default: + NoViableAltException nvae = + new NoViableAltException("", 7, 0, input); + throw nvae; + } + switch (alt7) { + case 1 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:188:7: storage_load + { + pushFollow(FOLLOW_storage_load_in_atom1414); + storage_load11=storage_load(); + state._fsp--; + + // TEMPLATE REWRITE + // 188:20: -> iconst(value=$storage_load.st) + { + retval.st = templateLib.getInstanceOf("iconst",new STAttrMap().put("value", (storage_load11!=null?((StringTemplate)storage_load11.getTemplate()):null))); + } + + + + } + break; + case 2 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:189:9: msg_sender + { + pushFollow(FOLLOW_msg_sender_in_atom1433); + msg_sender12=msg_sender(); + state._fsp--; + + // TEMPLATE REWRITE + // 189:20: -> iconst(value=$msg_sender.st) + { + retval.st = templateLib.getInstanceOf("iconst",new STAttrMap().put("value", (msg_sender12!=null?((StringTemplate)msg_sender12.getTemplate()):null))); + } + + + + } + break; + case 3 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:190:9: msg_datasize + { + pushFollow(FOLLOW_msg_datasize_in_atom1452); + msg_datasize13=msg_datasize(); + state._fsp--; + + // TEMPLATE REWRITE + // 190:22: -> iconst(value=$msg_datasize.st) + { + retval.st = templateLib.getInstanceOf("iconst",new STAttrMap().put("value", (msg_datasize13!=null?((StringTemplate)msg_datasize13.getTemplate()):null))); + } + + + + } + break; + case 4 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:191:9: msg_load + { + pushFollow(FOLLOW_msg_load_in_atom1471); + msg_load14=msg_load(); + state._fsp--; + + // TEMPLATE REWRITE + // 191:18: -> iconst(value=$msg_load.st) + { + retval.st = templateLib.getInstanceOf("iconst",new STAttrMap().put("value", (msg_load14!=null?((StringTemplate)msg_load14.getTemplate()):null))); + } + + + + } + break; + case 5 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:192:9: get_var + { + pushFollow(FOLLOW_get_var_in_atom1490); + get_var15=get_var(); + state._fsp--; + + // TEMPLATE REWRITE + // 192:18: -> iconst(value=$get_var.st) + { + retval.st = templateLib.getInstanceOf("iconst",new STAttrMap().put("value", (get_var15!=null?((StringTemplate)get_var15.getTemplate()):null))); + } + + + + } + break; + case 6 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:193:9: INTEGER + { + INTEGER16=(Token)match(input,INTEGER,FOLLOW_INTEGER_in_atom1510); + // TEMPLATE REWRITE + // 193:17: -> iconst(value=$INTEGER.text) + { + retval.st = templateLib.getInstanceOf("iconst",new STAttrMap().put("value", (INTEGER16!=null?INTEGER16.getText():null))); + } + + + + } + break; + case 7 : + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:194:9: hex_num + { + pushFollow(FOLLOW_hex_num_in_atom1529); + hex_num17=hex_num(); + state._fsp--; + + // TEMPLATE REWRITE + // 194:17: -> iconst(value=$hex_num.st) + { + retval.st = templateLib.getInstanceOf("iconst",new STAttrMap().put("value", (hex_num17!=null?((StringTemplate)hex_num17.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" + + + public static class hex_num_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "hex_num" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:198:1: hex_num : HEX_NUMBER -> iconst(value=dec_num); + public final hex_num_return hex_num() throws RecognitionException { + hex_num_return retval = new hex_num_return(); + retval.start = input.LT(1); + + Token HEX_NUMBER18=null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:199:4: ( HEX_NUMBER -> iconst(value=dec_num)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:200:10: HEX_NUMBER + { + HEX_NUMBER18=(Token)match(input,HEX_NUMBER,FOLLOW_HEX_NUMBER_in_hex_num1564); + + String dec_num = Utils.hexStringToDecimalString((HEX_NUMBER18!=null?HEX_NUMBER18.getText():null)); + + // TEMPLATE REWRITE + // 204:10: -> iconst(value=dec_num) + { + retval.st = templateLib.getInstanceOf("iconst",new STAttrMap().put("value", dec_num)); + } + + + + } + + retval.stop = input.LT(-1); + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + // do for sure before leaving + } + return retval; + } + // $ANTLR end "hex_num" + + + public static class var_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "var" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:207:1: var : IDENT -> refVar(id=$IDENT.text); + public final var_return var() throws RecognitionException { + var_return retval = new var_return(); + retval.start = input.LT(1); + + Token IDENT19=null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:208:5: ( IDENT -> refVar(id=$IDENT.text)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:208:7: IDENT + { + IDENT19=(Token)match(input,IDENT,FOLLOW_IDENT_in_var1609); + // TEMPLATE REWRITE + // 208:13: -> refVar(id=$IDENT.text) + { + retval.st = templateLib.getInstanceOf("refVar",new STAttrMap().put("id", (IDENT19!=null?IDENT19.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 "var" + + + public static class storage_load_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "storage_load" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:211:1: storage_load : 'contract.storage[' bin_expr ']' -> sload(index=$bin_expr.st); + public final storage_load_return storage_load() throws RecognitionException { + storage_load_return retval = new storage_load_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope bin_expr20 =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:212:7: ( 'contract.storage[' bin_expr ']' -> sload(index=$bin_expr.st)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:212:9: 'contract.storage[' bin_expr ']' + { + match(input,30,FOLLOW_30_in_storage_load1638); + pushFollow(FOLLOW_bin_expr_in_storage_load1639); + bin_expr20=bin_expr(); + state._fsp--; + + match(input,28,FOLLOW_28_in_storage_load1640); + // TEMPLATE REWRITE + // 212:40: -> sload(index=$bin_expr.st) + { + retval.st = templateLib.getInstanceOf("sload",new STAttrMap().put("index", (bin_expr20!=null?((StringTemplate)bin_expr20.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 "storage_load" + + + public static class msg_load_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "msg_load" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:215:1: msg_load : 'msg.data[' bin_expr ']' -> calldataload(index=$bin_expr.st); + public final msg_load_return msg_load() throws RecognitionException { + msg_load_return retval = new msg_load_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope bin_expr21 =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:216:7: ( 'msg.data[' bin_expr ']' -> calldataload(index=$bin_expr.st)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:216:9: 'msg.data[' bin_expr ']' + { + match(input,33,FOLLOW_33_in_msg_load1670); + pushFollow(FOLLOW_bin_expr_in_msg_load1671); + bin_expr21=bin_expr(); + state._fsp--; + + match(input,28,FOLLOW_28_in_msg_load1672); + // TEMPLATE REWRITE + // 216:33: -> calldataload(index=$bin_expr.st) + { + retval.st = templateLib.getInstanceOf("calldataload",new STAttrMap().put("index", (bin_expr21!=null?((StringTemplate)bin_expr21.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 "msg_load" + + + public static class msg_sender_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "msg_sender" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:219:1: msg_sender : 'msg.sender' -> msdSender(; + public final msg_sender_return msg_sender() throws RecognitionException { + msg_sender_return retval = new msg_sender_return(); + retval.start = input.LT(1); + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:220:7: ( 'msg.sender' -> msdSender() + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:220:9: 'msg.sender' + { + match(input,35,FOLLOW_35_in_msg_sender1703); + // TEMPLATE REWRITE + // 220:22: -> msdSender( + { + retval.st = templateLib.getInstanceOf("msdSender"); + } + + + + } + + retval.stop = input.LT(-1); + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + // do for sure before leaving + } + return retval; + } + // $ANTLR end "msg_sender" + + + public static class msg_datasize_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "msg_datasize" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:223:1: msg_datasize : 'msg.datasize' -> msgDatasize(; + public final msg_datasize_return msg_datasize() throws RecognitionException { + msg_datasize_return retval = new msg_datasize_return(); + retval.start = input.LT(1); + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:224:7: ( 'msg.datasize' -> msgDatasize() + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:224:9: 'msg.datasize' + { + match(input,34,FOLLOW_34_in_msg_datasize1730); + // TEMPLATE REWRITE + // 224:24: -> msgDatasize( + { + retval.st = templateLib.getInstanceOf("msgDatasize"); + } + + + + } + + retval.stop = input.LT(-1); + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + // do for sure before leaving + } + return retval; + } + // $ANTLR end "msg_datasize" + + + public static class return_stmt_return extends ParserRuleReturnScope { + public StringTemplate st; + public Object getTemplate() { return st; } + public String toString() { return st==null?null:st.toString(); } + }; + + + // $ANTLR start "return_stmt" + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:227:1: return_stmt : 'return(' bin_expr ')' -> returnStmt(index=$bin_expr.st); + public final return_stmt_return return_stmt() throws RecognitionException { + return_stmt_return retval = new return_stmt_return(); + retval.start = input.LT(1); + + ParserRuleReturnScope bin_expr22 =null; + + try { + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:228:7: ( 'return(' bin_expr ')' -> returnStmt(index=$bin_expr.st)) + // E:\\WorkingArea\\ethereumJ\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g:228:9: 'return(' bin_expr ')' + { + match(input,36,FOLLOW_36_in_return_stmt1757); + pushFollow(FOLLOW_bin_expr_in_return_stmt1758); + bin_expr22=bin_expr(); + state._fsp--; + + match(input,16,FOLLOW_16_in_return_stmt1759); + // TEMPLATE REWRITE + // 228:31: -> returnStmt(index=$bin_expr.st) + { + retval.st = templateLib.getInstanceOf("returnStmt",new STAttrMap().put("index", (bin_expr22!=null?((StringTemplate)bin_expr22.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 "return_stmt" + + // Delegated rules + + + + public static final BitSet FOLLOW_gen_body_in_program60 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_set_var_in_test_1120 = new BitSet(new long[]{0x0000000000000102L}); + public static final BitSet FOLLOW_get_var_in_test_1146 = new BitSet(new long[]{0x0000000000000102L}); + public static final BitSet FOLLOW_set_var_in_gen_body201 = new BitSet(new long[]{0x0000001140000102L}); + public static final BitSet FOLLOW_storage_save_in_gen_body227 = new BitSet(new long[]{0x0000001140000102L}); + public static final BitSet FOLLOW_return_stmt_in_gen_body253 = new BitSet(new long[]{0x0000001140000102L}); + public static final BitSet FOLLOW_if_else_stmt_in_gen_body281 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_32_in_if_stmt328 = new BitSet(new long[]{0x0000000E40001380L}); + public static final BitSet FOLLOW_unr_expr_in_if_stmt330 = new BitSet(new long[]{0x0000000000200000L}); + public static final BitSet FOLLOW_21_in_if_stmt332 = new BitSet(new long[]{0x0000001140000100L}); + public static final BitSet FOLLOW_gen_body_in_if_stmt334 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_32_in_if_else_stmt448 = new BitSet(new long[]{0x0000000E40001380L}); + public static final BitSet FOLLOW_unr_expr_in_if_else_stmt450 = new BitSet(new long[]{0x0000000000200000L}); + public static final BitSet FOLLOW_21_in_if_else_stmt452 = new BitSet(new long[]{0x00000011C0000100L}); + public static final BitSet FOLLOW_gen_body_in_if_else_stmt456 = new BitSet(new long[]{0x0000000080000000L}); + public static final BitSet FOLLOW_31_in_if_else_stmt467 = new BitSet(new long[]{0x0000000000200000L}); + public static final BitSet FOLLOW_21_in_if_else_stmt469 = new BitSet(new long[]{0x0000001140000100L}); + public static final BitSet FOLLOW_gen_body_in_if_else_stmt473 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_var_in_set_var601 = new BitSet(new long[]{0x0000000001000000L}); + public static final BitSet FOLLOW_24_in_set_var614 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_set_var618 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_var_in_get_var670 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_12_in_unr_expr732 = new BitSet(new long[]{0x0000000E40001380L}); + public static final BitSet FOLLOW_cond_expr_in_unr_expr742 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_bin_expr_in_cond_expr774 = new BitSet(new long[]{0x000000000EC00002L}); + public static final BitSet FOLLOW_25_in_cond_expr803 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_cond_expr807 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_22_in_cond_expr843 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_cond_expr848 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_23_in_cond_expr882 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_cond_expr887 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_27_in_cond_expr921 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_cond_expr926 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_26_in_cond_expr960 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_cond_expr965 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_30_in_storage_save1024 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_storage_save1027 = new BitSet(new long[]{0x0000000010000000L}); + public static final BitSet FOLLOW_28_in_storage_save1028 = new BitSet(new long[]{0x0000000001000000L}); + public static final BitSet FOLLOW_24_in_storage_save1030 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_storage_save1034 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_atom_in_bin_expr1072 = new BitSet(new long[]{0x00000000201EE002L}); + public static final BitSet FOLLOW_18_in_bin_expr1090 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_atom_in_bin_expr1095 = new BitSet(new long[]{0x00000000201EE002L}); + public static final BitSet FOLLOW_19_in_bin_expr1126 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_atom_in_bin_expr1131 = new BitSet(new long[]{0x00000000201EE002L}); + public static final BitSet FOLLOW_17_in_bin_expr1162 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_atom_in_bin_expr1167 = new BitSet(new long[]{0x00000000201EE002L}); + public static final BitSet FOLLOW_20_in_bin_expr1198 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_atom_in_bin_expr1203 = new BitSet(new long[]{0x00000000201EE002L}); + public static final BitSet FOLLOW_29_in_bin_expr1234 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_atom_in_bin_expr1239 = new BitSet(new long[]{0x00000000201EE002L}); + public static final BitSet FOLLOW_15_in_bin_expr1270 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_atom_in_bin_expr1275 = new BitSet(new long[]{0x00000000201EE002L}); + public static final BitSet FOLLOW_14_in_bin_expr1306 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_atom_in_bin_expr1310 = new BitSet(new long[]{0x00000000201EE002L}); + public static final BitSet FOLLOW_13_in_bin_expr1340 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_atom_in_bin_expr1344 = new BitSet(new long[]{0x00000000201EE002L}); + public static final BitSet FOLLOW_storage_load_in_atom1414 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_msg_sender_in_atom1433 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_msg_datasize_in_atom1452 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_msg_load_in_atom1471 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_get_var_in_atom1490 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_INTEGER_in_atom1510 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_hex_num_in_atom1529 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_HEX_NUMBER_in_hex_num1564 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_IDENT_in_var1609 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_30_in_storage_load1638 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_storage_load1639 = new BitSet(new long[]{0x0000000010000000L}); + public static final BitSet FOLLOW_28_in_storage_load1640 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_33_in_msg_load1670 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_msg_load1671 = new BitSet(new long[]{0x0000000010000000L}); + public static final BitSet FOLLOW_28_in_msg_load1672 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_35_in_msg_sender1703 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_34_in_msg_datasize1730 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_36_in_return_stmt1757 = new BitSet(new long[]{0x0000000E40000380L}); + public static final BitSet FOLLOW_bin_expr_in_return_stmt1758 = new BitSet(new long[]{0x0000000000010000L}); + public static final BitSet FOLLOW_16_in_return_stmt1759 = new BitSet(new long[]{0x0000000000000002L}); +} diff --git a/ethereumj-core/src/main/java/org/ethereum/util/Utils.java b/ethereumj-core/src/main/java/org/ethereum/util/Utils.java new file mode 100644 index 00000000..dd91bf8d --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/util/Utils.java @@ -0,0 +1,168 @@ +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; + +/** + * www.ethereumj.com + * User: Roman Mandeleil + * Created on: 06/04/14 13:13 + */ +public class Utils { + + 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 String toHexString(byte[] data){ + + if (data == null) return "null"; + else return Hex.toHexString(data); + } + + /** + * @param hexNum should be in form '0x34fabd34....' + * @return + */ + public static String hexStringToDecimalString(String hexNum){ + + boolean match = Pattern.matches("0[xX][0-9a-fA-F]+", hexNum); + if (!match) throw new Error("The string doesn't conains hex num in form 0x.. : [" + hexNum + "]"); + + byte[] numberBytes = Hex.decode(hexNum.substring(2)); + return (new BigInteger(1, numberBytes)).toString(); + } + + + public static void printHexStringForByte(byte data){ + + System.out.print("["); + + String hexNum = Integer.toHexString ((int) data & 0xFF); + 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("["); + for (int i = 0; i < data.length; ++i){ + + String hexNum = Integer.toHexString ((int) data[i] & 0xFF); + 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 new file mode 100644 index 00000000..7c78b85f --- /dev/null +++ b/ethereumj-core/src/main/java/samples/DeterministicDSA.java @@ -0,0 +1,439 @@ +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 new file mode 100644 index 00000000..83543bd8 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/Main1.java @@ -0,0 +1,191 @@ +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 new file mode 100644 index 00000000..738100fb --- /dev/null +++ b/ethereumj-core/src/main/java/samples/Main2.java @@ -0,0 +1,84 @@ +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 new file mode 100644 index 00000000..ddb6c017 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/Main3.java @@ -0,0 +1,48 @@ +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 new file mode 100644 index 00000000..8fff06fb --- /dev/null +++ b/ethereumj-core/src/main/java/samples/Main4.java @@ -0,0 +1,64 @@ +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 new file mode 100644 index 00000000..bdf67680 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/PeersTableMain.java @@ -0,0 +1,81 @@ +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 new file mode 100644 index 00000000..66119b2d --- /dev/null +++ b/ethereumj-core/src/main/java/samples/antlr/GenParser.java @@ -0,0 +1,17 @@ +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 new file mode 100644 index 00000000..3b29b727 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/antlr/PyEsque.g @@ -0,0 +1,105 @@ +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 new file mode 100644 index 00000000..1341f220 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/antlr/PyEsqueLexer.java @@ -0,0 +1,547 @@ +// $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 new file mode 100644 index 00000000..387a6159 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/antlr/PyEsqueParser.java @@ -0,0 +1,394 @@ +// $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 new file mode 100644 index 00000000..ddf5d060 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/antlr/Python.g @@ -0,0 +1,611 @@ +/* + [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 new file mode 100644 index 00000000..96fd5b69 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/antlr/Sample.g @@ -0,0 +1,201 @@ +/******************************************************************************* + * 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 new file mode 100644 index 00000000..5a1728e3 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/antlr/Sample2Asm.stg @@ -0,0 +1,10 @@ + +/** 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 new file mode 100644 index 00000000..c015d8c0 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/antlr/SampleLexer.java @@ -0,0 +1,2151 @@ +// $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 new file mode 100644 index 00000000..2513de23 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/antlr/Test1.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * 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 new file mode 100644 index 00000000..4555270d --- /dev/null +++ b/ethereumj-core/src/main/java/samples/netty/Client.java @@ -0,0 +1,51 @@ +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 new file mode 100644 index 00000000..bbe6977f --- /dev/null +++ b/ethereumj-core/src/main/java/samples/netty/ClientMessageHandler.java @@ -0,0 +1,70 @@ +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 new file mode 100644 index 00000000..b7427a96 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/netty/RomanProtocol.java @@ -0,0 +1,47 @@ +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 new file mode 100644 index 00000000..7e2e5ded --- /dev/null +++ b/ethereumj-core/src/main/java/samples/netty/Server.java @@ -0,0 +1,69 @@ +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 new file mode 100644 index 00000000..4d8abd65 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/netty/ServerMessageHandler.java @@ -0,0 +1,65 @@ +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 new file mode 100644 index 00000000..2d638fdc --- /dev/null +++ b/ethereumj-core/src/main/java/samples/niotut/ChangeRequest.java @@ -0,0 +1,18 @@ +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 new file mode 100644 index 00000000..b6ef02b7 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/niotut/EchoWorker.java @@ -0,0 +1,38 @@ +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 new file mode 100644 index 00000000..28cf42b5 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/niotut/NioClient.java @@ -0,0 +1,403 @@ +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 new file mode 100644 index 00000000..80860955 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/niotut/NioServer.java @@ -0,0 +1,213 @@ +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 new file mode 100644 index 00000000..55212e85 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/niotut/RspHandler.java @@ -0,0 +1,107 @@ +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 new file mode 100644 index 00000000..acc1a0fe --- /dev/null +++ b/ethereumj-core/src/main/java/samples/niotut/ServerDataEvent.java @@ -0,0 +1,16 @@ + +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 new file mode 100644 index 00000000..86769cad --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/Bytecode.stg @@ -0,0 +1,74 @@ +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 new file mode 100644 index 00000000..37322b3e --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/CMinus.g @@ -0,0 +1,152 @@ +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 new file mode 100644 index 00000000..151bc94c --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/CMinusLexer.java @@ -0,0 +1,824 @@ +// $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 new file mode 100644 index 00000000..15ebaad4 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/CMinusParser.java @@ -0,0 +1,1574 @@ +// $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 new file mode 100644 index 00000000..19c64df9 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/GenParser.java @@ -0,0 +1,17 @@ +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 new file mode 100644 index 00000000..c6a3f34d --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/Java.stg @@ -0,0 +1,55 @@ +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 new file mode 100644 index 00000000..34f73bbc --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/Main.java @@ -0,0 +1,30 @@ + +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 new file mode 100644 index 00000000..9ea37bda --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/Python.stg @@ -0,0 +1,48 @@ +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 new file mode 100644 index 00000000..ecda47a0 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/files @@ -0,0 +1,7 @@ +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 new file mode 100644 index 00000000..416f4fc4 --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/input @@ -0,0 +1,9 @@ +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 new file mode 100644 index 00000000..17ab43db --- /dev/null +++ b/ethereumj-core/src/main/java/samples/stg/output @@ -0,0 +1,11 @@ +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/main/resources/GeoLiteCity.dat b/ethereumj-core/src/main/resources/GeoLiteCity.dat new file mode 100644 index 00000000..e94f60e3 Binary files /dev/null and b/ethereumj-core/src/main/resources/GeoLiteCity.dat differ diff --git a/ethereumj-core/src/main/resources/Thumbs.db b/ethereumj-core/src/main/resources/Thumbs.db new file mode 100644 index 00000000..8896a8b9 Binary files /dev/null and b/ethereumj-core/src/main/resources/Thumbs.db differ diff --git a/ethereumj-core/src/main/resources/buttons/Thumbs.db b/ethereumj-core/src/main/resources/buttons/Thumbs.db new file mode 100644 index 00000000..04f0b5cb Binary files /dev/null and b/ethereumj-core/src/main/resources/buttons/Thumbs.db differ diff --git a/ethereumj-core/src/main/resources/buttons/browser.png b/ethereumj-core/src/main/resources/buttons/browser.png new file mode 100644 index 00000000..9d185283 Binary files /dev/null and b/ethereumj-core/src/main/resources/buttons/browser.png differ diff --git a/ethereumj-core/src/main/resources/buttons/feedly.png b/ethereumj-core/src/main/resources/buttons/feedly.png new file mode 100644 index 00000000..5c1df03b Binary files /dev/null and b/ethereumj-core/src/main/resources/buttons/feedly.png differ diff --git a/ethereumj-core/src/main/resources/buttons/ingress.png b/ethereumj-core/src/main/resources/buttons/ingress.png new file mode 100644 index 00000000..4cd817b0 Binary files /dev/null and b/ethereumj-core/src/main/resources/buttons/ingress.png differ diff --git a/ethereumj-core/src/main/resources/buttons/messenger.png b/ethereumj-core/src/main/resources/buttons/messenger.png new file mode 100644 index 00000000..489ec5f7 Binary files /dev/null and b/ethereumj-core/src/main/resources/buttons/messenger.png differ diff --git a/ethereumj-core/src/main/resources/buttons/winamp.png b/ethereumj-core/src/main/resources/buttons/winamp.png new file mode 100644 index 00000000..9a014558 Binary files /dev/null and b/ethereumj-core/src/main/resources/buttons/winamp.png differ diff --git a/ethereumj-core/src/main/resources/connected.png b/ethereumj-core/src/main/resources/connected.png new file mode 100644 index 00000000..fe6d0e7a Binary files /dev/null and b/ethereumj-core/src/main/resources/connected.png differ diff --git a/ethereumj-core/src/main/resources/disconnected.jpg b/ethereumj-core/src/main/resources/disconnected.jpg new file mode 100644 index 00000000..20749be5 Binary files /dev/null and b/ethereumj-core/src/main/resources/disconnected.jpg differ diff --git a/ethereumj-core/src/main/resources/disconnected.png b/ethereumj-core/src/main/resources/disconnected.png new file mode 100644 index 00000000..7d2cf0db Binary files /dev/null and b/ethereumj-core/src/main/resources/disconnected.png differ diff --git a/ethereumj-core/src/main/resources/ethereum-icon - Copy.png b/ethereumj-core/src/main/resources/ethereum-icon - Copy.png new file mode 100644 index 00000000..4bdea4ee Binary files /dev/null and b/ethereumj-core/src/main/resources/ethereum-icon - Copy.png differ diff --git a/ethereumj-core/src/main/resources/ethereum-icon-old.png b/ethereumj-core/src/main/resources/ethereum-icon-old.png new file mode 100644 index 00000000..5d036e0c Binary files /dev/null and b/ethereumj-core/src/main/resources/ethereum-icon-old.png differ diff --git a/ethereumj-core/src/main/resources/ethereum-icon.png b/ethereumj-core/src/main/resources/ethereum-icon.png new file mode 100644 index 00000000..5b775230 Binary files /dev/null and b/ethereumj-core/src/main/resources/ethereum-icon.png differ diff --git a/ethereumj-core/src/main/resources/flags/_ASEAN.png b/ethereumj-core/src/main/resources/flags/_ASEAN.png new file mode 100644 index 00000000..1fb1b918 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_ASEAN.png differ diff --git a/ethereumj-core/src/main/resources/flags/_African Union(OAS).png b/ethereumj-core/src/main/resources/flags/_African Union(OAS).png new file mode 100644 index 00000000..85b268ef Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_African Union(OAS).png differ diff --git a/ethereumj-core/src/main/resources/flags/_Arab League.png b/ethereumj-core/src/main/resources/flags/_Arab League.png new file mode 100644 index 00000000..646a3f72 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Arab League.png differ diff --git a/ethereumj-core/src/main/resources/flags/_CARICOM.png b/ethereumj-core/src/main/resources/flags/_CARICOM.png new file mode 100644 index 00000000..19dfeae3 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_CARICOM.png differ diff --git a/ethereumj-core/src/main/resources/flags/_CIS.png b/ethereumj-core/src/main/resources/flags/_CIS.png new file mode 100644 index 00000000..809c0261 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_CIS.png differ diff --git a/ethereumj-core/src/main/resources/flags/_Commonwealth.png b/ethereumj-core/src/main/resources/flags/_Commonwealth.png new file mode 100644 index 00000000..aa0d8abb Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Commonwealth.png differ diff --git a/ethereumj-core/src/main/resources/flags/_England.png b/ethereumj-core/src/main/resources/flags/_England.png new file mode 100644 index 00000000..22fb06b5 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_England.png differ diff --git a/ethereumj-core/src/main/resources/flags/_European Union.png b/ethereumj-core/src/main/resources/flags/_European Union.png new file mode 100644 index 00000000..18c86daf Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_European Union.png differ diff --git a/ethereumj-core/src/main/resources/flags/_Islamic Conference.png b/ethereumj-core/src/main/resources/flags/_Islamic Conference.png new file mode 100644 index 00000000..cc4aa3b3 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Islamic Conference.png differ diff --git a/ethereumj-core/src/main/resources/flags/_Kosovo.png b/ethereumj-core/src/main/resources/flags/_Kosovo.png new file mode 100644 index 00000000..1d462864 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Kosovo.png differ diff --git a/ethereumj-core/src/main/resources/flags/_NATO.png b/ethereumj-core/src/main/resources/flags/_NATO.png new file mode 100644 index 00000000..d651f063 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_NATO.png differ diff --git a/ethereumj-core/src/main/resources/flags/_Northern Cyprus.png b/ethereumj-core/src/main/resources/flags/_Northern Cyprus.png new file mode 100644 index 00000000..cb346570 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Northern Cyprus.png differ diff --git a/ethereumj-core/src/main/resources/flags/_Northern Ireland.png b/ethereumj-core/src/main/resources/flags/_Northern Ireland.png new file mode 100644 index 00000000..c0eafdf3 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Northern Ireland.png differ diff --git a/ethereumj-core/src/main/resources/flags/_OPEC.png b/ethereumj-core/src/main/resources/flags/_OPEC.png new file mode 100644 index 00000000..5d9c242c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_OPEC.png differ diff --git a/ethereumj-core/src/main/resources/flags/_Olimpic Movement.png b/ethereumj-core/src/main/resources/flags/_Olimpic Movement.png new file mode 100644 index 00000000..71d97aef Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Olimpic Movement.png differ diff --git a/ethereumj-core/src/main/resources/flags/_Red Cross.png b/ethereumj-core/src/main/resources/flags/_Red Cross.png new file mode 100644 index 00000000..fd799672 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Red Cross.png differ diff --git a/ethereumj-core/src/main/resources/flags/_Scotland.png b/ethereumj-core/src/main/resources/flags/_Scotland.png new file mode 100644 index 00000000..4ac5281d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Scotland.png differ diff --git a/ethereumj-core/src/main/resources/flags/_Somaliland.png b/ethereumj-core/src/main/resources/flags/_Somaliland.png new file mode 100644 index 00000000..d44f5809 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Somaliland.png differ diff --git a/ethereumj-core/src/main/resources/flags/_United Nations.png b/ethereumj-core/src/main/resources/flags/_United Nations.png new file mode 100644 index 00000000..6b5f6397 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_United Nations.png differ diff --git a/ethereumj-core/src/main/resources/flags/_Wales.png b/ethereumj-core/src/main/resources/flags/_Wales.png new file mode 100644 index 00000000..3c493454 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/_Wales.png differ diff --git a/ethereumj-core/src/main/resources/flags/ad.png b/ethereumj-core/src/main/resources/flags/ad.png new file mode 100644 index 00000000..e753cd65 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ad.png differ diff --git a/ethereumj-core/src/main/resources/flags/ae.png b/ethereumj-core/src/main/resources/flags/ae.png new file mode 100644 index 00000000..11613758 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ae.png differ diff --git a/ethereumj-core/src/main/resources/flags/af.png b/ethereumj-core/src/main/resources/flags/af.png new file mode 100644 index 00000000..2575b8a9 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/af.png differ diff --git a/ethereumj-core/src/main/resources/flags/ag.png b/ethereumj-core/src/main/resources/flags/ag.png new file mode 100644 index 00000000..cfc157a5 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ag.png differ diff --git a/ethereumj-core/src/main/resources/flags/ai.png b/ethereumj-core/src/main/resources/flags/ai.png new file mode 100644 index 00000000..7a6ac041 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ai.png differ diff --git a/ethereumj-core/src/main/resources/flags/al.png b/ethereumj-core/src/main/resources/flags/al.png new file mode 100644 index 00000000..2e16c3b6 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/al.png differ diff --git a/ethereumj-core/src/main/resources/flags/am.png b/ethereumj-core/src/main/resources/flags/am.png new file mode 100644 index 00000000..f4f9baea Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/am.png differ diff --git a/ethereumj-core/src/main/resources/flags/an.png b/ethereumj-core/src/main/resources/flags/an.png new file mode 100644 index 00000000..e4f171fd Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/an.png differ diff --git a/ethereumj-core/src/main/resources/flags/ao.png b/ethereumj-core/src/main/resources/flags/ao.png new file mode 100644 index 00000000..97ae9630 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ao.png differ diff --git a/ethereumj-core/src/main/resources/flags/aq.png b/ethereumj-core/src/main/resources/flags/aq.png new file mode 100644 index 00000000..a97b3552 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/aq.png differ diff --git a/ethereumj-core/src/main/resources/flags/ar.png b/ethereumj-core/src/main/resources/flags/ar.png new file mode 100644 index 00000000..62d15185 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ar.png differ diff --git a/ethereumj-core/src/main/resources/flags/as.png b/ethereumj-core/src/main/resources/flags/as.png new file mode 100644 index 00000000..b0d4cdc6 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/as.png differ diff --git a/ethereumj-core/src/main/resources/flags/at.png b/ethereumj-core/src/main/resources/flags/at.png new file mode 100644 index 00000000..fe66fef4 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/at.png differ diff --git a/ethereumj-core/src/main/resources/flags/au.png b/ethereumj-core/src/main/resources/flags/au.png new file mode 100644 index 00000000..89374045 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/au.png differ diff --git a/ethereumj-core/src/main/resources/flags/aw.png b/ethereumj-core/src/main/resources/flags/aw.png new file mode 100644 index 00000000..0083ef62 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/aw.png differ diff --git a/ethereumj-core/src/main/resources/flags/az.png b/ethereumj-core/src/main/resources/flags/az.png new file mode 100644 index 00000000..1850abc9 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/az.png differ diff --git a/ethereumj-core/src/main/resources/flags/ba.png b/ethereumj-core/src/main/resources/flags/ba.png new file mode 100644 index 00000000..806d05d2 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ba.png differ diff --git a/ethereumj-core/src/main/resources/flags/bb.png b/ethereumj-core/src/main/resources/flags/bb.png new file mode 100644 index 00000000..d440d410 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bb.png differ diff --git a/ethereumj-core/src/main/resources/flags/bd.png b/ethereumj-core/src/main/resources/flags/bd.png new file mode 100644 index 00000000..8ef2443c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bd.png differ diff --git a/ethereumj-core/src/main/resources/flags/be.png b/ethereumj-core/src/main/resources/flags/be.png new file mode 100644 index 00000000..1d3df4c5 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/be.png differ diff --git a/ethereumj-core/src/main/resources/flags/bf.png b/ethereumj-core/src/main/resources/flags/bf.png new file mode 100644 index 00000000..13ff1326 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bf.png differ diff --git a/ethereumj-core/src/main/resources/flags/bg.png b/ethereumj-core/src/main/resources/flags/bg.png new file mode 100644 index 00000000..c1301928 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bg.png differ diff --git a/ethereumj-core/src/main/resources/flags/bh.png b/ethereumj-core/src/main/resources/flags/bh.png new file mode 100644 index 00000000..c45c7b48 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bh.png differ diff --git a/ethereumj-core/src/main/resources/flags/bi.png b/ethereumj-core/src/main/resources/flags/bi.png new file mode 100644 index 00000000..15e76aa2 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bi.png differ diff --git a/ethereumj-core/src/main/resources/flags/bj.png b/ethereumj-core/src/main/resources/flags/bj.png new file mode 100644 index 00000000..af460631 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bj.png differ diff --git a/ethereumj-core/src/main/resources/flags/bm.png b/ethereumj-core/src/main/resources/flags/bm.png new file mode 100644 index 00000000..880d9653 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bm.png differ diff --git a/ethereumj-core/src/main/resources/flags/bn.png b/ethereumj-core/src/main/resources/flags/bn.png new file mode 100644 index 00000000..650cca6d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bn.png differ diff --git a/ethereumj-core/src/main/resources/flags/bo.png b/ethereumj-core/src/main/resources/flags/bo.png new file mode 100644 index 00000000..a28f0609 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bo.png differ diff --git a/ethereumj-core/src/main/resources/flags/br.png b/ethereumj-core/src/main/resources/flags/br.png new file mode 100644 index 00000000..47a007f2 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/br.png differ diff --git a/ethereumj-core/src/main/resources/flags/bs.png b/ethereumj-core/src/main/resources/flags/bs.png new file mode 100644 index 00000000..753fc830 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bs.png differ diff --git a/ethereumj-core/src/main/resources/flags/bt.png b/ethereumj-core/src/main/resources/flags/bt.png new file mode 100644 index 00000000..db0372ed Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bt.png differ diff --git a/ethereumj-core/src/main/resources/flags/bw.png b/ethereumj-core/src/main/resources/flags/bw.png new file mode 100644 index 00000000..9a06843f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bw.png differ diff --git a/ethereumj-core/src/main/resources/flags/by.png b/ethereumj-core/src/main/resources/flags/by.png new file mode 100644 index 00000000..ce75c73c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/by.png differ diff --git a/ethereumj-core/src/main/resources/flags/bz.png b/ethereumj-core/src/main/resources/flags/bz.png new file mode 100644 index 00000000..4a9aea02 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/bz.png differ diff --git a/ethereumj-core/src/main/resources/flags/ca.png b/ethereumj-core/src/main/resources/flags/ca.png new file mode 100644 index 00000000..bfff4140 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ca.png differ diff --git a/ethereumj-core/src/main/resources/flags/cd.png b/ethereumj-core/src/main/resources/flags/cd.png new file mode 100644 index 00000000..be42ea09 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cd.png differ diff --git a/ethereumj-core/src/main/resources/flags/cf.png b/ethereumj-core/src/main/resources/flags/cf.png new file mode 100644 index 00000000..3f0b5017 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cf.png differ diff --git a/ethereumj-core/src/main/resources/flags/cg.png b/ethereumj-core/src/main/resources/flags/cg.png new file mode 100644 index 00000000..f8c0b25e Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cg.png differ diff --git a/ethereumj-core/src/main/resources/flags/ch.png b/ethereumj-core/src/main/resources/flags/ch.png new file mode 100644 index 00000000..223154d7 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ch.png differ diff --git a/ethereumj-core/src/main/resources/flags/ci.png b/ethereumj-core/src/main/resources/flags/ci.png new file mode 100644 index 00000000..1fee82ca Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ci.png differ diff --git a/ethereumj-core/src/main/resources/flags/ck.png b/ethereumj-core/src/main/resources/flags/ck.png new file mode 100644 index 00000000..7c432c89 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ck.png differ diff --git a/ethereumj-core/src/main/resources/flags/cl.png b/ethereumj-core/src/main/resources/flags/cl.png new file mode 100644 index 00000000..3e764627 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cl.png differ diff --git a/ethereumj-core/src/main/resources/flags/cm.png b/ethereumj-core/src/main/resources/flags/cm.png new file mode 100644 index 00000000..32eccee5 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cm.png differ diff --git a/ethereumj-core/src/main/resources/flags/cn.png b/ethereumj-core/src/main/resources/flags/cn.png new file mode 100644 index 00000000..d0da5509 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cn.png differ diff --git a/ethereumj-core/src/main/resources/flags/co.png b/ethereumj-core/src/main/resources/flags/co.png new file mode 100644 index 00000000..da19e539 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/co.png differ diff --git a/ethereumj-core/src/main/resources/flags/cr.png b/ethereumj-core/src/main/resources/flags/cr.png new file mode 100644 index 00000000..44a30739 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cr.png differ diff --git a/ethereumj-core/src/main/resources/flags/cu.png b/ethereumj-core/src/main/resources/flags/cu.png new file mode 100644 index 00000000..4e3cf299 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cu.png differ diff --git a/ethereumj-core/src/main/resources/flags/cv.png b/ethereumj-core/src/main/resources/flags/cv.png new file mode 100644 index 00000000..103043c2 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cv.png differ diff --git a/ethereumj-core/src/main/resources/flags/cy.png b/ethereumj-core/src/main/resources/flags/cy.png new file mode 100644 index 00000000..df22c033 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cy.png differ diff --git a/ethereumj-core/src/main/resources/flags/cz.png b/ethereumj-core/src/main/resources/flags/cz.png new file mode 100644 index 00000000..31f9ad9b Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/cz.png differ diff --git a/ethereumj-core/src/main/resources/flags/de.png b/ethereumj-core/src/main/resources/flags/de.png new file mode 100644 index 00000000..77e9338b Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/de.png differ diff --git a/ethereumj-core/src/main/resources/flags/dj.png b/ethereumj-core/src/main/resources/flags/dj.png new file mode 100644 index 00000000..8f32f748 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/dj.png differ diff --git a/ethereumj-core/src/main/resources/flags/dk.png b/ethereumj-core/src/main/resources/flags/dk.png new file mode 100644 index 00000000..3f4dac36 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/dk.png differ diff --git a/ethereumj-core/src/main/resources/flags/dm.png b/ethereumj-core/src/main/resources/flags/dm.png new file mode 100644 index 00000000..e70b1a45 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/dm.png differ diff --git a/ethereumj-core/src/main/resources/flags/do.png b/ethereumj-core/src/main/resources/flags/do.png new file mode 100644 index 00000000..ca2d40ac Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/do.png differ diff --git a/ethereumj-core/src/main/resources/flags/dz.png b/ethereumj-core/src/main/resources/flags/dz.png new file mode 100644 index 00000000..69477f04 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/dz.png differ diff --git a/ethereumj-core/src/main/resources/flags/ec.png b/ethereumj-core/src/main/resources/flags/ec.png new file mode 100644 index 00000000..4913cec5 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ec.png differ diff --git a/ethereumj-core/src/main/resources/flags/ee.png b/ethereumj-core/src/main/resources/flags/ee.png new file mode 100644 index 00000000..3eadb299 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ee.png differ diff --git a/ethereumj-core/src/main/resources/flags/eg.png b/ethereumj-core/src/main/resources/flags/eg.png new file mode 100644 index 00000000..ee9fef08 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/eg.png differ diff --git a/ethereumj-core/src/main/resources/flags/eh.png b/ethereumj-core/src/main/resources/flags/eh.png new file mode 100644 index 00000000..5eb501c8 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/eh.png differ diff --git a/ethereumj-core/src/main/resources/flags/er.png b/ethereumj-core/src/main/resources/flags/er.png new file mode 100644 index 00000000..5f38c52a Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/er.png differ diff --git a/ethereumj-core/src/main/resources/flags/es.png b/ethereumj-core/src/main/resources/flags/es.png new file mode 100644 index 00000000..38b66bc4 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/es.png differ diff --git a/ethereumj-core/src/main/resources/flags/et.png b/ethereumj-core/src/main/resources/flags/et.png new file mode 100644 index 00000000..b29191fc Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/et.png differ diff --git a/ethereumj-core/src/main/resources/flags/fi.png b/ethereumj-core/src/main/resources/flags/fi.png new file mode 100644 index 00000000..97d47a9f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/fi.png differ diff --git a/ethereumj-core/src/main/resources/flags/fj.png b/ethereumj-core/src/main/resources/flags/fj.png new file mode 100644 index 00000000..d96b232e Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/fj.png differ diff --git a/ethereumj-core/src/main/resources/flags/fm.png b/ethereumj-core/src/main/resources/flags/fm.png new file mode 100644 index 00000000..02cf4245 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/fm.png differ diff --git a/ethereumj-core/src/main/resources/flags/fo.png b/ethereumj-core/src/main/resources/flags/fo.png new file mode 100644 index 00000000..1bfb68e8 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/fo.png differ diff --git a/ethereumj-core/src/main/resources/flags/fr.png b/ethereumj-core/src/main/resources/flags/fr.png new file mode 100644 index 00000000..12318d45 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/fr.png differ diff --git a/ethereumj-core/src/main/resources/flags/ga.png b/ethereumj-core/src/main/resources/flags/ga.png new file mode 100644 index 00000000..bb1f634c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ga.png differ diff --git a/ethereumj-core/src/main/resources/flags/gb.png b/ethereumj-core/src/main/resources/flags/gb.png new file mode 100644 index 00000000..3853f5e1 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gb.png differ diff --git a/ethereumj-core/src/main/resources/flags/gd.png b/ethereumj-core/src/main/resources/flags/gd.png new file mode 100644 index 00000000..26be61ee Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gd.png differ diff --git a/ethereumj-core/src/main/resources/flags/ge.png b/ethereumj-core/src/main/resources/flags/ge.png new file mode 100644 index 00000000..fb293a0b Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ge.png differ diff --git a/ethereumj-core/src/main/resources/flags/gg.png b/ethereumj-core/src/main/resources/flags/gg.png new file mode 100644 index 00000000..0514cc9e Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gg.png differ diff --git a/ethereumj-core/src/main/resources/flags/gh.png b/ethereumj-core/src/main/resources/flags/gh.png new file mode 100644 index 00000000..16ddfb4f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gh.png differ diff --git a/ethereumj-core/src/main/resources/flags/gi.png b/ethereumj-core/src/main/resources/flags/gi.png new file mode 100644 index 00000000..3d3b66dc Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gi.png differ diff --git a/ethereumj-core/src/main/resources/flags/gl.png b/ethereumj-core/src/main/resources/flags/gl.png new file mode 100644 index 00000000..8dc87f4d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gl.png differ diff --git a/ethereumj-core/src/main/resources/flags/gm.png b/ethereumj-core/src/main/resources/flags/gm.png new file mode 100644 index 00000000..e4bee6ce Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gm.png differ diff --git a/ethereumj-core/src/main/resources/flags/gn.png b/ethereumj-core/src/main/resources/flags/gn.png new file mode 100644 index 00000000..f71c621f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gn.png differ diff --git a/ethereumj-core/src/main/resources/flags/gp.png b/ethereumj-core/src/main/resources/flags/gp.png new file mode 100644 index 00000000..53dca174 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gp.png differ diff --git a/ethereumj-core/src/main/resources/flags/gq.png b/ethereumj-core/src/main/resources/flags/gq.png new file mode 100644 index 00000000..13d3c92d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gq.png differ diff --git a/ethereumj-core/src/main/resources/flags/gr.png b/ethereumj-core/src/main/resources/flags/gr.png new file mode 100644 index 00000000..b00fd5a7 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gr.png differ diff --git a/ethereumj-core/src/main/resources/flags/gt.png b/ethereumj-core/src/main/resources/flags/gt.png new file mode 100644 index 00000000..e5580e93 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gt.png differ diff --git a/ethereumj-core/src/main/resources/flags/gu.png b/ethereumj-core/src/main/resources/flags/gu.png new file mode 100644 index 00000000..f1d6b7a4 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gu.png differ diff --git a/ethereumj-core/src/main/resources/flags/gw.png b/ethereumj-core/src/main/resources/flags/gw.png new file mode 100644 index 00000000..d097a289 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gw.png differ diff --git a/ethereumj-core/src/main/resources/flags/gy.png b/ethereumj-core/src/main/resources/flags/gy.png new file mode 100644 index 00000000..76eabd9c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/gy.png differ diff --git a/ethereumj-core/src/main/resources/flags/hk.png b/ethereumj-core/src/main/resources/flags/hk.png new file mode 100644 index 00000000..46208e0d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/hk.png differ diff --git a/ethereumj-core/src/main/resources/flags/hn.png b/ethereumj-core/src/main/resources/flags/hn.png new file mode 100644 index 00000000..1f327f1b Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/hn.png differ diff --git a/ethereumj-core/src/main/resources/flags/hr.png b/ethereumj-core/src/main/resources/flags/hr.png new file mode 100644 index 00000000..4cb4ea74 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/hr.png differ diff --git a/ethereumj-core/src/main/resources/flags/ht.png b/ethereumj-core/src/main/resources/flags/ht.png new file mode 100644 index 00000000..325cef0c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ht.png differ diff --git a/ethereumj-core/src/main/resources/flags/hu.png b/ethereumj-core/src/main/resources/flags/hu.png new file mode 100644 index 00000000..af757c6c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/hu.png differ diff --git a/ethereumj-core/src/main/resources/flags/id.png b/ethereumj-core/src/main/resources/flags/id.png new file mode 100644 index 00000000..ed42d1f9 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/id.png differ diff --git a/ethereumj-core/src/main/resources/flags/ie.png b/ethereumj-core/src/main/resources/flags/ie.png new file mode 100644 index 00000000..74219ab8 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ie.png differ diff --git a/ethereumj-core/src/main/resources/flags/il.png b/ethereumj-core/src/main/resources/flags/il.png new file mode 100644 index 00000000..3ba7553d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/il.png differ diff --git a/ethereumj-core/src/main/resources/flags/im.png b/ethereumj-core/src/main/resources/flags/im.png new file mode 100644 index 00000000..9478023c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/im.png differ diff --git a/ethereumj-core/src/main/resources/flags/in.png b/ethereumj-core/src/main/resources/flags/in.png new file mode 100644 index 00000000..e0a8865f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/in.png differ diff --git a/ethereumj-core/src/main/resources/flags/iq.png b/ethereumj-core/src/main/resources/flags/iq.png new file mode 100644 index 00000000..cdd0c4fe Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/iq.png differ diff --git a/ethereumj-core/src/main/resources/flags/ir.png b/ethereumj-core/src/main/resources/flags/ir.png new file mode 100644 index 00000000..70da4fcd Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ir.png differ diff --git a/ethereumj-core/src/main/resources/flags/is.png b/ethereumj-core/src/main/resources/flags/is.png new file mode 100644 index 00000000..33d68ddf Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/is.png differ diff --git a/ethereumj-core/src/main/resources/flags/it.png b/ethereumj-core/src/main/resources/flags/it.png new file mode 100644 index 00000000..c31017ef Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/it.png differ diff --git a/ethereumj-core/src/main/resources/flags/je.png b/ethereumj-core/src/main/resources/flags/je.png new file mode 100644 index 00000000..b8f5ba6c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/je.png differ diff --git a/ethereumj-core/src/main/resources/flags/jm.png b/ethereumj-core/src/main/resources/flags/jm.png new file mode 100644 index 00000000..e79cf2a8 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/jm.png differ diff --git a/ethereumj-core/src/main/resources/flags/jo.png b/ethereumj-core/src/main/resources/flags/jo.png new file mode 100644 index 00000000..b627a5c9 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/jo.png differ diff --git a/ethereumj-core/src/main/resources/flags/jp.png b/ethereumj-core/src/main/resources/flags/jp.png new file mode 100644 index 00000000..29c45d58 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/jp.png differ diff --git a/ethereumj-core/src/main/resources/flags/ke.png b/ethereumj-core/src/main/resources/flags/ke.png new file mode 100644 index 00000000..e3d7f12d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ke.png differ diff --git a/ethereumj-core/src/main/resources/flags/kg.png b/ethereumj-core/src/main/resources/flags/kg.png new file mode 100644 index 00000000..cf2d885f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/kg.png differ diff --git a/ethereumj-core/src/main/resources/flags/kh.png b/ethereumj-core/src/main/resources/flags/kh.png new file mode 100644 index 00000000..65b4c06e Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/kh.png differ diff --git a/ethereumj-core/src/main/resources/flags/ki.png b/ethereumj-core/src/main/resources/flags/ki.png new file mode 100644 index 00000000..5d286d25 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ki.png differ diff --git a/ethereumj-core/src/main/resources/flags/km.png b/ethereumj-core/src/main/resources/flags/km.png new file mode 100644 index 00000000..051fc5ad Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/km.png differ diff --git a/ethereumj-core/src/main/resources/flags/kn.png b/ethereumj-core/src/main/resources/flags/kn.png new file mode 100644 index 00000000..75f3ed29 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/kn.png differ diff --git a/ethereumj-core/src/main/resources/flags/kp.png b/ethereumj-core/src/main/resources/flags/kp.png new file mode 100644 index 00000000..f51a2bf8 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/kp.png differ diff --git a/ethereumj-core/src/main/resources/flags/kr.png b/ethereumj-core/src/main/resources/flags/kr.png new file mode 100644 index 00000000..13e27e11 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/kr.png differ diff --git a/ethereumj-core/src/main/resources/flags/kw.png b/ethereumj-core/src/main/resources/flags/kw.png new file mode 100644 index 00000000..8d7adb1a Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/kw.png differ diff --git a/ethereumj-core/src/main/resources/flags/ky.png b/ethereumj-core/src/main/resources/flags/ky.png new file mode 100644 index 00000000..f2a6b6c2 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ky.png differ diff --git a/ethereumj-core/src/main/resources/flags/kz.png b/ethereumj-core/src/main/resources/flags/kz.png new file mode 100644 index 00000000..8980ad96 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/kz.png differ diff --git a/ethereumj-core/src/main/resources/flags/la.png b/ethereumj-core/src/main/resources/flags/la.png new file mode 100644 index 00000000..f3b23092 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/la.png differ diff --git a/ethereumj-core/src/main/resources/flags/lb.png b/ethereumj-core/src/main/resources/flags/lb.png new file mode 100644 index 00000000..854717e9 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/lb.png differ diff --git a/ethereumj-core/src/main/resources/flags/lc.png b/ethereumj-core/src/main/resources/flags/lc.png new file mode 100644 index 00000000..987e1f0f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/lc.png differ diff --git a/ethereumj-core/src/main/resources/flags/li.png b/ethereumj-core/src/main/resources/flags/li.png new file mode 100644 index 00000000..4661f3dd Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/li.png differ diff --git a/ethereumj-core/src/main/resources/flags/lk.png b/ethereumj-core/src/main/resources/flags/lk.png new file mode 100644 index 00000000..2a7d9259 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/lk.png differ diff --git a/ethereumj-core/src/main/resources/flags/lr.png b/ethereumj-core/src/main/resources/flags/lr.png new file mode 100644 index 00000000..cadfec1d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/lr.png differ diff --git a/ethereumj-core/src/main/resources/flags/ls.png b/ethereumj-core/src/main/resources/flags/ls.png new file mode 100644 index 00000000..9af5c4a1 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ls.png differ diff --git a/ethereumj-core/src/main/resources/flags/lt.png b/ethereumj-core/src/main/resources/flags/lt.png new file mode 100644 index 00000000..875dd3f9 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/lt.png differ diff --git a/ethereumj-core/src/main/resources/flags/lu.png b/ethereumj-core/src/main/resources/flags/lu.png new file mode 100644 index 00000000..cef746a4 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/lu.png differ diff --git a/ethereumj-core/src/main/resources/flags/lv.png b/ethereumj-core/src/main/resources/flags/lv.png new file mode 100644 index 00000000..6ace36d1 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/lv.png differ diff --git a/ethereumj-core/src/main/resources/flags/ly.png b/ethereumj-core/src/main/resources/flags/ly.png new file mode 100644 index 00000000..8176ad52 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ly.png differ diff --git a/ethereumj-core/src/main/resources/flags/ma.png b/ethereumj-core/src/main/resources/flags/ma.png new file mode 100644 index 00000000..c1bb9707 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ma.png differ diff --git a/ethereumj-core/src/main/resources/flags/mc.png b/ethereumj-core/src/main/resources/flags/mc.png new file mode 100644 index 00000000..bda53b1d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mc.png differ diff --git a/ethereumj-core/src/main/resources/flags/md.png b/ethereumj-core/src/main/resources/flags/md.png new file mode 100644 index 00000000..344855ae Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/md.png differ diff --git a/ethereumj-core/src/main/resources/flags/me.png b/ethereumj-core/src/main/resources/flags/me.png new file mode 100644 index 00000000..51429184 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/me.png differ diff --git a/ethereumj-core/src/main/resources/flags/mg.png b/ethereumj-core/src/main/resources/flags/mg.png new file mode 100644 index 00000000..31e6d84c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mg.png differ diff --git a/ethereumj-core/src/main/resources/flags/mh.png b/ethereumj-core/src/main/resources/flags/mh.png new file mode 100644 index 00000000..1d158692 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mh.png differ diff --git a/ethereumj-core/src/main/resources/flags/mk.png b/ethereumj-core/src/main/resources/flags/mk.png new file mode 100644 index 00000000..0bc91513 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mk.png differ diff --git a/ethereumj-core/src/main/resources/flags/ml.png b/ethereumj-core/src/main/resources/flags/ml.png new file mode 100644 index 00000000..189bff7f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ml.png differ diff --git a/ethereumj-core/src/main/resources/flags/mm.png b/ethereumj-core/src/main/resources/flags/mm.png new file mode 100644 index 00000000..2deafe18 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mm.png differ diff --git a/ethereumj-core/src/main/resources/flags/mn.png b/ethereumj-core/src/main/resources/flags/mn.png new file mode 100644 index 00000000..83b75425 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mn.png differ diff --git a/ethereumj-core/src/main/resources/flags/mo.png b/ethereumj-core/src/main/resources/flags/mo.png new file mode 100644 index 00000000..e413fa5a Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mo.png differ diff --git a/ethereumj-core/src/main/resources/flags/mq.png b/ethereumj-core/src/main/resources/flags/mq.png new file mode 100644 index 00000000..f2b7be41 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mq.png differ diff --git a/ethereumj-core/src/main/resources/flags/mr.png b/ethereumj-core/src/main/resources/flags/mr.png new file mode 100644 index 00000000..fcf1b44b Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mr.png differ diff --git a/ethereumj-core/src/main/resources/flags/ms.png b/ethereumj-core/src/main/resources/flags/ms.png new file mode 100644 index 00000000..a799545d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ms.png differ diff --git a/ethereumj-core/src/main/resources/flags/mt.png b/ethereumj-core/src/main/resources/flags/mt.png new file mode 100644 index 00000000..a93f9eef Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mt.png differ diff --git a/ethereumj-core/src/main/resources/flags/mu.png b/ethereumj-core/src/main/resources/flags/mu.png new file mode 100644 index 00000000..e4c0b7d8 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mu.png differ diff --git a/ethereumj-core/src/main/resources/flags/mv.png b/ethereumj-core/src/main/resources/flags/mv.png new file mode 100644 index 00000000..92472ec8 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mv.png differ diff --git a/ethereumj-core/src/main/resources/flags/mw.png b/ethereumj-core/src/main/resources/flags/mw.png new file mode 100644 index 00000000..b96d0ad2 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mw.png differ diff --git a/ethereumj-core/src/main/resources/flags/mx.png b/ethereumj-core/src/main/resources/flags/mx.png new file mode 100644 index 00000000..f0557d0d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mx.png differ diff --git a/ethereumj-core/src/main/resources/flags/my.png b/ethereumj-core/src/main/resources/flags/my.png new file mode 100644 index 00000000..92686c29 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/my.png differ diff --git a/ethereumj-core/src/main/resources/flags/mz.png b/ethereumj-core/src/main/resources/flags/mz.png new file mode 100644 index 00000000..07c0a8a9 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/mz.png differ diff --git a/ethereumj-core/src/main/resources/flags/na.png b/ethereumj-core/src/main/resources/flags/na.png new file mode 100644 index 00000000..9d14ed35 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/na.png differ diff --git a/ethereumj-core/src/main/resources/flags/nc.png b/ethereumj-core/src/main/resources/flags/nc.png new file mode 100644 index 00000000..dc3e9e10 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/nc.png differ diff --git a/ethereumj-core/src/main/resources/flags/ne.png b/ethereumj-core/src/main/resources/flags/ne.png new file mode 100644 index 00000000..06a7c089 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ne.png differ diff --git a/ethereumj-core/src/main/resources/flags/ng.png b/ethereumj-core/src/main/resources/flags/ng.png new file mode 100644 index 00000000..899e0be6 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ng.png differ diff --git a/ethereumj-core/src/main/resources/flags/ni.png b/ethereumj-core/src/main/resources/flags/ni.png new file mode 100644 index 00000000..ad8ab440 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ni.png differ diff --git a/ethereumj-core/src/main/resources/flags/nl.png b/ethereumj-core/src/main/resources/flags/nl.png new file mode 100644 index 00000000..d5ea7687 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/nl.png differ diff --git a/ethereumj-core/src/main/resources/flags/no.png b/ethereumj-core/src/main/resources/flags/no.png new file mode 100644 index 00000000..2b03236f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/no.png differ diff --git a/ethereumj-core/src/main/resources/flags/np.png b/ethereumj-core/src/main/resources/flags/np.png new file mode 100644 index 00000000..f011adc4 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/np.png differ diff --git a/ethereumj-core/src/main/resources/flags/nr.png b/ethereumj-core/src/main/resources/flags/nr.png new file mode 100644 index 00000000..f763397c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/nr.png differ diff --git a/ethereumj-core/src/main/resources/flags/nz.png b/ethereumj-core/src/main/resources/flags/nz.png new file mode 100644 index 00000000..ef474ad1 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/nz.png differ diff --git a/ethereumj-core/src/main/resources/flags/om.png b/ethereumj-core/src/main/resources/flags/om.png new file mode 100644 index 00000000..111b1149 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/om.png differ diff --git a/ethereumj-core/src/main/resources/flags/pa.png b/ethereumj-core/src/main/resources/flags/pa.png new file mode 100644 index 00000000..e39849d7 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/pa.png differ diff --git a/ethereumj-core/src/main/resources/flags/pe.png b/ethereumj-core/src/main/resources/flags/pe.png new file mode 100644 index 00000000..f971a354 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/pe.png differ diff --git a/ethereumj-core/src/main/resources/flags/pf.png b/ethereumj-core/src/main/resources/flags/pf.png new file mode 100644 index 00000000..cbc56d0a Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/pf.png differ diff --git a/ethereumj-core/src/main/resources/flags/pg.png b/ethereumj-core/src/main/resources/flags/pg.png new file mode 100644 index 00000000..7b0d0eec Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/pg.png differ diff --git a/ethereumj-core/src/main/resources/flags/ph.png b/ethereumj-core/src/main/resources/flags/ph.png new file mode 100644 index 00000000..d025d4d5 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ph.png differ diff --git a/ethereumj-core/src/main/resources/flags/pk.png b/ethereumj-core/src/main/resources/flags/pk.png new file mode 100644 index 00000000..1630f551 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/pk.png differ diff --git a/ethereumj-core/src/main/resources/flags/pl.png b/ethereumj-core/src/main/resources/flags/pl.png new file mode 100644 index 00000000..7a718046 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/pl.png differ diff --git a/ethereumj-core/src/main/resources/flags/pr.png b/ethereumj-core/src/main/resources/flags/pr.png new file mode 100644 index 00000000..146ca81e Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/pr.png differ diff --git a/ethereumj-core/src/main/resources/flags/ps.png b/ethereumj-core/src/main/resources/flags/ps.png new file mode 100644 index 00000000..6f654e31 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ps.png differ diff --git a/ethereumj-core/src/main/resources/flags/pt.png b/ethereumj-core/src/main/resources/flags/pt.png new file mode 100644 index 00000000..5b390731 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/pt.png differ diff --git a/ethereumj-core/src/main/resources/flags/pw.png b/ethereumj-core/src/main/resources/flags/pw.png new file mode 100644 index 00000000..21a45c4c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/pw.png differ diff --git a/ethereumj-core/src/main/resources/flags/py.png b/ethereumj-core/src/main/resources/flags/py.png new file mode 100644 index 00000000..d8cc505a Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/py.png differ diff --git a/ethereumj-core/src/main/resources/flags/qa.png b/ethereumj-core/src/main/resources/flags/qa.png new file mode 100644 index 00000000..1dd11830 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/qa.png differ diff --git a/ethereumj-core/src/main/resources/flags/re.png b/ethereumj-core/src/main/resources/flags/re.png new file mode 100644 index 00000000..8087909f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/re.png differ diff --git a/ethereumj-core/src/main/resources/flags/ro.png b/ethereumj-core/src/main/resources/flags/ro.png new file mode 100644 index 00000000..b8cdad8b Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ro.png differ diff --git a/ethereumj-core/src/main/resources/flags/rs.png b/ethereumj-core/src/main/resources/flags/rs.png new file mode 100644 index 00000000..b2afcf5d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/rs.png differ diff --git a/ethereumj-core/src/main/resources/flags/ru.png b/ethereumj-core/src/main/resources/flags/ru.png new file mode 100644 index 00000000..a5b95285 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ru.png differ diff --git a/ethereumj-core/src/main/resources/flags/rw.png b/ethereumj-core/src/main/resources/flags/rw.png new file mode 100644 index 00000000..f6f51635 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/rw.png differ diff --git a/ethereumj-core/src/main/resources/flags/sa.png b/ethereumj-core/src/main/resources/flags/sa.png new file mode 100644 index 00000000..9630e83d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sa.png differ diff --git a/ethereumj-core/src/main/resources/flags/sb.png b/ethereumj-core/src/main/resources/flags/sb.png new file mode 100644 index 00000000..f1ffebb3 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sb.png differ diff --git a/ethereumj-core/src/main/resources/flags/sc.png b/ethereumj-core/src/main/resources/flags/sc.png new file mode 100644 index 00000000..de605e60 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sc.png differ diff --git a/ethereumj-core/src/main/resources/flags/sd.png b/ethereumj-core/src/main/resources/flags/sd.png new file mode 100644 index 00000000..3a379852 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sd.png differ diff --git a/ethereumj-core/src/main/resources/flags/se.png b/ethereumj-core/src/main/resources/flags/se.png new file mode 100644 index 00000000..2c9bd9db Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/se.png differ diff --git a/ethereumj-core/src/main/resources/flags/sg.png b/ethereumj-core/src/main/resources/flags/sg.png new file mode 100644 index 00000000..4b887853 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sg.png differ diff --git a/ethereumj-core/src/main/resources/flags/si.png b/ethereumj-core/src/main/resources/flags/si.png new file mode 100644 index 00000000..cfa83b54 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/si.png differ diff --git a/ethereumj-core/src/main/resources/flags/sk.png b/ethereumj-core/src/main/resources/flags/sk.png new file mode 100644 index 00000000..418c7869 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sk.png differ diff --git a/ethereumj-core/src/main/resources/flags/sl.png b/ethereumj-core/src/main/resources/flags/sl.png new file mode 100644 index 00000000..47b26eb5 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sl.png differ diff --git a/ethereumj-core/src/main/resources/flags/sm.png b/ethereumj-core/src/main/resources/flags/sm.png new file mode 100644 index 00000000..92bd72b6 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sm.png differ diff --git a/ethereumj-core/src/main/resources/flags/sn.png b/ethereumj-core/src/main/resources/flags/sn.png new file mode 100644 index 00000000..13c93653 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sn.png differ diff --git a/ethereumj-core/src/main/resources/flags/so.png b/ethereumj-core/src/main/resources/flags/so.png new file mode 100644 index 00000000..6a02c72c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/so.png differ diff --git a/ethereumj-core/src/main/resources/flags/sr.png b/ethereumj-core/src/main/resources/flags/sr.png new file mode 100644 index 00000000..cb4a87ac Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sr.png differ diff --git a/ethereumj-core/src/main/resources/flags/st.png b/ethereumj-core/src/main/resources/flags/st.png new file mode 100644 index 00000000..b5187c6a Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/st.png differ diff --git a/ethereumj-core/src/main/resources/flags/sv.png b/ethereumj-core/src/main/resources/flags/sv.png new file mode 100644 index 00000000..adf8750b Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sv.png differ diff --git a/ethereumj-core/src/main/resources/flags/sy.png b/ethereumj-core/src/main/resources/flags/sy.png new file mode 100644 index 00000000..0584c20d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sy.png differ diff --git a/ethereumj-core/src/main/resources/flags/sz.png b/ethereumj-core/src/main/resources/flags/sz.png new file mode 100644 index 00000000..3585ac09 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/sz.png differ diff --git a/ethereumj-core/src/main/resources/flags/tc.png b/ethereumj-core/src/main/resources/flags/tc.png new file mode 100644 index 00000000..fc66ef01 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tc.png differ diff --git a/ethereumj-core/src/main/resources/flags/td.png b/ethereumj-core/src/main/resources/flags/td.png new file mode 100644 index 00000000..c74a4a4a Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/td.png differ diff --git a/ethereumj-core/src/main/resources/flags/tg.png b/ethereumj-core/src/main/resources/flags/tg.png new file mode 100644 index 00000000..5a100b15 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tg.png differ diff --git a/ethereumj-core/src/main/resources/flags/th.png b/ethereumj-core/src/main/resources/flags/th.png new file mode 100644 index 00000000..8f3b5e71 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/th.png differ diff --git a/ethereumj-core/src/main/resources/flags/tj.png b/ethereumj-core/src/main/resources/flags/tj.png new file mode 100644 index 00000000..09a79072 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tj.png differ diff --git a/ethereumj-core/src/main/resources/flags/tl.png b/ethereumj-core/src/main/resources/flags/tl.png new file mode 100644 index 00000000..296fba0d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tl.png differ diff --git a/ethereumj-core/src/main/resources/flags/tm.png b/ethereumj-core/src/main/resources/flags/tm.png new file mode 100644 index 00000000..e3c50edd Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tm.png differ diff --git a/ethereumj-core/src/main/resources/flags/tn.png b/ethereumj-core/src/main/resources/flags/tn.png new file mode 100644 index 00000000..d867a5ef Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tn.png differ diff --git a/ethereumj-core/src/main/resources/flags/to.png b/ethereumj-core/src/main/resources/flags/to.png new file mode 100644 index 00000000..f62ba374 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/to.png differ diff --git a/ethereumj-core/src/main/resources/flags/tr.png b/ethereumj-core/src/main/resources/flags/tr.png new file mode 100644 index 00000000..0398e54d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tr.png differ diff --git a/ethereumj-core/src/main/resources/flags/tt.png b/ethereumj-core/src/main/resources/flags/tt.png new file mode 100644 index 00000000..cf856603 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tt.png differ diff --git a/ethereumj-core/src/main/resources/flags/tv.png b/ethereumj-core/src/main/resources/flags/tv.png new file mode 100644 index 00000000..3a403a61 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tv.png differ diff --git a/ethereumj-core/src/main/resources/flags/tw.png b/ethereumj-core/src/main/resources/flags/tw.png new file mode 100644 index 00000000..956d8534 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tw.png differ diff --git a/ethereumj-core/src/main/resources/flags/tz.png b/ethereumj-core/src/main/resources/flags/tz.png new file mode 100644 index 00000000..f0e1f395 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/tz.png differ diff --git a/ethereumj-core/src/main/resources/flags/ua.png b/ethereumj-core/src/main/resources/flags/ua.png new file mode 100644 index 00000000..78e4945c Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ua.png differ diff --git a/ethereumj-core/src/main/resources/flags/ug.png b/ethereumj-core/src/main/resources/flags/ug.png new file mode 100644 index 00000000..744d39d9 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ug.png differ diff --git a/ethereumj-core/src/main/resources/flags/us.png b/ethereumj-core/src/main/resources/flags/us.png new file mode 100644 index 00000000..48c448fc Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/us.png differ diff --git a/ethereumj-core/src/main/resources/flags/uy.png b/ethereumj-core/src/main/resources/flags/uy.png new file mode 100644 index 00000000..0eddedc9 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/uy.png differ diff --git a/ethereumj-core/src/main/resources/flags/uz.png b/ethereumj-core/src/main/resources/flags/uz.png new file mode 100644 index 00000000..97ade3f2 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/uz.png differ diff --git a/ethereumj-core/src/main/resources/flags/va.png b/ethereumj-core/src/main/resources/flags/va.png new file mode 100644 index 00000000..c344e8b6 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/va.png differ diff --git a/ethereumj-core/src/main/resources/flags/vc.png b/ethereumj-core/src/main/resources/flags/vc.png new file mode 100644 index 00000000..e6333601 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/vc.png differ diff --git a/ethereumj-core/src/main/resources/flags/ve.png b/ethereumj-core/src/main/resources/flags/ve.png new file mode 100644 index 00000000..8ba69c4f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ve.png differ diff --git a/ethereumj-core/src/main/resources/flags/vg.png b/ethereumj-core/src/main/resources/flags/vg.png new file mode 100644 index 00000000..eb22e44f Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/vg.png differ diff --git a/ethereumj-core/src/main/resources/flags/vi.png b/ethereumj-core/src/main/resources/flags/vi.png new file mode 100644 index 00000000..13be8077 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/vi.png differ diff --git a/ethereumj-core/src/main/resources/flags/vn.png b/ethereumj-core/src/main/resources/flags/vn.png new file mode 100644 index 00000000..c9368df0 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/vn.png differ diff --git a/ethereumj-core/src/main/resources/flags/vu.png b/ethereumj-core/src/main/resources/flags/vu.png new file mode 100644 index 00000000..ff6cbeff Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/vu.png differ diff --git a/ethereumj-core/src/main/resources/flags/ws.png b/ethereumj-core/src/main/resources/flags/ws.png new file mode 100644 index 00000000..e671ebb6 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ws.png differ diff --git a/ethereumj-core/src/main/resources/flags/ye.png b/ethereumj-core/src/main/resources/flags/ye.png new file mode 100644 index 00000000..987a212d Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/ye.png differ diff --git a/ethereumj-core/src/main/resources/flags/za.png b/ethereumj-core/src/main/resources/flags/za.png new file mode 100644 index 00000000..d1920dec Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/za.png differ diff --git a/ethereumj-core/src/main/resources/flags/zm.png b/ethereumj-core/src/main/resources/flags/zm.png new file mode 100644 index 00000000..639c3ace Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/zm.png differ diff --git a/ethereumj-core/src/main/resources/flags/zw.png b/ethereumj-core/src/main/resources/flags/zw.png new file mode 100644 index 00000000..39106df6 Binary files /dev/null and b/ethereumj-core/src/main/resources/flags/zw.png differ diff --git a/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java b/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java new file mode 100644 index 00000000..b5c9cf20 --- /dev/null +++ b/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java @@ -0,0 +1,169 @@ +package org.ethereum.block; + +import org.bouncycastle.util.encoders.Hex; +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 */ + public void test1() throws IOException { + +/* + def serialize(self): + txlist = [x.serialize() for x in self.transactions] + header = [encode_int(self.number), + self.prevhash, + sha3(rlp.encode(self.uncles)), + self.coinbase.decode('hex'), + self.state.root, + sha3(rlp.encode(txlist)), + encode_int(self.difficulty), + encode_int(self.timestamp), + self.extradata, + encode_int(self.nonce)] + return rlp.encode([header, txlist, self.uncles]) +*/ + +/* + + + ( 0(256) - parentHash + SHA3(RLP(emptyList)) - hashes of transactions + 0(160) - coinbase + 0(256) - stateRoot + SHA3(RLP(emptyList)) - hashes of uncles + 2**22 - difficulty + 0 - timestamp + () - + 42 - nonce ) + () - uncles + () - transactions + + + block.appendList(9) << h256() << sha3EmptyList << h160() << stateRoot << sha3EmptyList << c_genesisDifficulty << (uint)0 << string() << sha3(bytes(1, 42)); + 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + prevHash = RLP.encodeElement(prevHash); + + /* 2 */ byte[] uncleList = RLP.encodeElement(Utils.sha3(RLP.encodeList(new byte[]{}))); + + /* 3 */ byte[] coinbase = + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + coinbase = RLP.encodeElement(coinbase); + + /* 4 */ byte[] rootState = {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}; + rootState = RLP.encodeElement(rootState); + + /* 5 */ byte[] transactionsRoot = RLP.encodeElement(Utils.sha3(RLP.encodeList(new byte[]{}))); + + /* 6 */ BigInteger difficulty = new BigInteger("2"); + difficulty = difficulty.pow(22); + byte[] diffBytes = RLP.encodeElement(difficulty.toByteArray()); + + /* 7 */ byte[] longTS = {0x00, 0x00, 0x00, 0x00}; + longTS = RLP.encodeElement(longTS); + + /* 8 */ byte[] extradata = {}; + extradata = RLP.encodeElement(extradata); + + /* 9 */ byte[] nonce = {42}; + nonce = RLP.encodeElement( Utils.sha3(nonce) ); + + + + byte[] header = RLP.encodeList( prevHash, + uncleList, + coinbase, + rootState, + transactionsRoot, + diffBytes, + longTS, + extradata, + nonce); + +// 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); + + System.out.println(Hex.toHexString(hash)); + + System.out.println("ab6b9a5613970faa771b12d449b2e9bb925ab7a369f0a4b86b286e9d540099cf"); + + + } + + @Test /* got from go guy */ + public void test2(){ + + byte[] goGenesisBytes = Hex.decode("f8a4f8a0a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794000000000000000000000000000000000000000080a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347834000008080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0"); + System.out.println( Hex.toHexString( Utils.sha3(goGenesisBytes) ) ); + + } + + + @Test /* create BlockData from part of real RLP BLOCKS message */ + public void test3(){ + + String blocksMsg= "F8C8F8C4A07B2536237CBF114A043B0F9B27C76F84AC160EA5B87B53E42C7E76148964D450A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A07A3BE0EE10ECE4B03097BF74AABAC628AA0FAE617377D30AB1B97376EE31F41AA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FBFE884533F1CE880A0000000000000000000000000000000000000000000000000F3DEEA84969B6E95C0C0"; + + byte[] payload = Hex.decode(blocksMsg); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + BlockData blockData = new BlockData(rlpList); + + RLPList.recursivePrint(rlpList); + + } + + +} + + + +/* +[[ab6b9a5613970faa771b12d449b2e9bb925ab7a369f0a4b86b286e9d540099cf, 1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347, 3854aaf203ba5f8d49b1ec221329c7aebcf050d3, 990dc3b5acbee04124361d958fe51acb582593613fc290683940a0769549d3ed, 9bfe4817d274ea3eb8672e9fe848c3885b53bbbd1d7c26e6039f90fb96b942b0, 3ff000, 533f16b7, null, 00000000000000000000000000000000000000000000000077377adff6c227db, ] + [ + [null, null, 0000000000000000000000000000000000000000, 09184e72a000, 2710, 606956330c0d630000003359366000530a0d630000003359602060005301356000533557604060005301600054630000000c58, 33606957, 1c, 7f6eb94576346488c6253197bde6a7e59ddc36f2773672c849402aa9c402c3c4, 6d254e662bf7450dd8d835160cbb053463fed0b53f2cdd7f3ea8731919c8e8cc, ] + [01, null, 0000000000000000000000000000000000000000, 09184e72a000, 2710, 36630000002e59606956330c0d63000000155933ff33560d63000000275960003356576000335700630000005358600035560d630000003a590033560d63000000485960003356573360003557600035335700, 7f4e616d65526567000000000000000000000000000000000000000000000000003057307f4e616d65526567000000000000000000000000000000000000000000000000005733606957, 1b, 4af15a0ec494aeac5b243c8a2690833faa74c0f73db1f439d521c49c381513e9, 5802e64939be5a1f9d4d614038fbd5479538c48795614ef9c551477ecbdb49d2, ] + [02, null, ccdeac59d35627b7de09332e819d5159e7bb7250, 09184e72a000, 2710, 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d0aceee7e5ab874e22ccf8d1a649f59106d74e8, 1b, d05887574456c6de8f7a0d172342c2cbdd4cf7afe15d9dbb8b75b748ba6791c9, 1e87172a861f6c37b5a9e3a5d0d7393152a7fbe41530e5bb8ac8f35433e5931b, ]]*/ diff --git a/ethereumj-core/src/test/java/org/ethereum/crypto/CryptoTest.java b/ethereumj-core/src/test/java/org/ethereum/crypto/CryptoTest.java new file mode 100644 index 00000000..21035bbf --- /dev/null +++ b/ethereumj-core/src/test/java/org/ethereum/crypto/CryptoTest.java @@ -0,0 +1,133 @@ +package org.ethereum.crypto; + +import junit.framework.Assert; +import org.bouncycastle.util.encoders.Hex; +import org.ethereum.util.Utils; +import org.junit.Test; + +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()); + + Assert.assertEquals("c87f65ff3f271bf5dc8643484f66b200109caffe4bf98c4cb393dc35740b28c0", + Hex.toHexString(result)); + + result = Utils.sha3("cow".getBytes()); + + Assert.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)); + } + + @Test + public void test4(){ + + byte[] cowBytes = Utils.sha3("cow".getBytes()); + + byte[] addr = Utils.privToAddress(cowBytes); + Assert.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()); + } + + + @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()); + } + 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)); + String txHash = Utils.toHexString(txHashB); + + Assert.assertEquals("4b7d9670a92bf120d5b43400543b69304a14d767cf836a7f6abff4edde092895", txHash); + + } + + @Test /* real block hash calc */ + public void test8(){ + + String blockRaw = "F885F8818080A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347940000000000000000000000000000000000000000A0BCDDD284BF396739C224DBA0411566C891C32115FEB998A3E2B4E61F3F35582AA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D4934783800000808080C0C0"; + + byte[] blockHashB = Utils.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/net/MessagesTest.java b/ethereumj-core/src/test/java/org/ethereum/net/MessagesTest.java new file mode 100644 index 00000000..a45f1243 --- /dev/null +++ b/ethereumj-core/src/test/java/org/ethereum/net/MessagesTest.java @@ -0,0 +1,483 @@ +package org.ethereum.net; + +import junit.framework.Assert; +import org.bouncycastle.util.encoders.Hex; +import org.ethereum.net.message.*; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.net.vo.BlockData; +import org.ethereum.net.vo.PeerData; +import org.ethereum.net.vo.TransactionData; +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 */ + + @Test /* HelloMessage 1 */ + public void test_1(){ + + String helloMessageRaw = "F8 77 80 0C 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 35 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 83 3B 83 56 0E 0B 12 17 0E 91 69 DC 43 78 " + + "42 23 A5 98 42 DE 23 59 E6 D0 3D B3 4C 30 A9 66 " + + "C2 DE 3B 4B 25 52 FB 0D 75 95 A1 85 D5 58 F2 E6 " + + "69 B5 95 67 4F 52 17 C9 96 EE 14 88 84 82 8B E0 FD"; + byte[] payload = Hex.decode(helloMessageRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + HelloMessage helloMessage = new HelloMessage(rlpList); + helloMessage.parseRLP(); + 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( + "D8833B83560E0B12170E9169DC43784223A59842DE2359E6D03DB34C30A966C2DE3B4B2552FB0D7595A185D558F2E669B595674F5217C996EE148884828BE0FD", + Utils.toHexString(helloMessage.getPeerId()).toUpperCase() ); + } + + @Test /* HelloMessage 2 */ + public void test_2(){ + + String helloMessageRaw = "F87F800B80B5457468657265756D282B2B292F76302E342E332F4554485F4255494C445F545950452F4554485F4255494C445F504C4154464F524D0782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1"; + byte[] payload = Hex.decode(helloMessageRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + HelloMessage helloMessage = new HelloMessage(rlpList); + 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( + "E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1", + Utils.toHexString(helloMessage.getPeerId()).toUpperCase() ); + } + + + /* DISCONNECT_MESSAGE */ + + @Test /* DisconnectMessage 1 */ + public void test_3(){ + + String disconnectMessageRaw = "C20100"; + byte[] payload = Hex.decode(disconnectMessageRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + DisconnectMessage disconnectMessage = new DisconnectMessage(rlpList); + System.out.println(disconnectMessage); + + Assert.assertEquals(disconnectMessage.getReason(), + DisconnectMessage.REASON_DISCONNECT_REQUESTED); + } + + @Test /* DisconnectMessage 2 */ + public void test_4(){ + + String disconnectMessageRaw = "C20101"; + byte[] payload = Hex.decode(disconnectMessageRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + DisconnectMessage disconnectMessage = new DisconnectMessage(rlpList); + System.out.println(disconnectMessage); + + Assert.assertEquals(disconnectMessage.getReason(), + DisconnectMessage.REASON_TCP_ERROR); + } + + + /* PEERS */ + + @Test /* PeersMessage 1*/ + public void test_5(){ + + String peersMessageRaw = "F902BC11F84CC65381AC81E24F82765FB84033F506917503D16ECA1574F73D427BB6BC8725BED28542151E966C71FF5E9EE2EB0B09A8A6D7F6BC9E3F58F407F3DEDF174C4B6D6426973FB874E18F9ACB2BB6F84DC781C87681AB81BE82765FB840370A33EE6716C22E8AB13FF666C2389BDF0947F2FD8C15F3ABA5D545A0B78F7A8ABB95FD575073BE596D237038149A3B71E3A8F30B55AE70ED0189803FD62F24F84CC66A81A80E81F982765FB84052C1D33B5635C25504AD3985A79BEE3FF26CA5A17D351B8775E7ACEBAB1365624C9EE3CDFF843AFD07B235D8569196C781115E8DCAEF93E0383B20CFA64766D0F84AC455417E2D82765FB84082A8A5831D3B4FB76CF130CDC8A2B162A85D005D82A1DCC9B73239035EADE6347EDE2FFC86571ABE348EA38699CE886AA3D425FE58182C433434AB4CFD7B5B88F84CC6443081AD81A3827A51B840A5FD77C0D432FBFA3317084914C2E8A8821E4BA1DCBA44961FF7480E6DB608789CAB6291416360EA8CDC26B0D2F0877C50E89A70C1BCF5D6DD8B182E0A9E37D3F84AC436481F3782765FB840CE73660A06626C1B3FDA7B18EF7BA3CE17B6BF604F9541D3C6C654B7AE88B239407F659C78F419025D785727ED017B6ADD21952D7E12007373E321DBC31824BAF84AC455417E2D82765FB840CE73F1F1F1F16C1B3FDA7B18EF7BA3CE17B6F1F1F1F141D3C6C654B7AE88B239407FF1F1F1F119025D785727ED017B6ADD21F1F1F1F1000001E321DBC31824BAF84CC66B81AA3981F782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1F84EC881BF81B181D1819F82765FB840EFDFAE4BC66C2FBAAA70FEC4E764552256D3E15B143FA8F9EF278A5E042221BA0D4E8688DD4BA9582ABAC97D81B9418E50391204E9335E8E37CD16B7D95193A7"; + byte[] payload = Hex.decode(peersMessageRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + PeersMessage peersMessage= new PeersMessage(rlpList); + System.out.println(peersMessage); + + Assert.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", + Utils.toHexString( peerData.getPeerId() ).toUpperCase()); + + } + + @Test /* PeersMessage 2 */ + public void test_6(){ + + String peersMessageRaw = "F9175011F84CC681836881FC0482765FB840077E537A8B3673E8F1B625DBCC902EA7D4CED9402E4664E873679512CC2360698E53425652A04624FCF78CDBA1A3233087A919A34D11AEDACEEEB7D833FCBF26F84CC66381E75881AF82765FB8400AB2CDE83A098403DDC2EA5414740D8A0193E449C96E112419967ABC62EB17CDCED77AE0AB075E04F7DDDCD43FB9048BE53206A040620BDE26CB743FA312319FF84BC545818F165582765FB84015D678DBB6C9F241133DD2F5EAC96B1B8308C556037D83F63A3729DDE4C3F84ED8491C7C645827DC54CE32AB8A759EE04EA079F2703F352BBA24ED6249B47CA5F84EC881BF81B181D1819F82765FB84019549FBE60B8A8D8188C9F1741325C92A5CE2226F23B40053FB68D90ED4DD551C891952ABDB9A894713EE9A7B037D06822F8EBC68F53326D9559BFE8277BE4E9F84DC781CF81DB45819A82765FB84019C33DA7031CFF177EFA842FAA3D31BD83E1764EC610F236944A9F8A21C1C51A04F47F6B5FC3EFE65CAF369443635AFC58D8F5D4E2F12AF9EEEC3C6E30BF0A2BF84CC6443081AD81A382765FB8401E59C282081294808497AE7A7E976798C42B8BCCE13C9D8B0ECF8AFECDB5DFD4EFA8770FC0D1F7DE63C91640E7E8B4358C9E3ED0F3D6C98620AD7EA42418C9ECF84BC51F12819E4882765FB8401F68C075C1D87BC04765430FDFB1E5D00F1B784ED6BE721E4CAFF7BEB57B4B217B95DA19B5EC66045868B39AAC2E0876CF80F0B68D0FA20BDB9036BEAA7061EAF84CC681BF81EA393782765FB84021780C55B47DB4B11467B5F55B0B555E0887CE36FBD975E224B1C70EAC7AB8E8C2DB37F0A48B90FFDD5A379ADA99B6A0F6429C4A53C25558191A682636AEF4F2F84CC6443081AD81A382765FB8402315CB7CF49B8EAB212C5A45790B50797739738F5F733439B190119737EE8C09BC723794712AA82F2670BC581AB0757EF23137AC0FDF0F8C8965E7DD6BA79F8CF84AC455417E2D82765FB8402A38EA5D9A7EFD7FFFC0A81D8EA7ED28311C4012BBAB1407C8DAD2685129E042172734A328E8907F9054B8225FE77041D8A486A97976D2837242AB6C8C5905E4F84CC681836881FC0482765FB840324DD936384D8C0DDEFDE04BA7402998ABBD63D79C0BF8586B3DD2C7DBF6C91EB80A7B6DE8F16A50044F149C7B39AAFB9C3AD7F2CAA40355AAB09888186FCCA2F84CC65381AC81E24F82765FB84033F506917503D16ECA1574F73D427BB6BC8725BED28542151E966C71FF5E9EE2EB0B09A8A6D7F6BC9E3F58F407F3DEDF174C4B6D6426973FB874E18F9ACB2BB6F84DC781C87681AB81BE82765FB840370A33EE6716C22E8AB13FF666C2389BDF0947F2FD8C15F3ABA5D545A0B78F7A8ABB95FD575073BE596D237038149A3B71E3A8F30B55AE70ED0189803FD62F24F84CC6443081AD81A382765FB840394245C0991633ED060BAFB9646853D344188B804FE37E25A5BCAC44ED443A84A68B3AAF155EFE4861E84B4B515F9A5DECDBD7DAE98192D7A320A792C7D4DFAFF84DC75681B781E781CD82765FB840398650F67B2292939DE34C0EAEB9141F9484A0FB173FA33F81A1F7315D0EB77BDE3A76C38636FAE66FA14BF2AFDFD63E60ABD40E29B02A914E65DE5789983FD4F84CC64481B981EA4082765FB8403A15587A1C3ADABF0291B307F71B2C04D198AAE36B834995D3305DFF42F1AB86F483AE129E9203FBC6EF2187C8621EDD18F61D53EAA5B587FFDEA4D926489038F84DC781CF81DB45819A82765FB8403B1462040EA778E3F75E65CE2453418A662E6212C9F65B02EAB58D22B287E45053BDE5EBF060960CBFA0D9DC85BF51BA7AA1F2CAA2C13682D93277641D60DBEBF84CC66A81A80E81F982765FB8403ECC97AB15D22F7B9EDF19C04CE3B6095FA2504214002B35989C6F81EE4B961CC2A899C49415C914E313908340047D1D3B25D74F5B9C85A06AFA2659A539992EF84BC52E0481C10982765FB840407C22003F3BBAA6CBEB8E4B0AB7073073FEAB85182B405525F8BD283255043D713518F74748D92C43FBB99ECC7C3FBAB95D598006513AA8E59C48041C8B41C2F84BC5327E5681C282765FB840408C9324203BD8262FCE6506BA59DCDD567089B0EB9A5BB183477BABBF6163914ACDC7F495F8964D8AC12FE2401887B8CD8D97C0C9DCCFADDBB20A3C3147A789F84AC4266C4F6882765FB840423E4004DA2FA7500BC012C0674AA6571502C53AA4D91EFA6E2B5CB1E468C462CA3114A2E2EB0965B7044F9C9575965B47E47A41F13F1ADC03A2A4B342D7128DF84BC54081E7082D82765FB84042839375272C2F3DEADB28085D06055E353135C6C8D896097A1BC480C4884FD1604518CBDF731AC18F0984B7F02148E88290D13C224D82464314E2B5962E3F89F84BC581CB22640282765FB84043BFC2EBC291825D9EC00C636330235DCEDF3A623F4F08E49BCC1504D8E9B165F0A0FE976C1881455BB3051C7B604F64AC45C117C275C636F1A36ABFB11544FBF84DC73281AA81D881C882765FB84044CF19446CA465018E4DE6C60FC0DF529EBA250292EF7441E1DB59841C69F022F6092810C9A5A7F274F2F97C4BD6C76EADC064C7D6597CAEB17ED87CB257735FF84BC532819C5A5382765FB840461C9B54E91953C5BBC31C6712A917382BE67D60F75EB7F50651BEA3E594D0D19C2229D8F66ADB3F203F600038E7CC934DC92787FAC4392B9BFA7CBC786FD05BF84BC58186647D2982765FB84048353A0058E26448D94E59336CCA9D28A9374120DEF76C4BCCFEE18B0123E59192393A2EE3044D80E0EECBB09476BE62FDE1E874F93D05EA5C4A9A45C06E8FE1F84BC54E080581BB82765FB84048E8950949D4C00BCDBBE939C5BF078F2CBFF10884AF1660B1C322B9CAA3BA357BB4157FC6B0039AF9438DFE51EC278A47FCD3B726FA0A087D4C3C01A62F335EF84AC6584581C681C607B8404A0255FA4673FAA30FC5ABFD3C550BFDBC0D3C973D35F726463AF81C54A03281CFFF22C5F5965B38AC630152987757A31782478549C36F7C84CB4436BA79D6D9F84BC54081E7082D82765FB8404C7547AB4D541E10164CD3741F3476ED194B0AB9A136DFCAC3943F97358C9B0514142736CA2F170F125229057B473244A6230BF5471AD168188524B2B5CD8B7BF84CC6443081AD81A382765FB8404D5E4875D60EB4EEAFB6B2A7D3936ED3C9BC58ACAADE6A7F3C5F25598C20B364F12BEA2FB1DB3B2C2EF64785A47D6B6B5B103427CBAC0C88B18FE92A9F5393F8F84BC5520C81E35482765FB8404FD898627574D3E86B3F5A65C3EDC2E5DA84535926E4A28820B0038B19636E07DB5EB004D791F8041A006E33E108E4EC535499D128D8D9C5CAF6BBDC2204F76AF84CC66A81A80E81F982765FB84052C1D33B5635C25504AD3985A79BEE3FF26CA5A17D351B8775E7ACEBAB1365624C9EE3CDFF843AFD07B235D8569196C781115E8DCAEF93E0383B20CFA64766D0F84BC581B4202B0882765FB84053CCF25AB59409ECBB903D2EC3A9AA2EB39D7CC4C7DB7E6F68FD711A7CEBC606216DE737826DA42093E3E6521EE4770EB2D669DC4BF3546CC757C34012696EAEF84AC44C67374782765FB840600A77FB14E792C0C70DC4ADE382ED604362B978B19B94C4ED188338A1795D2DB45F7F223B66BAEBA391C59B5588B44EBAF71C7EB39755C27229C7FDE641BECEF84BC545818F165582765FB840634C1D314F4D0AE98A0A57D406091FC055E023F8A02800E93273BA34928D063877B7D5E7301ACBBEDA7BD4A7DFA3C3DBC840BB443E8863A6C514B82F2273A2DDF84BC56D2B819A4282765FB84069DD445F67C3BEF394F9549FDAE1623DBC20884A62FD5616DDBB49F84BA87E147CB8A50BA971D730C4621D0EB65133494E94FA5EA2E69C661F6B12E7ED2A8D4EF84BC518093D819B82765FB8406B5D4C35FFD1F5A198038A90834D29A1B88BE0D5EFCA08BC8A2D5881180B0B416BE00629AABE450A50828B8D1EE82D98F5528187EE67ED6E073BCEEFCDFB2BC9F84AC455417E2D82765FB8406CBB1ED536DC3858C1F063429BD3952A5D32EF8E11526CDFE72F41FEA1ACE960187C9975ABBC23783511C00F2698354747F905AAAC11DCD2B7478B3EAF327AC6F84BC54081E7082D82765FB8406EA28F64EA1CC3B6572544FD5BF743B0EAABE017F514730C897DA3C77F03C516F1E5F31D793B4BCE3CAA1DED56356D20B2EBB55A7066F41C25B7C3D56614E06BF84AC455417E2D82765FB84072532408E8BE6D5E2C9F650FB9C9F99650CC1FA062A4A4F2CFE4E6AE69CDD2E8B23ED14AFE66955C23FA048F3A976E3CE8169E505B6A89CC53D4FAC20C2A11BFF84DC77481FB81DD81FB82765FB84077B92DC86BC2599EEF46CAF2E84338165AE58971256A92CF0B802B6B510D9F690D1C0DA48A74C1A7C5FFFF46A267F5E3AB501D6F5E81E32EFCBB4EA4EC103CF3F84CC65281D94881A982765FB8407AEEA43360B9368B30E7F48286613FD1E3B0207FB71F0308D50412114463E77AB83027C0D40CADAAB8BBF612FC5B6967FA1C407329D47EC61FB0DC3DA1086832F84CC681A68193534F82765FB8407B3CDDE058D5B45D8DB2243660CFEA02E074EC213114C251D7C0C32D0403BB7AB47713D2492FF6C881CFC2AAC3F52CB269768C8968F3B6B18BAC9722D05331F6F84CC681B43881A23C82765FB840817219171552FE8DCF019EDDB90187FB0DE6A471456809698AB5251E6F498D8DF15C34CF1D86F4320689E458483657F04FA651407AFDBB2B2A91D5FBFCAD4FD6F84AC455417E2D82765FB84082A8A5831D3B4FB76CF130CDC8A2B162A85D005D82A1DCC9B73239035EADE6347EDE2FFC86571ABE348EA38699CE886AA3D425FE58182C433434AB4CFD7B5B88F84CC66A81A80E81F982765FB84087AB581BB97C212A2DA7EF0D6E105E41B55E4E42CBB6A1AF9A761A01CA8C65069AB4B5827E322CF2C5F59E7F592BE2A817C45AB641F5A9DD368963C73F9EE688F84CC65281D94881A982765FB8408C660DBC6D3DB0186AD10F05FD4F2F0643778EC514E8452A7550C630DA21171A29B1BB67C2E8E101EA1DB39743F3E78C4D2676A13D15515121515FC38B048F37F84CC66381E75881AF82765FB84094FE3D52A2894CEDC6B15424156EB8738A8441DD74BA9CED6664ED30A332A95B574D89262EA367FA900AE9706FB81A408287BDDEF3A9DD9FF44E3A41BC090FDCF84CC64D81B781903782765FB840951FAFCB6F521F0AA23BC58AF19CC40D6795124D89DC8E0CAF23369B67726A1BF6A7B4EF59CD983059B6A67C15F409903C96577CEDDACD89C7423A103C134E08F84DC781D5818181E60A82765FB840952114F110E8AC00DFEA5F050D955E764C7CBA8FB207C05A7AA5AE849168640A2B4E314391FC3A76795B3827055462639CFF4AE2D64AB80E95274428313E366AF84CC6584581C681C682765FB84096F347B096ED1630F474B97623E45E8D471B1D43C22F599607C8B2E3ED0D7B7905D8554AD399DBD739C76126404424D8DB0DC7D2B047C1A328AE27D40906C583F84CC681836881FC0482765FB8409A22C8FB1BD8BBD02F0E74ED9D3D55B0F5B09672BC43A2D47B1ED04238C1C32B6A657426525B15518236E9789B546A4A072A605E1373FE5B996BAEDC30359428F84BC5520C81E35482765FB8409B1A3A8D771B3D949CA394A88EB5DC29A953B02C81F017361FFC0AFE09ABCE3069171A87D474523687FCC9A9D32CC02CFAB4132256FEAABFE05F7AC747194E88F84BC54281D7781C82765FB8409FA7E55B2D98F1D744C76232E4FDA242FE9FD3D5743D16D3CAD2E548A07CB5AF06FE60EBAEB8C6095028179234DCDDD3CDCF1FCFE6EDAA2A53307FD103DA4AF0F84AC455417E2D82765FB840A01F834E9D1A613C3C747E561CAC19CB12D879C1A57420A49C23652B8F51288C8B111AA3888998B05E327F47A235C6A4A377F888E3005A2D4B03ECB7268608D3F84CC6443081AD81A3827A51B840A5FD77C0D432FBFA3317084914C2E8A8821E4BA1DCBA44961FF7480E6DB608789CAB6291416360EA8CDC26B0D2F0877C50E89A70C1BCF5D6DD8B182E0A9E37D3F84DC7818881A081983182765FB840AE31BD0254EE7D10B80FC90E74BA06BA761187DF3138A9799DE5828D0163524C44BAC7D2A9B5C41BE5BE8289A172361F0BA90410C94F579BF7EBD28F18AAA1CDF84AC455417E2D82765FB840BA3D216772CDC74558D2545624A2D62DCBCFD272305730C74643C7A7E819AFA6CDD82223E2B5501EB6D4EAE5DBF21E558C768ACAEC2C1CA10E74C4C87A574B53F84AC455417E2D82765FB840BDB49C01872D91BD1EA990BD2EDF16C48171A6067F9A6F7F48BFB194630B5AE9031B5DC263F59C66ADA444CB4E6F9DF62B3017CE612CAB7B53DA08D356F78D30F84CC66381E75881AF82765FB840C12BA91F95044D78EED1D3A9535EBD6471524418135EEB46AD5D5C6ECC2F5168B4AB3A062BB0742AEA65FFEA767FAB8DCC21783CB29BF32E2CD6222209FA71FDF84CC6443081AD81A3827A51B840C2E269E64AA8C9BE2D41812A48AFA2346BD41A1AB2E4646241AE3B8D0CCD41F2D682B15A025F759C0D955A6071D4E8EA7D4DE397D6E052230920113B6EB74C09F84AC44A4F177782765FB840C303B83F6A161F996736344480AE9D88FDC1D9C675BFACA888F70F24897265628209DA53741E03C0F65921F68F602DC9F334A3C45BCB92AF8544A6FB119BD887F84BC50C81FA611A82765FB840C76E7C157B7735511153D1F95081A144E088A989171F3D432CC5D8293ECE9CFAA483C032155D7B53656A6E33A3D75CD0624E09A2F949C156093DBAA83F1111F2F84BC5520C81E35482765FB840C7D5A3691A59599DE333489CBF8A47A7433E92C72706E13D94ED211296D35C97D8357D7E07B3858564D7268ED7AA097F37589C27770F90DD0B07635BE3F53364F84CC64E09819281B282765FB840C88197A82B0ACF0A872494D1DFAC9DE846DAA7DE08B240647A96BA72FBE08FD52B55C6C94514A47EC51BA49A975489EBC9383B48F5E240939068CE5836FF24F1F84BC581B4202B0882765FB840C9E039D8A8B9E435BEF2F45FC7CB7E788716E8C7AFC1BACC64E1246D2AB506D36073792AE696E41AD6BA0C8ABD2EC0D545B0757F94A9F3538280E56DB5F5D8ECF84BC54E6881A35182765FB840CA27683702A8E9BF3201656FF84A60D5B1DD814273993CF1A025B054454E40D53092F48518EE05BEAD4F18021F4F540C0B7C7D26EBA50EA4890B9E5E49A76C5FF84AC436481F3782765FB840CE73660A06626C1B3FDA7B18EF7BA3CE17B6BF604F9541D3C6C654B7AE88B239407F659C78F419025D785727ED017B6ADD21952D7E12007373E321DBC31824BAF84AC455417E2D82765FB840CE73F1F1F1F16C1B3FDA7B18EF7BA3CE17B6F1F1F1F141D3C6C654B7AE88B239407FF1F1F1F119025D785727ED017B6ADD21F1F1F1F1000001E321DBC31824BAF84BC549310781F382765FB840D553D2596461568CC7365D53F92F387FD39F10C4A9AC388EBFA1F59761F2DF215669B1C4A255DCC33E271573A01CBD1E12F0DF40C3DDC609C59F3E9A6E346EE1F84CC66B81AA3981F782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1F84CC64081E70A81D082765FB840E31115A76FA7FB2EFD3CFAF46AD00B05FC3498E1BAF1785DFFE6CA69913D256531D180564235FD3D3C10409CD11FC259CF7CFDA9B6BB253340412D82878F3BD3F84BC5415E31819782765FB840E5E8D8C2D762D21CA1E9BCEE8ADC53600F2D894097542666D6B5F41B23584B07F60901AB409DDF91E0CD2562DAFFF2CB0F221EB9F1156F781A5D9931A02A2E07F84CC65D818681C24982765FB840ECF3D13E7843E1B2537B742FA689912F7CFFB5D75E2CDD6732AAD1A3088F06066B435C0FA6D95C82A948AE0A1A0067D11A15668F70974299FD0F52CCD87D67DDF84EC881BF81B181D1819F82765FB840EFDFAE4BC66C2FBAAA70FEC4E764552256D3E15B143FA8F9EF278A5E042221BA0D4E8688DD4BA9582ABAC97D81B9418E50391204E9335E8E37CD16B7D95193A7F84BC5567C5281FE82765FB840F6155F1A60143B7D9D5D1A440D7D52FE6809F69E0C6F1E0024457E0D71DD88ADE3B13AAA940C89AC0610952B48BD832C42E343A13E61FFDB06010CFFC345E053F84CC66381E75881AF82765FB840FA568561B7D5288DF7A506C9BC1C9512AB396E68C46F0E62C21DC1AA584B844A8A7E944F6971303665FD37B138D9A5F637E672EDB98969664C4E7FD1C4126DEF"; + byte[] payload = Hex.decode(peersMessageRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + PeersMessage peersMessage= new PeersMessage(rlpList); + System.out.println(peersMessage); + + Assert.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", + 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", + Utils.toHexString( peerData.getPeerId() ).toUpperCase()); + + } + + + @Test /* Peers msg parsing performance*/ + public void test_7() throws UnknownHostException { + + long time1 = System.currentTimeMillis(); + for (int i = 0; i < 20000; ++i){ + + String peersPacketRaw = "F9152E11F84CC681836881FC0482765FB840077E537A8B3673E8F1B625DBCC902EA7D4CED9402E4664E873679512CC2360698E53425652A04624FCF78CDBA1A3233087A919A34D11AEDACEEEB7D833FCBF26F84CC66381E75881AF82765FB8400AB2CDE83A098403DDC2EA5414740D8A0193E449C96E112419967ABC62EB17CDCED77AE0AB075E04F7DDDCD43FB9048BE53206A040620BDE26CB743FA312319FF84BC545818F165582765FB84015D678DBB6C9F241133DD2F5EAC96B1B8308C556037D83F63A3729DDE4C3F84ED8491C7C645827DC54CE32AB8A759EE04EA079F2703F352BBA24ED6249B47CA5F84DC781CF81DB45819A82765FB84019C33DA7031CFF177EFA842FAA3D31BD83E1764EC610F236944A9F8A21C1C51A04F47F6B5FC3EFE65CAF369443635AFC58D8F5D4E2F12AF9EEEC3C6E30BF0A2BF84CC6443081AD81A382765FB8401E59C282081294808497AE7A7E976798C42B8BCCE13C9D8B0ECF8AFECDB5DFD4EFA8770FC0D1F7DE63C91640E7E8B4358C9E3ED0F3D6C98620AD7EA42418C9ECF84BC51F12819E4882765FB8401F68C075C1D87BC04765430FDFB1E5D00F1B784ED6BE721E4CAFF7BEB57B4B217B95DA19B5EC66045868B39AAC2E0876CF80F0B68D0FA20BDB9036BEAA7061EAF84CC681BF81EA393782765FB84021780C55B47DB4B11467B5F55B0B555E0887CE36FBD975E224B1C70EAC7AB8E8C2DB37F0A48B90FFDD5A379ADA99B6A0F6429C4A53C25558191A682636AEF4F2F84CC6443081AD81A382765FB8402315CB7CF49B8EAB212C5A45790B50797739738F5F733439B190119737EE8C09BC723794712AA82F2670BC581AB0757EF23137AC0FDF0F8C8965E7DD6BA79F8CF84EC881BF81B181D1819F82765FB840249A3641E5A8D08E41A5CFC8DAE11F1761254F4FD47D9B13338DB8E6E3729E6F2AC9EC097A5C809684D62A41E6DFC2FFF72DC3DBD97EA26132BB97640565BB0CF84AC455417E2D82765FB8402A38EA5D9A7EFD7FFFC0A81D8EA7ED28311C4012BBAB1407C8DAD2685129E042172734A328E8907F9054B8225FE77041D8A486A97976D2837242AB6C8C5905E4F84CC66A81A80E81F982765FB8402CB30D5314ECE47E5B43DBD27A12CAD9A55CF57DD6EFB467151FEE95B9217B8BE2AB6214E07EFD9535660AE9C4FB932D2947ED6EDCD54F11081BA0FF7F30CE42F84CC681836881FC0482765FB840324DD936384D8C0DDEFDE04BA7402998ABBD63D79C0BF8586B3DD2C7DBF6C91EB80A7B6DE8F16A50044F149C7B39AAFB9C3AD7F2CAA40355AAB09888186FCCA2F84CC6443081AD81A382765FB840394245C0991633ED060BAFB9646853D344188B804FE37E25A5BCAC44ED443A84A68B3AAF155EFE4861E84B4B515F9A5DECDBD7DAE98192D7A320A792C7D4DFAFF84DC75681B781E781CD82765FB840398650F67B2292939DE34C0EAEB9141F9484A0FB173FA33F81A1F7315D0EB77BDE3A76C38636FAE66FA14BF2AFDFD63E60ABD40E29B02A914E65DE5789983FD4F84CC64481B981EA4082765FB8403A15587A1C3ADABF0291B307F71B2C04D198AAE36B834995D3305DFF42F1AB86F483AE129E9203FBC6EF2187C8621EDD18F61D53EAA5B587FFDEA4D926489038F84DC781CF81DB45819A82765FB8403B1462040EA778E3F75E65CE2453418A662E6212C9F65B02EAB58D22B287E45053BDE5EBF060960CBFA0D9DC85BF51BA7AA1F2CAA2C13682D93277641D60DBEBF84CC66A81A80E81F982765FB8403ECC97AB15D22F7B9EDF19C04CE3B6095FA2504214002B35989C6F81EE4B961CC2A899C49415C914E313908340047D1D3B25D74F5B9C85A06AFA2659A539992EF84BC52E0481C10982765FB840407C22003F3BBAA6CBEB8E4B0AB7073073FEAB85182B405525F8BD283255043D713518F74748D92C43FBB99ECC7C3FBAB95D598006513AA8E59C48041C8B41C2F84BC5327E5681C282765FB840408C9324203BD8262FCE6506BA59DCDD567089B0EB9A5BB183477BABBF6163914ACDC7F495F8964D8AC12FE2401887B8CD8D97C0C9DCCFADDBB20A3C3147A789F84AC4266C4F6882765FB840423E4004DA2FA7500BC012C0674AA6571502C53AA4D91EFA6E2B5CB1E468C462CA3114A2E2EB0965B7044F9C9575965B47E47A41F13F1ADC03A2A4B342D7128DF84BC54081E7082D82765FB84042839375272C2F3DEADB28085D06055E353135C6C8D896097A1BC480C4884FD1604518CBDF731AC18F0984B7F02148E88290D13C224D82464314E2B5962E3F89F84DC73281AA81D881C882765FB84044CF19446CA465018E4DE6C60FC0DF529EBA250292EF7441E1DB59841C69F022F6092810C9A5A7F274F2F97C4BD6C76EADC064C7D6597CAEB17ED87CB257735FF84BC532819C5A5382765FB840461C9B54E91953C5BBC31C6712A917382BE67D60F75EB7F50651BEA3E594D0D19C2229D8F66ADB3F203F600038E7CC934DC92787FAC4392B9BFA7CBC786FD05BF84BC58186647D2982765FB84048353A0058E26448D94E59336CCA9D28A9374120DEF76C4BCCFEE18B0123E59192393A2EE3044D80E0EECBB09476BE62FDE1E874F93D05EA5C4A9A45C06E8FE1F84BC54E080581BB82765FB84048E8950949D4C00BCDBBE939C5BF078F2CBFF10884AF1660B1C322B9CAA3BA357BB4157FC6B0039AF9438DFE51EC278A47FCD3B726FA0A087D4C3C01A62F335EF84AC6584581C681C607B8404A0255FA4673FAA30FC5ABFD3C550BFDBC0D3C973D35F726463AF81C54A03281CFFF22C5F5965B38AC630152987757A31782478549C36F7C84CB4436BA79D6D9F84BC54081E7082D82765FB8404C7547AB4D541E10164CD3741F3476ED194B0AB9A136DFCAC3943F97358C9B0514142736CA2F170F125229057B473244A6230BF5471AD168188524B2B5CD8B7BF84CC6443081AD81A382765FB8404D5E4875D60EB4EEAFB6B2A7D3936ED3C9BC58ACAADE6A7F3C5F25598C20B364F12BEA2FB1DB3B2C2EF64785A47D6B6B5B103427CBAC0C88B18FE92A9F5393F8F84BC5520C81E35482765FB8404FD898627574D3E86B3F5A65C3EDC2E5DA84535926E4A28820B0038B19636E07DB5EB004D791F8041A006E33E108E4EC535499D128D8D9C5CAF6BBDC2204F76AF84BC581B4202B0882765FB84053CCF25AB59409ECBB903D2EC3A9AA2EB39D7CC4C7DB7E6F68FD711A7CEBC606216DE737826DA42093E3E6521EE4770EB2D669DC4BF3546CC757C34012696EAEF84AC44C67374782765FB840600A77FB14E792C0C70DC4ADE382ED604362B978B19B94C4ED188338A1795D2DB45F7F223B66BAEBA391C59B5588B44EBAF71C7EB39755C27229C7FDE641BECEF84BC56D2B819A4282765FB84069DD445F67C3BEF394F9549FDAE1623DBC20884A62FD5616DDBB49F84BA87E147CB8A50BA971D730C4621D0EB65133494E94FA5EA2E69C661F6B12E7ED2A8D4EF84BC518093D819B82765FB8406B5D4C35FFD1F5A198038A90834D29A1B88BE0D5EFCA08BC8A2D5881180B0B416BE00629AABE450A50828B8D1EE82D98F5528187EE67ED6E073BCEEFCDFB2BC9F84AC455417E2D82765FB8406CBB1ED536DC3858C1F063429BD3952A5D32EF8E11526CDFE72F41FEA1ACE960187C9975ABBC23783511C00F2698354747F905AAAC11DCD2B7478B3EAF327AC6F84BC54081E7082D82765FB8406EA28F64EA1CC3B6572544FD5BF743B0EAABE017F514730C897DA3C77F03C516F1E5F31D793B4BCE3CAA1DED56356D20B2EBB55A7066F41C25B7C3D56614E06BF84AC455417E2D82765FB84072532408E8BE6D5E2C9F650FB9C9F99650CC1FA062A4A4F2CFE4E6AE69CDD2E8B23ED14AFE66955C23FA048F3A976E3CE8169E505B6A89CC53D4FAC20C2A11BFF84CC65281D94881A982765FB8407AEEA43360B9368B30E7F48286613FD1E3B0207FB71F0308D50412114463E77AB83027C0D40CADAAB8BBF612FC5B6967FA1C407329D47EC61FB0DC3DA1086832F84CC681A68193534F82765FB8407B3CDDE058D5B45D8DB2243660CFEA02E074EC213114C251D7C0C32D0403BB7AB47713D2492FF6C881CFC2AAC3F52CB269768C8968F3B6B18BAC9722D05331F6F84CC66A81A80E81F982765FB84087AB581BB97C212A2DA7EF0D6E105E41B55E4E42CBB6A1AF9A761A01CA8C65069AB4B5827E322CF2C5F59E7F592BE2A817C45AB641F5A9DD368963C73F9EE688F84CC65281D94881A982765FB8408C660DBC6D3DB0186AD10F05FD4F2F0643778EC514E8452A7550C630DA21171A29B1BB67C2E8E101EA1DB39743F3E78C4D2676A13D15515121515FC38B048F37F84CC66381E75881AF82765FB84094FE3D52A2894CEDC6B15424156EB8738A8441DD74BA9CED6664ED30A332A95B574D89262EA367FA900AE9706FB81A408287BDDEF3A9DD9FF44E3A41BC090FDCF84CC64D81B781903782765FB840951FAFCB6F521F0AA23BC58AF19CC40D6795124D89DC8E0CAF23369B67726A1BF6A7B4EF59CD983059B6A67C15F409903C96577CEDDACD89C7423A103C134E08F84DC781D5818181E60A82765FB840952114F110E8AC00DFEA5F050D955E764C7CBA8FB207C05A7AA5AE849168640A2B4E314391FC3A76795B3827055462639CFF4AE2D64AB80E95274428313E366AF84CC6584581C681C682765FB84096F347B096ED1630F474B97623E45E8D471B1D43C22F599607C8B2E3ED0D7B7905D8554AD399DBD739C76126404424D8DB0DC7D2B047C1A328AE27D40906C583F84CC681836881FC0482765FB8409A22C8FB1BD8BBD02F0E74ED9D3D55B0F5B09672BC43A2D47B1ED04238C1C32B6A657426525B15518236E9789B546A4A072A605E1373FE5B996BAEDC30359428F84BC5520C81E35482765FB8409B1A3A8D771B3D949CA394A88EB5DC29A953B02C81F017361FFC0AFE09ABCE3069171A87D474523687FCC9A9D32CC02CFAB4132256FEAABFE05F7AC747194E88F84BC54281D7781C82765FB8409FA7E55B2D98F1D744C76232E4FDA242FE9FD3D5743D16D3CAD2E548A07CB5AF06FE60EBAEB8C6095028179234DCDDD3CDCF1FCFE6EDAA2A53307FD103DA4AF0F84AC455417E2D82765FB840A01F834E9D1A613C3C747E561CAC19CB12D879C1A57420A49C23652B8F51288C8B111AA3888998B05E327F47A235C6A4A377F888E3005A2D4B03ECB7268608D3F84CC6443081AD81A3827A51B840A5FD77C0D432FBFA3317084914C2E8A8821E4BA1DCBA44961FF7480E6DB608789CAB6291416360EA8CDC26B0D2F0877C50E89A70C1BCF5D6DD8B182E0A9E37D3F84DC7818881A081983182765FB840AE31BD0254EE7D10B80FC90E74BA06BA761187DF3138A9799DE5828D0163524C44BAC7D2A9B5C41BE5BE8289A172361F0BA90410C94F579BF7EBD28F18AAA1CDF84CC681D95B81FC3D82765FB840B1D3B2BB241F3297CC1003E5907DD187B9FF3147F816B068D257222629F5AB9EF2AEAF7965F366AF72A299131D23F7A1ECD4A098D7D37D6F52F3A8C0037C52E0F84AC455417E2D82765FB840BA3D216772CDC74558D2545624A2D62DCBCFD272305730C74643C7A7E819AFA6CDD82223E2B5501EB6D4EAE5DBF21E558C768ACAEC2C1CA10E74C4C87A574B53F84AC455417E2D82765FB840BDB49C01872D91BD1EA990BD2EDF16C48171A6067F9A6F7F48BFB194630B5AE9031B5DC263F59C66ADA444CB4E6F9DF62B3017CE612CAB7B53DA08D356F78D30F84CC66381E75881AF82765FB840C12BA91F95044D78EED1D3A9535EBD6471524418135EEB46AD5D5C6ECC2F5168B4AB3A062BB0742AEA65FFEA767FAB8DCC21783CB29BF32E2CD6222209FA71FDF84CC6443081AD81A3827A51B840C2E269E64AA8C9BE2D41812A48AFA2346BD41A1AB2E4646241AE3B8D0CCD41F2D682B15A025F759C0D955A6071D4E8EA7D4DE397D6E052230920113B6EB74C09F84AC44A4F177782765FB840C303B83F6A161F996736344480AE9D88FDC1D9C675BFACA888F70F24897265628209DA53741E03C0F65921F68F602DC9F334A3C45BCB92AF8544A6FB119BD887F84BC50C81FA611A82765FB840C76E7C157B7735511153D1F95081A144E088A989171F3D432CC5D8293ECE9CFAA483C032155D7B53656A6E33A3D75CD0624E09A2F949C156093DBAA83F1111F2F84BC5520C81E35482765FB840C7D5A3691A59599DE333489CBF8A47A7433E92C72706E13D94ED211296D35C97D8357D7E07B3858564D7268ED7AA097F37589C27770F90DD0B07635BE3F53364F84CC64E09819281B282765FB840C88197A82B0ACF0A872494D1DFAC9DE846DAA7DE08B240647A96BA72FBE08FD52B55C6C94514A47EC51BA49A975489EBC9383B48F5E240939068CE5836FF24F1F84BC581B4202B0882765FB840C9E039D8A8B9E435BEF2F45FC7CB7E788716E8C7AFC1BACC64E1246D2AB506D36073792AE696E41AD6BA0C8ABD2EC0D545B0757F94A9F3538280E56DB5F5D8ECF84BC54E6881A35182765FB840CA27683702A8E9BF3201656FF84A60D5B1DD814273993CF1A025B054454E40D53092F48518EE05BEAD4F18021F4F540C0B7C7D26EBA50EA4890B9E5E49A76C5FF84CC681BF81EA393782765FB840CB78D224C1F5F1319EE9FD058050D24F40234570EAA5941046C7F967D8ADD06484776EB60C3BB11ED9E3562D259B9941585FDAD2D5F236564B8253A565483F89F84BC55C4B81D24C82765FB840CD9699760740E99DB8ED79311B80AFDACD6AA937AB1816B42BD3F465814152F3D9973DF578BE4D8C77FBB19416BDE414140AF3289356512F1BFEB54DD2679A94F84AC436481F3782765FB840CE73660A06626C1B3FDA7B18EF7BA3CE17B6BF604F9541D3C6C654B7AE88B239407F659C78F419025D785727ED017B6ADD21952D7E12007373E321DBC31824BAF84AC455417E2D82765FB840CE73F1F1F1F16C1B3FDA7B18EF7BA3CE17B6F1F1F1F141D3C6C654B7AE88B239407FF1F1F1F119025D785727ED017B6ADD21F1F1F1F1000001E321DBC31824BAF84CC66B81AA3981F782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1F84CC64081E70A81D082765FB840E31115A76FA7FB2EFD3CFAF46AD00B05FC3498E1BAF1785DFFE6CA69913D256531D180564235FD3D3C10409CD11FC259CF7CFDA9B6BB253340412D82878F3BD3F84BC5415E31819782765FB840E5E8D8C2D762D21CA1E9BCEE8ADC53600F2D894097542666D6B5F41B23584B07F60901AB409DDF91E0CD2562DAFFF2CB0F221EB9F1156F781A5D9931A02A2E07F84BC5567C5281FE82765FB840F6155F1A60143B7D9D5D1A440D7D52FE6809F69E0C6F1E0024457E0D71DD88ADE3B13AAA940C89AC0610952B48BD832C42E343A13E61FFDB06010CFFC345E053F84CC66381E75881AF82765FB840FA568561B7D5288DF7A506C9BC1C9512AB396E68C46F0E62C21DC1AA584B844A8A7E944F6971303665FD37B138D9A5F637E672EDB98969664C4E7FD1C4126DEF"; + + byte[] payload = Hex.decode(peersPacketRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + PeersMessage peersMessage = new PeersMessage(rlpList); + peersMessage.parseRLP(); + } + long time2 = System.currentTimeMillis(); + + System.out.println("20,000 PEERS packets parsing: " + (time2 - time1) + "(msec)"); + } + + /* TRANSACTIONS */ + + @Test /* Transactions message 1 */ + public void test_8(){ + + String transactionsPacketRaw = "F86E12F86B04881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA05E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54A00FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467"; + + byte[] payload = Hex.decode(transactionsPacketRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList); + System.out.println(transactionsMessage); + + Assert.assertEquals(1, transactionsMessage.getTransactions().size()); + + TransactionData tx = + transactionsMessage.getTransactions().get(0); + + Assert.assertEquals("558A3797E0DD3FBFAF761F1ADD6749C7D5DB313FDAC5CBA59F40E28AF7BBACD1", + Utils.toHexString( tx.getHash() ).toUpperCase()); + + Assert.assertEquals("04", + Utils.toHexString( tx.getNonce() ).toUpperCase()); + + Assert.assertEquals("1BC16D674EC80000", + Utils.toHexString( tx.getValue() ).toUpperCase()); + + Assert.assertEquals("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826", + Utils.toHexString( tx.getReceiveAddress() ).toUpperCase()); + + Assert.assertEquals("09184E72A000", + Utils.toHexString( tx.getGasPrice() ).toUpperCase()); + + Assert.assertEquals("64", + Utils.toHexString( tx.getGas() ).toUpperCase()); + + Assert.assertEquals("NULL", + Utils.toHexString( tx.getData() ).toUpperCase()); + + Assert.assertEquals("NULL", + Utils.toHexString( tx.getInit() ).toUpperCase()); + + Assert.assertEquals("1B", + Utils.toHexString( new byte[] {tx.getSignatureV()} ).toUpperCase()); + + Assert.assertEquals("5E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54", + Utils.toHexString( tx.getSignatureR() ).toUpperCase()); + + Assert.assertEquals("0FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467", + Utils.toHexString( tx.getSignatureS() ).toUpperCase()); + + } + + + @Test /* Transactions message 2 */ + public void test_9(){ + + String transactionsPacketRaw = "F9025012F89D80809400000000000000000000000000000000000000008609184E72A000822710B3606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C5884336069571CA07F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4A06D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CCF9010501809400000000000000000000000000000000000000008609184E72A000822710B85336630000002E59606956330C0D63000000155933FF33560D63000000275960003356576000335700630000005358600035560D630000003A590033560D63000000485960003356573360003557600035335700B84A7F4E616D65526567000000000000000000000000000000000000000000000000003057307F4E616D655265670000000000000000000000000000000000000000000000000057336069571BA04AF15A0EC494AEAC5B243C8A2690833FAA74C0F73DB1F439D521C49C381513E9A05802E64939BE5A1F9D4D614038FBD5479538C48795614EF9C551477ECBDB49D2F8A6028094CCDEAC59D35627B7DE09332E819D5159E7BB72508609184E72A000822710B84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D0ACEEE7E5AB874E22CCF8D1A649F59106D74E81BA0D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9A01E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931B"; + + byte[] payload = Hex.decode(transactionsPacketRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList); + System.out.println(transactionsMessage); + + Assert.assertEquals(3, transactionsMessage.getTransactions().size()); + + TransactionData tx = + transactionsMessage.getTransactions().get(0); + + Assert.assertEquals("4B7D9670A92BF120D5B43400543B69304A14D767CF836A7F6ABFF4EDDE092895", + Utils.toHexString( tx.getHash() ).toUpperCase()); + + Assert.assertEquals("NULL", + Utils.toHexString( tx.getNonce() ).toUpperCase()); + + Assert.assertEquals("NULL", + Utils.toHexString( tx.getValue() ).toUpperCase()); + + Assert.assertEquals("0000000000000000000000000000000000000000", + Utils.toHexString( tx.getReceiveAddress() ).toUpperCase()); + + Assert.assertEquals("09184E72A000", + Utils.toHexString( tx.getGasPrice() ).toUpperCase()); + + Assert.assertEquals("2710", + Utils.toHexString( tx.getGas() ).toUpperCase()); + + Assert.assertEquals("606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C58", + Utils.toHexString( tx.getData() ).toUpperCase()); + + Assert.assertEquals("33606957", + Utils.toHexString( tx.getInit() ).toUpperCase()); + + Assert.assertEquals("1C", + Utils.toHexString( new byte[] {tx.getSignatureV()} ).toUpperCase()); + + Assert.assertEquals("7F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4", + Utils.toHexString( tx.getSignatureR() ).toUpperCase()); + + Assert.assertEquals("6D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC", + Utils.toHexString( tx.getSignatureS() ).toUpperCase()); + + + tx = + transactionsMessage.getTransactions().get(2); + + Assert.assertEquals("B0251A1BB20B44459DB5B5444AB53EDD9E12C46D0BA07FA401A797BEB967D53C", + Utils.toHexString( tx.getHash() ).toUpperCase()); + + Assert.assertEquals("02", + Utils.toHexString( tx.getNonce() ).toUpperCase()); + + Assert.assertEquals("NULL", + Utils.toHexString( tx.getValue() ).toUpperCase()); + + Assert.assertEquals("CCDEAC59D35627B7DE09332E819D5159E7BB7250", + Utils.toHexString( tx.getReceiveAddress() ).toUpperCase()); + + Assert.assertEquals("09184E72A000", + Utils.toHexString( tx.getGasPrice() ).toUpperCase()); + + Assert.assertEquals("2710", + Utils.toHexString( tx.getGas() ).toUpperCase()); + + Assert.assertEquals("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D0ACEEE7E5AB874E22CCF8D1A649F59106D74E8", + Utils.toHexString( tx.getData() ).toUpperCase()); + + Assert.assertEquals("NULL", + Utils.toHexString( tx.getInit() ).toUpperCase()); + + Assert.assertEquals("1B", + Utils.toHexString( new byte[] {tx.getSignatureV()} ).toUpperCase()); + + Assert.assertEquals("D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9", + Utils.toHexString( tx.getSignatureR() ).toUpperCase()); + + Assert.assertEquals("1E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931B", + Utils.toHexString(tx.getSignatureS()).toUpperCase()); + + } + + + /* BLOCKS */ + + @Test /* BlocksMessage parsing 1*/ + public void test_10(){ + +// BlockData [ hash=36a24b56c6104e5a5c0e70b0553f1a4d6109d065d718d7443a6a475ec8c83905 parentHash=372d8e5c6e32335fb86fa7a6ae1b35165745346e1c786eacd42df85f8da12b3d, unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347, coinbase=1a4d98707ba8dd3d36d16e8c165c272645695cea, stateHash=5e2d2cc0b42b38b5b18c9d65734f9877c035dd390b9c12c48624f2243668a268, txListHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347, difficulty=02471a26, timestamp=1398260220, extraData=null, nonce=0000000000000000000000000000000000000000000000006f4cd02da011a235] + String blocksRaw = "F8CC13F8C9F8C5A0372D8E5C6E32335FB86FA7A6AE1B35165745346E1C786EACD42DF85F8DA12B3DA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347941A4D98707BA8DD3D36D16E8C165C272645695CEAA05E2D2CC0B42B38B5B18C9D65734F9877C035DD390B9C12C48624F2243668A268A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D493478402471A26845357C1FC80A00000000000000000000000000000000000000000000000006F4CD02DA011A235C0C0"; + + byte[] payload = Hex.decode(blocksRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + BlocksMessage blocksMessage = new BlocksMessage(rlpList); + List list = blocksMessage.getBlockDataList(); + System.out.println(blocksMessage); + + Assert.assertEquals(1, list.size()); + + BlockData block = list.get(0); + + assertEquals("36A24B56C6104E5A5C0E70B0553F1A4D6109D065D718D7443A6A475EC8C83905", + Utils.toHexString(block.getHash()).toUpperCase()); + + assertEquals("372D8E5C6E32335FB86FA7A6AE1B35165745346E1C786EACD42DF85F8DA12B3D", + Utils.toHexString(block.getParentHash()).toUpperCase()); + + assertEquals("1DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347", + Utils.toHexString(block.getUnclesHash()).toUpperCase()); + + assertEquals("1A4D98707BA8DD3D36D16E8C165C272645695CEA", + Utils.toHexString(block.getCoinbase()).toUpperCase()); + + assertEquals("5E2D2CC0B42B38B5B18C9D65734F9877C035DD390B9C12C48624F2243668A268", + Utils.toHexString(block.getStateHash()).toUpperCase()); + + assertEquals("1DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347", + Utils.toHexString(block.getTxListHash()).toUpperCase()); + + assertEquals("02471A26", Utils.toHexString(block.getDifficulty()).toUpperCase()); + assertEquals(1398260220, block.getTimestamp()); + + assertNull(block.getExtraData()); + + assertEquals("0000000000000000000000000000000000000000000000006F4CD02DA011A235", + Utils.toHexString(block.getNonce()).toUpperCase()); + } + + + @Test /* BlocksMessage really big message parsing */ + public void test11(){ + + String blocksRaw = "F91C1C13F90150F8C4A07DF3D35D4DF0A56FCF1D6344D5315CB56B9BF83BB96AD17C7B96A9CD14133C5DA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A064AFB6284FA35F26D7B2C5A26AFAA5483072FBCB575221B34CE002A991B7A223A04A8ABE6D802797DC80B497584F898C2D4FD561CC185828CFA1B92F6F38EE348E833FBFE484533F201C80A000000000000000000000000000000000000000000000000000CFCCB5CFD4667CF887F8850380942D0ACEEE7E5AB874E22CCF8D1A649F59106D74E88609184E72A000822710A047617600000000000000000000000000000000000000000000000000000000001CA08691AB40E258DE3C4F55C868C0C34E780E747158A1D96CA50186DFD3305ABD78A042269C981D048A7B791AAFC8F4E644232740C1A1CCEB5B6D05568827A64C0664C0F8C8F8C4A0637C8A6CDB907FAC6F752334AB79065BCC4E46CD4F4358DBC2A653544A20EB31A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A022A36C1A1E807E6AFC22E6BB53A31111F56E7EE7DBB2EE571CEFB152B514DB4DA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FCFD784533F1CF980A0000000000000000000000000000000000000000000000000E153D743FA040B18C0C0F8C8F8C4A07B2536237CBF114A043B0F9B27C76F84AC160EA5B87B53E42C7E76148964D450A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A07A3BE0EE10ECE4B03097BF74AABAC628AA0FAE617377D30AB1B97376EE31F41AA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FBFE884533F1CE880A0000000000000000000000000000000000000000000000000F3DEEA84969B6E95C0C0F8C8F8C4A0D2AE3F5DD931926DE428D99611980E7CDD7C1B838273E43FCAD1B94DA987CFB8A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A00B5B11FCF4EE12C6812F9D01CF0DFF07C72CD7E02E48B35682F67C595407BE14A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FAFFD84533F1CE280A00000000000000000000000000000000000000000000000005FCBC97B2EB8FFB3C0C0F8C8F8C4A094D615D3CB4B306D20985028C78F0C8413D509A75E8BB84EDA95F734DEBAD2A0A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A04B8FD1B98CF5758BD303FF86393EB6D944C1058124BDDCE5D4E04B5395254D5EA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FBFEC84533F1C7680A000000000000000000000000000000000000000000000000079FE3710116B32AAC0C0F8C8F8C4A09424A07A0E4C05BB872906C40844A75B76F6517467B79C12FA9CC6D79AE09934A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A02DBE9FF9CBBC4C5A6FF26971F75B405891141F4E9BCE3C2DC4200A305138E584A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FCFDF84533F1C3B80A0000000000000000000000000000000000000000000000000E0A6F8CF1D56031BC0C0F8C8F8C4A009AABEA60CF7EAA9DF4AFDF4E1B5F3E684DAB34FC9A9180A050085A4131CEEDFA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0436DA067F9683029E717EDF92DA46C3443E8C342974F47A563302A0678EFE702A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFD684533F1BFC80A00000000000000000000000000000000000000000000000005BC88C041662FFDAC0C0F8C8F8C4A0F8B104093483B7C0182E1BBA2CE3340D14469D3A3EE7646821223A676C680AC1A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0D482E71CDE61190A33CA5AEB88B6B06276984E5A14253A98DF232E8767167221A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFD184533F1BCE80A00000000000000000000000000000000000000000000000004AEB31823F6A1950C0C0F8C8F8C4A0DD1F0ABA02C2BB3B5A2B6CB1CC907EA70912BD46DC7A78577F2CAE6CDBCBE5F3A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A058AB6DF33D7CBEB6A735A7E4CCF4F28143E6A1742E45DDA8F8CF48AF43CB66C0A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FFFD084533F1B9F80A0000000000000000000000000000000000000000000000000577042B0858B510BC0C0F8C8F8C4A0A287BB7DA30F04344976ABE569BD719F69C1CBEA65533E5311CA5862E6EAA504A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A07E0537009C23CB1152CAF84A52272431F74B6140866B15805622B7BCB607CD42A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D4934783400FD384533F1B6180A000000000000000000000000000000000000000000000000083D31378A0993E1AC0C0F8C8F8C4A063483CFF8FBD489E6CE273326D8DC1D54A31C67F936CA84BF500E5419D3E9805A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A07737D08564819D51F8F834A6EE4278C23A0C2F29A3F485B21002C1F24F04D8E4A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FFFD484533F1B5780A0000000000000000000000000000000000000000000000000BB586FE6DE016E14C0C0F8C8F8C4A0975C8ED0C9197B7C018E02E1C95F315ACF82B25E4A812140F4515E8BC827650CA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0AD51229ABEAD59E93C80DB5BA160F0939BC49DCEE65D1C081F6EB040FF1F571FA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFD984533F1B4E80A0000000000000000000000000000000000000000000000000548F02C6CEB26FD4C0C0F8C8F8C4A05844082E41F7C1F34485C7902AFA0AA0979A6A849100FC553CD946F4A663929CA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A01BC726443437C4C062BE18D052278E4EF735B8FE84387C8A4FC85FB70D5078E0A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FFFD884533F1B1080A0000000000000000000000000000000000000000000000000CC1E528F54F22BDAC0C0F8C8F8C4A0BA06BA81C93FAAF98EA2D83CBDC0788958D938B29A9EB2A92FFBD4A628B3D52EA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A05053BFE1C0F1F0DD341C6DF35E5A659989BE041E8521027CC90F7605EB15FBB9A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFDD84533F1B0380A0000000000000000000000000000000000000000000000000BCF9DF2FEC615ECAC0C0F8C8F8C4A083732D997DB15109E90464C24B7C959A78881D827C55A0D668A66A2736BE5D87A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A054F4012CBA33A2B80B0DCA9DD52F56B2C588133BD71700863F8CB95127176634A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FFFDC84533F1A4680A00000000000000000000000000000000000000000000000006920A1DC9D915D0EC0C0F8C8F8C4A052E2FBA761C2D0643170EF041C017391E781190FE715AE87CDAE8EEE1D45D95BA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0EE2C82F77D7AFD1F8DBE4F791DF8477496C23E5504B9D66814172077F65F81F2A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFE184533F1A3880A0000000000000000000000000000000000000000000000000AE86DA9012398FC4C0C0F8C8F8C4A055703BA09544F386966B6D63BFC31033B761A4D1A6BB86B0CF49B4BB0526744EA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A01684C03A675B53786F0077D1651C3D169A009B13A6EE2B5047BE6DBBE6D957FFA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFEA84533F1A2F80A00000000000000000000000000000000000000000000000003247320D0EB639DFC0C0F8C8F8C4A05109A79B33D81F4EE4814B550FB0002F03368D67570F6D4E6105FCE2874D8B72A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0AE72E8C60A3DCFD53DEECDB2790D18F0CC710F77CF2C1ED76E7DA829BDE619DCA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FCFF784533F1A1D80A000000000000000000000000000000000000000000000000040E0BC9BC9BCF295C0C0F8C8F8C4A03961E4BBBA5C95FAD3DB0CFFA3A16B9106F9EA3E8957993EAB576B683C22F416A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0E9C6CF457BBE64D6BDA67852A276CDBADB4F384A36D496E81801A496CFD9B7B5A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFEE84533F19DF80A0000000000000000000000000000000000000000000000000DBB3FD6C816776D8C0C0F8C8F8C4A06B8265A357CB3AD744E19F04EB15377F660C10C900CC352D24F9B09073A363D6A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A07BA07E1BC6A20FFA44AE6080D30982B9FAA148FAF6B1EC15E32D89AC853AC291A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFE984533F198D80A00000000000000000000000000000000000000000000000005171325B6A2F17F1C0C0F8C8F8C4A0DCDC0347BB87CE72D49AC2E4E11F89069509B129A2536BF3D57C6BCA30894032A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0CA24447AA0CEDB4B561C7810461EEF19B16A827C27352E5E01F914E9D7C78247A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FFFE884533F194680A0000000000000000000000000000000000000000000000000DA4714CFED9D8BBCC0C0F8C8F8C4A047F2DD6C15EA4082B3E11E5CF6B925B27E51D9DE68051A093E52EF465CFFBB8CA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A05A7206EDDDF50FCFEEAA97348A7112FC6EDD0B5EACB44CF43D6A6C6B6609B459A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFED84533F193E80A0000000000000000000000000000000000000000000000000FFAFBA4BF8DC944EC0C0F8C8F8C4A04D5AD6D860772145872F6660ECEFCB0B0B2056E0AA3509A48BF4C175459E5121A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A00F4659D09BB2CED56E7FD9C4D3D90DACA8B4F471307B7C4385FD34A41016B0B2A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFF684533F192580A000000000000000000000000000000000000000000000000090620E5E59A39FE5C0C0F8C8F8C4A0C1725C58D1BF023AF468E0088DB3CF642AE097CF2C58C2ECE2FC746980ACC7E6A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0BE19A182EA1584050DEB0A79ABDC11BE896CE8D00A282BCFAF9FFCD65FD64D6AA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFF184533F189080A000000000000000000000000000000000000000000000000076F17F4199BCCD12C0C0F8C8F8C4A0BD521A20A18CA6CA7115065065A1AA20067EE580FB11E2963D1E3A681E8302AFA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A011BE45633350E39475A1A07712BA72DE4602D9EEBF639CCD5422A389095CCAF1A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFFA84533F187B80A00000000000000000000000000000000000000000000000000C71B81C4A4CB82CC0C0F8C8F8C4A07C6D2D56E9C87F1553E4D06705AF61A7C19A6046D2C39F8ED1417988783D3B1DA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A012F5F0668063509E33A45A64EB6A072B2D84AA19F430F49F159BE5008A786B2EA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FD00684533F186080A0000000000000000000000000000000000000000000000000B3F962892CFEC9E6C0C0F8C8F8C4A07154F0F8ECC7F791D22EEC06EC86D87A44B2704F015B3D2CFF3571A3D01AE0F6A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A079536ABF8E163CF8AA97F0D52866D04363902D591FD7C36AA35FC983D45FEFD6A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFFD84533F182F80A0000000000000000000000000000000000000000000000000736716E42499890FC0C0F8C8F8C4A0BF2FB1EE988AC4E17EAE221A24176649774333FAB25B6FC96C6081527FB6F121A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A041578DAAE7BCCCD4976340AEB19E4132D2FE4193A0D92F87744C82BFE113502FA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FD00984533F182B80A00000000000000000000000000000000000000000000000001C62FA76645942C6C0C0F8C8F8C4A07F84873E2679D40458B9DDA9900478A78871044E08F6B47DAD659B9B60FF8D48A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0597D3F4160770C0492333F90BAD739DC05117D0E478A91F09573742E432904E8A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FE00184533F17F680A0000000000000000000000000000000000000000000000000E24D8B1140FB34D5C0C0F8C8F8C4A0FD77BD13A8CDE1766537FEBE751A27A2A31310A04638A1AFCD5E8AD3C5485453A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0473B2B248D91010BA9AEC2696FFC93C11C415ED132832BE0FD0578F184862E13A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFFC84533F17CA80A0000000000000000000000000000000000000000000000000FB5B65BAC3F0D947C0C0F8C8F8C4A0518916DFB79C390BD7BFF75712174512C2F96BEC42A3F573355507AD1588CE0CA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A08599D2EC9E95EC62F41A4975B655D8445D6767035F94EB235ED5EBEA976FB9EAA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FE00484533F17B880A0000000000000000000000000000000000000000000000000BC27F4B8A201476BC0C0F90319F8C4A0AB6B9A5613970FAA771B12D449B2E9BB925AB7A369F0A4B86B286E9D540099CFA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0990DC3B5ACBEE04124361D958FE51ACB582593613FC290683940A0769549D3EDA09BFE4817D274EA3EB8672E9FE848C3885B53BBBD1D7C26E6039F90FB96B942B0833FF00084533F16B780A000000000000000000000000000000000000000000000000077377ADFF6C227DBF9024FF89D80809400000000000000000000000000000000000000008609184E72A000822710B3606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C5884336069571CA07F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4A06D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CCF9010501809400000000000000000000000000000000000000008609184E72A000822710B85336630000002E59606956330C0D63000000155933FF33560D63000000275960003356576000335700630000005358600035560D630000003A590033560D63000000485960003356573360003557600035335700B84A7F4E616D65526567000000000000000000000000000000000000000000000000003057307F4E616D655265670000000000000000000000000000000000000000000000000057336069571BA04AF15A0EC494AEAC5B243C8A2690833FAA74C0F73DB1F439D521C49C381513E9A05802E64939BE5A1F9D4D614038FBD5479538C48795614EF9C551477ECBDB49D2F8A6028094CCDEAC59D35627B7DE09332E819D5159E7BB72508609184E72A000822710B84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D0ACEEE7E5AB874E22CCF8D1A649F59106D74E81BA0D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9A01E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931BC0"; + + byte[] payload = Hex.decode(blocksRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + BlocksMessage blocksMessage = new BlocksMessage(rlpList); + List list = blocksMessage.getBlockDataList(); + System.out.println(blocksMessage); + + + Assert.assertEquals(32, list.size()); + + BlockData block = list.get(31); + + assertEquals("518916DFB79C390BD7BFF75712174512C2F96BEC42A3F573355507AD1588CE0C", + Utils.toHexString(block.getHash()).toUpperCase()); + + assertEquals("AB6B9A5613970FAA771B12D449B2E9BB925AB7A369F0A4B86B286E9D540099CF", + Utils.toHexString(block.getParentHash()).toUpperCase()); + + assertEquals("1DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347", + Utils.toHexString(block.getUnclesHash()).toUpperCase()); + + assertEquals("3854AAF203BA5F8D49B1EC221329C7AEBCF050D3", + Utils.toHexString(block.getCoinbase()).toUpperCase()); + + assertEquals("990DC3B5ACBEE04124361D958FE51ACB582593613FC290683940A0769549D3ED", + Utils.toHexString(block.getStateHash()).toUpperCase()); + + assertEquals("9BFE4817D274EA3EB8672E9FE848C3885B53BBBD1D7C26E6039F90FB96B942B0", + Utils.toHexString(block.getTxListHash()).toUpperCase()); + + assertEquals("3FF000", Utils.toHexString(block.getDifficulty()).toUpperCase()); + assertEquals(1396643511, block.getTimestamp()); + + assertNull(block.getExtraData()); + + assertEquals("00000000000000000000000000000000000000000000000077377ADFF6C227DB", + Utils.toHexString(block.getNonce()).toUpperCase()); + + System.out.println(blocksMessage); + + } + + + + /* GET_CHAIN */ + + @Test /* GET_CHAIN message parsing*/ + public void test_12(){ + + String getChainRaw = "F9042414A09F7A910147A6C99AB7EEEAC1ADC7B1B9B0D7D9DD83FD7FC125561016F19B624DA024B519ED5F71207330C1F450B7A4C7445C589B5F9AE73E9BBA09E0A8CB15D845A01EF7B03C7E58E65068D71F68E168C0CC0438808C32FB3E46E402D078B2020E0DA06A0F152620F606E134679D22A86156F9DDEB56FACD62C3106CC66AE030234483A001A3E918F9C2F74BD144505CF70650EF30BE806C533BA5AE3C983F55615EE98EA0E5E441F0877116011CCDECE2501A50B40C40418377037E16D0282B2B5E347138A0C55035BC5BDA25A8C6A2EFF4CCF5386CFFF3E7EE1DC9168B00AABF1074FEB1E2A060AC4D0C12C4CBF552440E659FE4E54C38EF7D05EF98965BA0E0248379CB78DFA0E1620BF60A735DDEA7CB434143E7EF663D043420F017360289FF78046948A77AA0DA8BC25F6571AB0EDE9C3DEF34FFF996575ADFCC1F8009A0388CE0A63AD9FC57A0E153CD998421E4F6BAC6A8329AE90BDA70D5D0F46A7EC02B88BDF5D3CAA8384FA0D3F00977D766A5CAF8F07EF8D15B1DADBBFD57B60BBE6CA54B2F9C2446F614EFA08687EC7AE1A541B13CDA57DCF387DEA3EA35A35AC3D5A9381376EAFBC7BA2CF5A08814AC8660E776A3FCA432D2E9A3533AFFEAEC783ECBB5DAD495B44E04EF1F98A07F2E67F508830BF18E8A432BAB9B957FA2BCDE57BE6C766C13871F833C27B9A5A021EE1E6602530EF711F6C8022799108E1AFB546E7B5FF3E3CBB4DA66C054868DA02940A17DD5C1D1911FFDA7DFAE3E5FAF8E1808CBD11F3248C18B8777B4A5D256A07E5D2F25D9750665ADBFF9C36820AD67CC55850D7D798DAB512343AB0C4E58B3A06674BD13B1051852413031BAA885448E50917D7F1D5EFB7DBA397ED4E5C36D72A06AA7A7D18B07BE0222DA47A8EE6923BAD522DBF5D0650D64CA0F2AD4C606D0CCA07F877735FCC29F804926AACEDBF7AD4896E330DCCE57F257A7D5C81F5CC03188A0FF6B7749526281A5E6A845B8ACC7DC03D2CAAEAFF0CEBF78659FDE1007AD9C05A054D6375CF54B0246FB45787206BA70115DED577354942A9219BC9E761A7E0CBCA0809384946576FB15A8F827B30045D18203A90BE662863D5F205B868DF882472AA05A6EA58D02A2823BA693AC11C21D3C4D66AFFFDB9F1475EA86A461912C2F3187A003AF21F3939C29C231200B1F790F16421A8923254CBF2A90455B9B8F28BE4562A036FDFB3E05936CAA1ABBDCFBBACD9000F86FBCAE2228E77346533CEF17073767A0D3CE8B71E129020F3356A09946F9BC4C18E61D9516E74F6F912461A438F1E006A01D8203A8E23F50D70188ED3099E50645B92959C2216EA7A74719C159B4978BDBA03812A8FC4A5BB6EF0832EBF5058FAF65A46187CEE568C94915AE1850069775F3A0687DDEF8750F606637B3F5F23D286053671081A1AD224B35A624DE7392193951A0E6A8E1D4417292E20F9698A3464CEEABC6476A57521FF79D994DE22C55DADEAD820100"; + + byte[] payload = Hex.decode(getChainRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + GetChainMessage getChainMessage = new GetChainMessage(rlpList); + getChainMessage.parseRLP(); + System.out.println(getChainMessage); + + assertEquals(32, getChainMessage.getBlockHashList().size()); + + assertEquals("E5E441F0877116011CCDECE2501A50B40C40418377037E16D0282B2B5E347138", + Utils.toHexString( getChainMessage.getBlockHashList().get(5) ).toUpperCase()); + + assertEquals("6AA7A7D18B07BE0222DA47A8EE6923BAD522DBF5D0650D64CA0F2AD4C606D0CC", + Utils.toHexString( getChainMessage.getBlockHashList().get(19) ).toUpperCase()); + + assertEquals("03AF21F3939C29C231200B1F790F16421A8923254CBF2A90455B9B8F28BE4562", + Utils.toHexString( getChainMessage.getBlockHashList().get(25) ).toUpperCase()); + + + + } + + + /* NOT_IN_CHAIN */ + + @Test /* NotInChainMessage parsing 1 */ + public void test_13(){ + + String getChainRaw = "E015A0E5E441F0877116011CCDECE2501A50B40C40418377037E16D0282B2B5E347138"; + + byte[] payload = Hex.decode(getChainRaw); + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + NotInChainMessage notInChainMessage = new NotInChainMessage(rlpList); + System.out.println(notInChainMessage); + + Assert.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 new file mode 100644 index 00000000..999e310a --- /dev/null +++ b/ethereumj-core/src/test/java/org/ethereum/net/RLPTest.java @@ -0,0 +1,344 @@ +package org.ethereum.net; + +import org.bouncycastle.util.encoders.Hex; +import org.ethereum.net.rlp.RLPList; +import org.ethereum.util.Utils; +import org.junit.Assert; +import org.junit.Test; + +import java.math.BigInteger; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.LinkedList; +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 + public void test1() throws UnknownHostException { + + 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); + + + byte[] ip = RLP.decodeIP4Bytes(payload, 5); + + assertEquals(InetAddress.getByAddress(ip).toString(),("/54.204.10.41")); + + + } + + @Test + public void test2() throws UnknownHostException { + + 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); + int oneInt = RLP.decodeInt(payload, 11); + + assertEquals(oneInt, 30303); + + + } + + + @Test + public void test3() throws UnknownHostException { + + String peersPacket = "F8 9A 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 F8 4A C4 36 02 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); + + int nextIndex = 5; + byte[] ip = RLP.decodeIP4Bytes(payload, nextIndex); + assertEquals("/54.204.10.41", InetAddress.getByAddress(ip).toString()); + + nextIndex = RLP.getNextElementIndex(payload, nextIndex); + int port = RLP.decodeInt(payload, nextIndex); + assertEquals(30303, port); + + nextIndex = RLP.getNextElementIndex(payload, nextIndex); + BigInteger peerId = RLP.decodeBigInteger(payload, nextIndex); + + BigInteger expectedPeerId = + new BigInteger("-3757679129454624401847229560118336025674165800491763435653406124634392418475888088940922052683656239666728251000337405781915693264977453978537202650777524"); + assertEquals(expectedPeerId, peerId); + + nextIndex = RLP.getNextElementIndex(payload, nextIndex); + nextIndex = RLP.getFirstListElement(payload, nextIndex); + ip = RLP.decodeIP4Bytes(payload, nextIndex); + assertEquals("/54.2.10.41", InetAddress.getByAddress(ip).toString()); + + nextIndex = RLP.getNextElementIndex(payload, nextIndex); + port = RLP.decodeInt(payload, nextIndex); + assertEquals(30303, port); + + nextIndex = RLP.getNextElementIndex(payload, nextIndex); + peerId = RLP.decodeBigInteger(payload, nextIndex); + + expectedPeerId = + new BigInteger("-3757679129454624401847229560118336025674165800491763435653406124634392418475888088940922052683656239666728251000337405781915693264977453978537202650777524"); + + assertEquals(expectedPeerId ,peerId); + + nextIndex = RLP.getNextElementIndex(payload, nextIndex); + nextIndex = RLP.getFirstListElement(payload, nextIndex); + assertEquals(-1, nextIndex); + + } + + + @Test /** encode byte */ + public void test4(){ + + byte[] expected = {(byte)0x80}; + byte[] data = RLP.encodeByte((byte)0); + assertArrayEquals(expected, data); + + byte[] expected2 = {(byte)0x78}; + data = RLP.encodeByte((byte)120); + assertArrayEquals(expected2, data); + + byte[] expected3 = {(byte)0x81, (byte)0x7F}; + data = RLP.encodeByte((byte)127); + assertArrayEquals(expected3, data); + } + + @Test /** encode short */ + public void test5(){ + + byte[] expected = {(byte)0x80}; + byte[] data = RLP.encodeShort((byte) 0); + assertArrayEquals(expected, data); + + byte[] expected2 = {(byte)0x78}; + data = RLP.encodeShort((byte) 120); + assertArrayEquals(expected2, data); + + byte[] expected3 = {(byte)0x81, (byte)0x7F}; + data = RLP.encodeShort((byte) 127); + assertArrayEquals(expected3, data); + + byte[] expected4 = {(byte)0x82, (byte)0x76, (byte)0x5F}; + data = RLP.encodeShort((short)30303); + assertArrayEquals(expected4, data); + + byte[] expected5 = {(byte)0x82, (byte)0x4E, (byte)0xEA}; + data = RLP.encodeShort((short)20202); + assertArrayEquals(expected5, data); + + } + + @Test /** encode string */ + public void test6(){ + + byte[] data = RLP.encodeString(""); + Assert.assertArrayEquals(new byte[]{(byte)0x80}, data); + + + byte[] expected = { (byte)0x90, (byte)0x45, (byte)0x74, (byte)0x68, (byte)0x65, (byte)0x72, (byte)0x65, + (byte)0x75, (byte)0x6D, (byte)0x4A, (byte)0x20, (byte)0x43, (byte)0x6C, + (byte)0x69, (byte)0x65, (byte)0x6E, (byte)0x74}; + + String test = "EthereumJ Client"; + data = RLP.encodeString(test); + + Assert.assertArrayEquals(expected, data); + + String test2 = "Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++"; + + byte[] expected2 = { (byte)0xAD, (byte)0x45, (byte)0x74, (byte)0x68, (byte)0x65, (byte)0x72, (byte)0x65, + (byte)0x75, (byte)0x6D, (byte)0x28, (byte)0x2B, (byte)0x2B, (byte)0x29, (byte)0x2F, + (byte)0x5A, (byte)0x65, (byte)0x72, (byte)0x6F, (byte)0x47, (byte)0x6F, (byte)0x78, + (byte)0x2F, (byte)0x76, (byte)0x30, (byte)0x2E, (byte)0x35, (byte)0x2E, (byte)0x30, + (byte)0x2F, (byte)0x6E, (byte)0x63, (byte)0x75, (byte)0x72, (byte)0x73, (byte)0x65, + (byte)0x73, (byte)0x2F, (byte)0x4C, (byte)0x69, (byte)0x6E, (byte)0x75, (byte)0x78, + (byte)0x2F, (byte)0x67, (byte)0x2B, (byte)0x2B}; + + data = RLP.encodeString(test2); + Assert.assertArrayEquals(expected2, data); + + String test3 = "Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++"; + + byte[] expected3 = {(byte)0xB8, (byte)0x5A, + (byte)0x45, (byte)0x74, (byte)0x68, (byte)0x65, (byte)0x72, (byte)0x65, + (byte)0x75, (byte)0x6D, (byte)0x28, (byte)0x2B, (byte)0x2B, (byte)0x29, (byte)0x2F, + (byte)0x5A, (byte)0x65, (byte)0x72, (byte)0x6F, (byte)0x47, (byte)0x6F, (byte)0x78, + (byte)0x2F, (byte)0x76, (byte)0x30, (byte)0x2E, (byte)0x35, (byte)0x2E, (byte)0x30, + (byte)0x2F, (byte)0x6E, (byte)0x63, (byte)0x75, (byte)0x72, (byte)0x73, (byte)0x65, + (byte)0x73, (byte)0x2F, (byte)0x4C, (byte)0x69, (byte)0x6E, (byte)0x75, (byte)0x78, + (byte)0x2F, (byte)0x67, (byte)0x2B, (byte)0x2B, + + (byte)0x45, (byte)0x74, (byte)0x68, (byte)0x65, (byte)0x72, (byte)0x65, + (byte)0x75, (byte)0x6D, (byte)0x28, (byte)0x2B, (byte)0x2B, (byte)0x29, (byte)0x2F, + (byte)0x5A, (byte)0x65, (byte)0x72, (byte)0x6F, (byte)0x47, (byte)0x6F, (byte)0x78, + (byte)0x2F, (byte)0x76, (byte)0x30, (byte)0x2E, (byte)0x35, (byte)0x2E, (byte)0x30, + (byte)0x2F, (byte)0x6E, (byte)0x63, (byte)0x75, (byte)0x72, (byte)0x73, (byte)0x65, + (byte)0x73, (byte)0x2F, (byte)0x4C, (byte)0x69, (byte)0x6E, (byte)0x75, (byte)0x78, + (byte)0x2F, (byte)0x67, (byte)0x2B, (byte)0x2B}; + + data = RLP.encodeString(test3); + Assert.assertArrayEquals(expected3, data); + } + + + @Test /** encode byte array */ + public void test7(){ + + + String byteArr = "CE 73 66 0A 06 62 6C 1B 3F DA 7B 18 EF 7B A3 CE " + + "17 B6 BF 60 4F 95 41 D3 C6 C6 54 B7 AE 88 B2 39 " + + "40 7F 65 9C 78 F4 19 02 5D 78 57 27 ED 01 7B 6A " + + "DD 21 95 2D 7E 12 00 73 73 E3 21 DB C3 18 24 BA "; + + byte[] byteArray = Utils.hexStringToByteArr(byteArr); + + String expected = "B8 40 " + byteArr; + + Assert.assertArrayEquals(Utils.hexStringToByteArr(expected), + RLP.encodeElement(byteArray)); + + } + + @Test /** encode list */ + public void test8(){ + } + + + + @Test /** found bug encode list affects element value, + hhh... not really at the end but keep the test */ + public void test9(){ + + + /* 2 */ byte[] prevHash = + {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}; + prevHash = RLP.encodeElement(prevHash); + + /* 2 */ byte[] uncleList = Utils.sha3(RLP.encodeList(new byte[]{})); + + /* 3 */ byte[] coinbase = + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + coinbase = RLP.encodeElement(coinbase); + + byte[] header = RLP.encodeList( + prevHash, uncleList, coinbase); + + + Assert.assertEquals("f856a000000000000000000000000000000000000000000000000000000000000000001dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000", + Hex.toHexString(header)); + + } + + + + @Test + public void test10(){ +// 2240089100000070 + String tx = "F86E12F86B80881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA0C52C114D4F5A3BA904A9B3036E5E118FE0DBB987FE3955DA20F2CD8F6C21AB9CA06BA4C2874299A55AD947DBC98A25EE895AABF6B625C26C435E84BFD70EDF2F69"; + byte[] payload = Hex.decode(tx); + + Queue index = new LinkedList(); + RLP.fullTraverse(payload, 0, 0, payload.length, 1, index); + + + // TODO: assert lenght overflow while parsing list in RLP + } + + @Test + public void test11(){ + + String tx = "F86E12F86B80881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA0C52C114D4F5A3BA904A9B3036E5E118FE0DBB987FE3955DA20F2CD8F6C21AB9CA06BA4C2874299A55AD947DBC98A25EE895AABF6B625C26C435E84BFD70EDF2F69"; + byte[] payload = Hex.decode(tx); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + RLPList.recursivePrint(rlpList); + // TODO: add some asserts in place of just printing the rlpList + } + + + @Test /* very long peers msg */ + public void test12(){ + + String peers= "f9 14 90 11 f8 4c c6 81 83 68 81 fc 04 82 76 5f b8 40 07 7e 53 7a 8b 36 73 e8 f1 b6 25 db cc 90 2e a7 d4 ce d9 40 2e 46 64 e8 73 67 95 12 cc 23 60 69 8e 53 42 56 52 a0 46 24 fc f7 8c db a1 a3 23 30 87 a9 19 a3 4d 11 ae da ce ee b7 d8 33 fc bf 26 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 0a b2 cd e8 3a 09 84 03 dd c2 ea 54 14 74 0d 8a 01 93 e4 49 c9 6e 11 24 19 96 7a bc 62 eb 17 cd ce d7 7a e0 ab 07 5e 04 f7 dd dc d4 3f b9 04 8b e5 32 06 a0 40 62 0b de 26 cb 74 3f a3 12 31 9f f8 4d c7 81 cf 81 db 45 81 9a 82 76 5f b8 40 19 c3 3d a7 03 1c ff 17 7e fa 84 2f aa 3d 31 bd 83 e1 76 4e c6 10 f2 36 94 4a 9f 8a 21 c1 c5 1a 04 f4 7f 6b 5f c3 ef e6 5c af 36 94 43 63 5a fc 58 d8 f5 d4 e2 f1 2a f9 ee ec 3c 6e 30 bf 0a 2b f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 1e 59 c2 82 08 12 94 80 84 97 ae 7a 7e 97 67 98 c4 2b 8b cc e1 3c 9d 8b 0e cf 8a fe cd b5 df d4 ef a8 77 0f c0 d1 f7 de 63 c9 16 40 e7 e8 b4 35 8c 9e 3e d0 f3 d6 c9 86 20 ad 7e a4 24 18 c9 ec f8 4b c5 1f 12 81 9e 48 82 76 5f b8 40 1f 68 c0 75 c1 d8 7b c0 47 65 43 0f df b1 e5 d0 0f 1b 78 4e d6 be 72 1e 4c af f7 be b5 7b 4b 21 7b 95 da 19 b5 ec 66 04 58 68 b3 9a ac 2e 08 76 cf 80 f0 b6 8d 0f a2 0b db 90 36 be aa 70 61 ea f8 4c c6 81 bf 81 ea 39 37 82 76 5f b8 40 21 78 0c 55 b4 7d b4 b1 14 67 b5 f5 5b 0b 55 5e 08 87 ce 36 fb d9 75 e2 24 b1 c7 0e ac 7a b8 e8 c2 db 37 f0 a4 8b 90 ff dd 5a 37 9a da 99 b6 a0 f6 42 9c 4a 53 c2 55 58 19 1a 68 26 36 ae f4 f2 f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 23 15 cb 7c f4 9b 8e ab 21 2c 5a 45 79 0b 50 79 77 39 73 8f 5f 73 34 39 b1 90 11 97 37 ee 8c 09 bc 72 37 94 71 2a a8 2f 26 70 bc 58 1a b0 75 7e f2 31 37 ac 0f df 0f 8c 89 65 e7 dd 6b a7 9f 8c f8 4e c8 81 bf 81 b1 81 d1 81 9f 82 76 5f b8 40 24 9a 36 41 e5 a8 d0 8e 41 a5 cf c8 da e1 1f 17 61 25 4f 4f d4 7d 9b 13 33 8d b8 e6 e3 72 9e 6f 2a c9 ec 09 7a 5c 80 96 84 d6 2a 41 e6 df c2 ff f7 2d c3 db d9 7e a2 61 32 bb 97 64 05 65 bb 0c f8 4a c4 55 41 7e 2d 82 76 5f b8 40 2a 38 ea 5d 9a 7e fd 7f ff c0 a8 1d 8e a7 ed 28 31 1c 40 12 bb ab 14 07 c8 da d2 68 51 29 e0 42 17 27 34 a3 28 e8 90 7f 90 54 b8 22 5f e7 70 41 d8 a4 86 a9 79 76 d2 83 72 42 ab 6c 8c 59 05 e4 f8 4c c6 81 83 68 81 fc 04 82 76 5f b8 40 32 4d d9 36 38 4d 8c 0d de fd e0 4b a7 40 29 98 ab bd 63 d7 9c 0b f8 58 6b 3d d2 c7 db f6 c9 1e b8 0a 7b 6d e8 f1 6a 50 04 4f 14 9c 7b 39 aa fb 9c 3a d7 f2 ca a4 03 55 aa b0 98 88 18 6f cc a2 f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 39 42 45 c0 99 16 33 ed 06 0b af b9 64 68 53 d3 44 18 8b 80 4f e3 7e 25 a5 bc ac 44 ed 44 3a 84 a6 8b 3a af 15 5e fe 48 61 e8 4b 4b 51 5f 9a 5d ec db d7 da e9 81 92 d7 a3 20 a7 92 c7 d4 df af f8 4d c7 56 81 b7 81 e7 81 cd 82 76 5f b8 40 39 86 50 f6 7b 22 92 93 9d e3 4c 0e ae b9 14 1f 94 84 a0 fb 17 3f a3 3f 81 a1 f7 31 5d 0e b7 7b de 3a 76 c3 86 36 fa e6 6f a1 4b f2 af df d6 3e 60 ab d4 0e 29 b0 2a 91 4e 65 de 57 89 98 3f d4 f8 4c c6 44 81 b9 81 ea 40 82 76 5f b8 40 3a 15 58 7a 1c 3a da bf 02 91 b3 07 f7 1b 2c 04 d1 98 aa e3 6b 83 49 95 d3 30 5d ff 42 f1 ab 86 f4 83 ae 12 9e 92 03 fb c6 ef 21 87 c8 62 1e dd 18 f6 1d 53 ea a5 b5 87 ff de a4 d9 26 48 90 38 f8 4d c7 81 cf 81 db 45 81 9a 82 76 5f b8 40 3b 14 62 04 0e a7 78 e3 f7 5e 65 ce 24 53 41 8a 66 2e 62 12 c9 f6 5b 02 ea b5 8d 22 b2 87 e4 50 53 bd e5 eb f0 60 96 0c bf a0 d9 dc 85 bf 51 ba 7a a1 f2 ca a2 c1 36 82 d9 32 77 64 1d 60 db eb f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 3e cc 97 ab 15 d2 2f 7b 9e df 19 c0 4c e3 b6 09 5f a2 50 42 14 00 2b 35 98 9c 6f 81 ee 4b 96 1c c2 a8 99 c4 94 15 c9 14 e3 13 90 83 40 04 7d 1d 3b 25 d7 4f 5b 9c 85 a0 6a fa 26 59 a5 39 99 2e f8 4b c5 2e 04 81 c1 09 82 76 5f b8 40 40 7c 22 00 3f 3b ba a6 cb eb 8e 4b 0a b7 07 30 73 fe ab 85 18 2b 40 55 25 f8 bd 28 32 55 04 3d 71 35 18 f7 47 48 d9 2c 43 fb b9 9e cc 7c 3f ba b9 5d 59 80 06 51 3a a8 e5 9c 48 04 1c 8b 41 c2 f8 4b c5 32 7e 56 81 c2 82 76 5f b8 40 40 8c 93 24 20 3b d8 26 2f ce 65 06 ba 59 dc dd 56 70 89 b0 eb 9a 5b b1 83 47 7b ab bf 61 63 91 4a cd c7 f4 95 f8 96 4d 8a c1 2f e2 40 18 87 b8 cd 8d 97 c0 c9 dc cf ad db b2 0a 3c 31 47 a7 89 f8 4a c4 26 6c 4f 68 82 76 5f b8 40 42 3e 40 04 da 2f a7 50 0b c0 12 c0 67 4a a6 57 15 02 c5 3a a4 d9 1e fa 6e 2b 5c b1 e4 68 c4 62 ca 31 14 a2 e2 eb 09 65 b7 04 4f 9c 95 75 96 5b 47 e4 7a 41 f1 3f 1a dc 03 a2 a4 b3 42 d7 12 8d f8 4b c5 40 81 e7 08 2d 82 76 5f b8 40 42 83 93 75 27 2c 2f 3d ea db 28 08 5d 06 05 5e 35 31 35 c6 c8 d8 96 09 7a 1b c4 80 c4 88 4f d1 60 45 18 cb df 73 1a c1 8f 09 84 b7 f0 21 48 e8 82 90 d1 3c 22 4d 82 46 43 14 e2 b5 96 2e 3f 89 f8 4d c7 32 81 aa 81 d8 81 c8 82 76 5f b8 40 44 cf 19 44 6c a4 65 01 8e 4d e6 c6 0f c0 df 52 9e ba 25 02 92 ef 74 41 e1 db 59 84 1c 69 f0 22 f6 09 28 10 c9 a5 a7 f2 74 f2 f9 7c 4b d6 c7 6e ad c0 64 c7 d6 59 7c ae b1 7e d8 7c b2 57 73 5f f8 4b c5 32 81 9c 5a 53 82 76 5f b8 40 46 1c 9b 54 e9 19 53 c5 bb c3 1c 67 12 a9 17 38 2b e6 7d 60 f7 5e b7 f5 06 51 be a3 e5 94 d0 d1 9c 22 29 d8 f6 6a db 3f 20 3f 60 00 38 e7 cc 93 4d c9 27 87 fa c4 39 2b 9b fa 7c bc 78 6f d0 5b f8 4b c5 81 86 64 7d 29 82 76 5f b8 40 48 35 3a 00 58 e2 64 48 d9 4e 59 33 6c ca 9d 28 a9 37 41 20 de f7 6c 4b cc fe e1 8b 01 23 e5 91 92 39 3a 2e e3 04 4d 80 e0 ee cb b0 94 76 be 62 fd e1 e8 74 f9 3d 05 ea 5c 4a 9a 45 c0 6e 8f e1 f8 4b c5 4e 08 05 81 bb 82 76 5f b8 40 48 e8 95 09 49 d4 c0 0b cd bb e9 39 c5 bf 07 8f 2c bf f1 08 84 af 16 60 b1 c3 22 b9 ca a3 ba 35 7b b4 15 7f c6 b0 03 9a f9 43 8d fe 51 ec 27 8a 47 fc d3 b7 26 fa 0a 08 7d 4c 3c 01 a6 2f 33 5e f8 4a c6 58 45 81 c6 81 c6 07 b8 40 4a 02 55 fa 46 73 fa a3 0f c5 ab fd 3c 55 0b fd bc 0d 3c 97 3d 35 f7 26 46 3a f8 1c 54 a0 32 81 cf ff 22 c5 f5 96 5b 38 ac 63 01 52 98 77 57 a3 17 82 47 85 49 c3 6f 7c 84 cb 44 36 ba 79 d6 d9 f8 4b c5 40 81 e7 08 2d 82 76 5f b8 40 4c 75 47 ab 4d 54 1e 10 16 4c d3 74 1f 34 76 ed 19 4b 0a b9 a1 36 df ca c3 94 3f 97 35 8c 9b 05 14 14 27 36 ca 2f 17 0f 12 52 29 05 7b 47 32 44 a6 23 0b f5 47 1a d1 68 18 85 24 b2 b5 cd 8b 7b f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 4d 5e 48 75 d6 0e b4 ee af b6 b2 a7 d3 93 6e d3 c9 bc 58 ac aa de 6a 7f 3c 5f 25 59 8c 20 b3 64 f1 2b ea 2f b1 db 3b 2c 2e f6 47 85 a4 7d 6b 6b 5b 10 34 27 cb ac 0c 88 b1 8f e9 2a 9f 53 93 f8 f8 4b c5 52 0c 81 e3 54 82 76 5f b8 40 4f d8 98 62 75 74 d3 e8 6b 3f 5a 65 c3 ed c2 e5 da 84 53 59 26 e4 a2 88 20 b0 03 8b 19 63 6e 07 db 5e b0 04 d7 91 f8 04 1a 00 6e 33 e1 08 e4 ec 53 54 99 d1 28 d8 d9 c5 ca f6 bb dc 22 04 f7 6a f8 4b c5 81 b4 20 2b 08 82 76 5f b8 40 53 cc f2 5a b5 94 09 ec bb 90 3d 2e c3 a9 aa 2e b3 9d 7c c4 c7 db 7e 6f 68 fd 71 1a 7c eb c6 06 21 6d e7 37 82 6d a4 20 93 e3 e6 52 1e e4 77 0e b2 d6 69 dc 4b f3 54 6c c7 57 c3 40 12 69 6e ae f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 54 b3 93 15 69 91 39 87 80 50 2f a8 f4 14 13 79 bc e2 69 31 be 87 ba 8e 0b 74 9b a9 05 a9 e9 76 e5 de 6d 39 c9 8c f0 48 f2 5c 3c bb b8 c7 f3 02 c4 e6 04 ad 5b f7 2c db 06 10 0f 50 0d e3 a6 86 f8 4a c4 4c 67 37 47 82 76 5f b8 40 60 0a 77 fb 14 e7 92 c0 c7 0d c4 ad e3 82 ed 60 43 62 b9 78 b1 9b 94 c4 ed 18 83 38 a1 79 5d 2d b4 5f 7f 22 3b 66 ba eb a3 91 c5 9b 55 88 b4 4e ba f7 1c 7e b3 97 55 c2 72 29 c7 fd e6 41 be ce f8 4b c5 6d 2b 81 9a 42 82 76 5f b8 40 69 dd 44 5f 67 c3 be f3 94 f9 54 9f da e1 62 3d bc 20 88 4a 62 fd 56 16 dd bb 49 f8 4b a8 7e 14 7c b8 a5 0b a9 71 d7 30 c4 62 1d 0e b6 51 33 49 4e 94 fa 5e a2 e6 9c 66 1f 6b 12 e7 ed 2a 8d 4e f8 4b c5 18 09 3d 81 9b 82 76 5f b8 40 6b 5d 4c 35 ff d1 f5 a1 98 03 8a 90 83 4d 29 a1 b8 8b e0 d5 ef ca 08 bc 8a 2d 58 81 18 0b 0b 41 6b e0 06 29 aa be 45 0a 50 82 8b 8d 1e e8 2d 98 f5 52 81 87 ee 67 ed 6e 07 3b ce ef cd fb 2b c9 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 6c bb 1e d5 36 dc 38 58 c1 f0 63 42 9b d3 95 2a 5d 32 ef 8e 11 52 6c df e7 2f 41 fe a1 ac e9 60 18 7c 99 75 ab bc 23 78 35 11 c0 0f 26 98 35 47 47 f9 05 aa ac 11 dc d2 b7 47 8b 3e af 32 7a c6 f8 4b c5 40 81 e7 08 2d 82 76 5f b8 40 6e a2 8f 64 ea 1c c3 b6 57 25 44 fd 5b f7 43 b0 ea ab e0 17 f5 14 73 0c 89 7d a3 c7 7f 03 c5 16 f1 e5 f3 1d 79 3b 4b ce 3c aa 1d ed 56 35 6d 20 b2 eb b5 5a 70 66 f4 1c 25 b7 c3 d5 66 14 e0 6b f8 4a c4 55 41 7e 2d 82 76 5f b8 40 72 53 24 08 e8 be 6d 5e 2c 9f 65 0f b9 c9 f9 96 50 cc 1f a0 62 a4 a4 f2 cf e4 e6 ae 69 cd d2 e8 b2 3e d1 4a fe 66 95 5c 23 fa 04 8f 3a 97 6e 3c e8 16 9e 50 5b 6a 89 cc 53 d4 fa c2 0c 2a 11 bf f8 4c c6 52 81 d9 48 81 a9 82 76 5f b8 40 7a ee a4 33 60 b9 36 8b 30 e7 f4 82 86 61 3f d1 e3 b0 20 7f b7 1f 03 08 d5 04 12 11 44 63 e7 7a b8 30 27 c0 d4 0c ad aa b8 bb f6 12 fc 5b 69 67 fa 1c 40 73 29 d4 7e c6 1f b0 dc 3d a1 08 68 32 f8 4c c6 81 a6 81 93 53 4f 82 76 5f b8 40 7b 3c dd e0 58 d5 b4 5d 8d b2 24 36 60 cf ea 02 e0 74 ec 21 31 14 c2 51 d7 c0 c3 2d 04 03 bb 7a b4 77 13 d2 49 2f f6 c8 81 cf c2 aa c3 f5 2c b2 69 76 8c 89 68 f3 b6 b1 8b ac 97 22 d0 53 31 f6 f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 87 ab 58 1b b9 7c 21 2a 2d a7 ef 0d 6e 10 5e 41 b5 5e 4e 42 cb b6 a1 af 9a 76 1a 01 ca 8c 65 06 9a b4 b5 82 7e 32 2c f2 c5 f5 9e 7f 59 2b e2 a8 17 c4 5a b6 41 f5 a9 dd 36 89 63 c7 3f 9e e6 88 f8 4c c6 52 81 d9 48 81 a9 82 76 5f b8 40 8c 66 0d bc 6d 3d b0 18 6a d1 0f 05 fd 4f 2f 06 43 77 8e c5 14 e8 45 2a 75 50 c6 30 da 21 17 1a 29 b1 bb 67 c2 e8 e1 01 ea 1d b3 97 43 f3 e7 8c 4d 26 76 a1 3d 15 51 51 21 51 5f c3 8b 04 8f 37 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 94 fe 3d 52 a2 89 4c ed c6 b1 54 24 15 6e b8 73 8a 84 41 dd 74 ba 9c ed 66 64 ed 30 a3 32 a9 5b 57 4d 89 26 2e a3 67 fa 90 0a e9 70 6f b8 1a 40 82 87 bd de f3 a9 dd 9f f4 4e 3a 41 bc 09 0f dc f8 4d c7 81 d5 81 81 81 e6 0a 82 76 5f b8 40 95 21 14 f1 10 e8 ac 00 df ea 5f 05 0d 95 5e 76 4c 7c ba 8f b2 07 c0 5a 7a a5 ae 84 91 68 64 0a 2b 4e 31 43 91 fc 3a 76 79 5b 38 27 05 54 62 63 9c ff 4a e2 d6 4a b8 0e 95 27 44 28 31 3e 36 6a f8 4c c6 58 45 81 c6 81 c6 82 76 5f b8 40 96 f3 47 b0 96 ed 16 30 f4 74 b9 76 23 e4 5e 8d 47 1b 1d 43 c2 2f 59 96 07 c8 b2 e3 ed 0d 7b 79 05 d8 55 4a d3 99 db d7 39 c7 61 26 40 44 24 d8 db 0d c7 d2 b0 47 c1 a3 28 ae 27 d4 09 06 c5 83 f8 4c c6 81 83 68 81 fc 04 82 76 5f b8 40 9a 22 c8 fb 1b d8 bb d0 2f 0e 74 ed 9d 3d 55 b0 f5 b0 96 72 bc 43 a2 d4 7b 1e d0 42 38 c1 c3 2b 6a 65 74 26 52 5b 15 51 82 36 e9 78 9b 54 6a 4a 07 2a 60 5e 13 73 fe 5b 99 6b ae dc 30 35 94 28 f8 4b c5 52 0c 81 e3 54 82 76 5f b8 40 9b 1a 3a 8d 77 1b 3d 94 9c a3 94 a8 8e b5 dc 29 a9 53 b0 2c 81 f0 17 36 1f fc 0a fe 09 ab ce 30 69 17 1a 87 d4 74 52 36 87 fc c9 a9 d3 2c c0 2c fa b4 13 22 56 fe aa bf e0 5f 7a c7 47 19 4e 88 f8 4b c5 42 81 d7 78 1c 82 76 5f b8 40 9f a7 e5 5b 2d 98 f1 d7 44 c7 62 32 e4 fd a2 42 fe 9f d3 d5 74 3d 16 d3 ca d2 e5 48 a0 7c b5 af 06 fe 60 eb ae b8 c6 09 50 28 17 92 34 dc dd d3 cd cf 1f cf e6 ed aa 2a 53 30 7f d1 03 da 4a f0 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 a0 1f 83 4e 9d 1a 61 3c 3c 74 7e 56 1c ac 19 cb 12 d8 79 c1 a5 74 20 a4 9c 23 65 2b 8f 51 28 8c 8b 11 1a a3 88 89 98 b0 5e 32 7f 47 a2 35 c6 a4 a3 77 f8 88 e3 00 5a 2d 4b 03 ec b7 26 86 08 d3 f8 4c c6 44 30 81 ad 81 a3 82 7a 51 b8 40 a5 fd 77 c0 d4 32 fb fa 33 17 08 49 14 c2 e8 a8 82 1e 4b a1 dc ba 44 96 1f f7 48 0e 6d b6 08 78 9c ab 62 91 41 63 60 ea 8c dc 26 b0 d2 f0 87 7c 50 e8 9a 70 c1 bc f5 d6 dd 8b 18 2e 0a 9e 37 d3 f8 4d c7 81 88 81 a0 81 98 31 82 76 5f b8 40 ae 31 bd 02 54 ee 7d 10 b8 0f c9 0e 74 ba 06 ba 76 11 87 df 31 38 a9 79 9d e5 82 8d 01 63 52 4c 44 ba c7 d2 a9 b5 c4 1b e5 be 82 89 a1 72 36 1f 0b a9 04 10 c9 4f 57 9b f7 eb d2 8f 18 aa a1 cd f8 4a c4 55 41 7e 2d 82 76 5f b8 40 ba 3d 21 67 72 cd c7 45 58 d2 54 56 24 a2 d6 2d cb cf d2 72 30 57 30 c7 46 43 c7 a7 e8 19 af a6 cd d8 22 23 e2 b5 50 1e b6 d4 ea e5 db f2 1e 55 8c 76 8a ca ec 2c 1c a1 0e 74 c4 c8 7a 57 4b 53 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 bd b4 9c 01 87 2d 91 bd 1e a9 90 bd 2e df 16 c4 81 71 a6 06 7f 9a 6f 7f 48 bf b1 94 63 0b 5a e9 03 1b 5d c2 63 f5 9c 66 ad a4 44 cb 4e 6f 9d f6 2b 30 17 ce 61 2c ab 7b 53 da 08 d3 56 f7 8d 30 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 c1 2b a9 1f 95 04 4d 78 ee d1 d3 a9 53 5e bd 64 71 52 44 18 13 5e eb 46 ad 5d 5c 6e cc 2f 51 68 b4 ab 3a 06 2b b0 74 2a ea 65 ff ea 76 7f ab 8d cc 21 78 3c b2 9b f3 2e 2c d6 22 22 09 fa 71 fd f8 4c c6 44 30 81 ad 81 a3 82 7a 51 b8 40 c2 e2 69 e6 4a a8 c9 be 2d 41 81 2a 48 af a2 34 6b d4 1a 1a b2 e4 64 62 41 ae 3b 8d 0c cd 41 f2 d6 82 b1 5a 02 5f 75 9c 0d 95 5a 60 71 d4 e8 ea 7d 4d e3 97 d6 e0 52 23 09 20 11 3b 6e b7 4c 09 f8 4a c4 4a 4f 17 77 82 76 5f b8 40 c3 03 b8 3f 6a 16 1f 99 67 36 34 44 80 ae 9d 88 fd c1 d9 c6 75 bf ac a8 88 f7 0f 24 89 72 65 62 82 09 da 53 74 1e 03 c0 f6 59 21 f6 8f 60 2d c9 f3 34 a3 c4 5b cb 92 af 85 44 a6 fb 11 9b d8 87 f8 4b c5 0c 81 fa 61 1a 82 76 5f b8 40 c7 6e 7c 15 7b 77 35 51 11 53 d1 f9 50 81 a1 44 e0 88 a9 89 17 1f 3d 43 2c c5 d8 29 3e ce 9c fa a4 83 c0 32 15 5d 7b 53 65 6a 6e 33 a3 d7 5c d0 62 4e 09 a2 f9 49 c1 56 09 3d ba a8 3f 11 11 f2 f8 4b c5 52 0c 81 e3 54 82 76 5f b8 40 c7 d5 a3 69 1a 59 59 9d e3 33 48 9c bf 8a 47 a7 43 3e 92 c7 27 06 e1 3d 94 ed 21 12 96 d3 5c 97 d8 35 7d 7e 07 b3 85 85 64 d7 26 8e d7 aa 09 7f 37 58 9c 27 77 0f 90 dd 0b 07 63 5b e3 f5 33 64 f8 4c c6 4e 09 81 92 81 b2 82 76 5f b8 40 c8 81 97 a8 2b 0a cf 0a 87 24 94 d1 df ac 9d e8 46 da a7 de 08 b2 40 64 7a 96 ba 72 fb e0 8f d5 2b 55 c6 c9 45 14 a4 7e c5 1b a4 9a 97 54 89 eb c9 38 3b 48 f5 e2 40 93 90 68 ce 58 36 ff 24 f1 f8 4b c5 81 b4 20 2b 08 82 76 5f b8 40 c9 e0 39 d8 a8 b9 e4 35 be f2 f4 5f c7 cb 7e 78 87 16 e8 c7 af c1 ba cc 64 e1 24 6d 2a b5 06 d3 60 73 79 2a e6 96 e4 1a d6 ba 0c 8a bd 2e c0 d5 45 b0 75 7f 94 a9 f3 53 82 80 e5 6d b5 f5 d8 ec f8 4b c5 4e 68 81 a3 51 82 76 5f b8 40 ca 27 68 37 02 a8 e9 bf 32 01 65 6f f8 4a 60 d5 b1 dd 81 42 73 99 3c f1 a0 25 b0 54 45 4e 40 d5 30 92 f4 85 18 ee 05 be ad 4f 18 02 1f 4f 54 0c 0b 7c 7d 26 eb a5 0e a4 89 0b 9e 5e 49 a7 6c 5f f8 4a c4 55 41 7e 2d 82 76 5f b8 40 cb 72 be 9e 2e 5d 4a 1f 25 72 96 c7 39 39 10 4e ce 80 31 32 15 26 5a f0 6b c7 ea f4 42 ab ff 4f 0b 48 fc fc 6f 43 f4 df 46 30 c7 12 b5 e7 ef db 75 4a 86 e4 0c f2 02 16 6e b6 9e ea a6 ad 3a 2d f8 4a c4 36 48 1f 37 82 76 5f b8 40 ce 73 66 0a 06 62 6c 1b 3f da 7b 18 ef 7b a3 ce 17 b6 bf 60 4f 95 41 d3 c6 c6 54 b7 ae 88 b2 39 40 7f 65 9c 78 f4 19 02 5d 78 57 27 ed 01 7b 6a dd 21 95 2d 7e 12 00 73 73 e3 21 db c3 18 24 ba f8 4a c4 55 41 7e 2d 82 76 5f b8 40 ce 73 f1 f1 f1 f1 6c 1b 3f da 7b 18 ef 7b a3 ce 17 b6 f1 f1 f1 f1 41 d3 c6 c6 54 b7 ae 88 b2 39 40 7f f1 f1 f1 f1 19 02 5d 78 57 27 ed 01 7b 6a dd 21 f1 f1 f1 f1 00 00 01 e3 21 db c3 18 24 ba f8 4c c6 81 bf 81 ea 39 37 82 76 5f b8 40 d2 30 30 60 35 99 b7 6f 64 0b 8f 7c 11 99 12 bb 04 66 e7 ee f3 38 cd 9d e5 67 d2 b6 df ba 81 72 8d b2 e9 8f 29 38 25 bb 00 a9 a6 ac 93 66 83 fc 82 c8 bc 38 7a df 3a 4a 5f e1 cc ca dd 1a 74 59 f8 4c c6 6b 81 aa 39 81 f7 82 76 5f b8 40 e0 2b 18 fb a6 b8 87 fb 92 58 46 9c 3a f8 e4 45 cc 9a e2 b5 38 6c ac 5f 60 c4 17 0f 82 20 86 22 4e 38 76 55 5c 74 5a 7e c8 ac 18 1c 7f 97 01 77 6d 94 a7 79 60 4e a1 26 51 de 5f 4a 74 8d 29 e1 f8 4c c6 40 81 e7 0a 81 d0 82 76 5f b8 40 e3 11 15 a7 6f a7 fb 2e fd 3c fa f4 6a d0 0b 05 fc 34 98 e1 ba f1 78 5d ff e6 ca 69 91 3d 25 65 31 d1 80 56 42 35 fd 3d 3c 10 40 9c d1 1f c2 59 cf 7c fd a9 b6 bb 25 33 40 41 2d 82 87 8f 3b d3 f8 4b c5 41 5e 31 81 97 82 76 5f b8 40 e5 e8 d8 c2 d7 62 d2 1c a1 e9 bc ee 8a dc 53 60 0f 2d 89 40 97 54 26 66 d6 b5 f4 1b 23 58 4b 07 f6 09 01 ab 40 9d df 91 e0 cd 25 62 da ff f2 cb 0f 22 1e b9 f1 15 6f 78 1a 5d 99 31 a0 2a 2e 07 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 ea 99 2c 13 68 7c 20 e7 90 a9 ff a6 df 8b 1a 16 86 88 e2 a8 87 36 5d 7a 50 21 86 fa 0d 62 20 e8 3e 11 3a 1f e7 7d c0 68 9d 55 ba 2e 8a 83 aa 8e 20 42 18 f4 d8 e7 32 82 5b d7 80 cf 94 ed 5c c3 f8 4b c5 56 7c 52 81 fe 82 76 5f b8 40 f6 15 5f 1a 60 14 3b 7d 9d 5d 1a 44 0d 7d 52 fe 68 09 f6 9e 0c 6f 1e 00 24 45 7e 0d 71 dd 88 ad e3 b1 3a aa 94 0c 89 ac 06 10 95 2b 48 bd 83 2c 42 e3 43 a1 3e 61 ff db 06 01 0c ff c3 45 e0 53 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 fa 56 85 61 b7 d5 28 8d f7 a5 06 c9 bc 1c 95 12 ab 39 6e 68 c4 6f 0e 62 c2 1d c1 aa 58 4b 84 4a 8a 7e 94 4f 69 71 30 36 65 fd 37 b1 38 d9 a5 f6 37 e6 72 ed b9 89 69 66 4c 4e 7f d1 c4 12 6d ef"; + byte[] payload = Hex.decode(peers); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + RLPList.recursivePrint(rlpList); + // TODO: add some asserts in place of just printing the rlpList + } + + @Test /* very very very long blocks msg */ + public void test13(){ + + String blocksMsg= "f91c1c13f90150f8c4a07df3d35d4df0a56fcf1d6344d5315cb56b9bf83bb96ad17c7b96a9cd14133c5da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a064afb6284fa35f26d7b2c5a26afaa5483072fbcb575221b34ce002a991b7a223a04a8abe6d802797dc80b497584f898c2d4fd561cc185828cfa1b92f6f38ee348e833fbfe484533f201c80a000000000000000000000000000000000000000000000000000cfccb5cfd4667cf887f8850380942d0aceee7e5ab874e22ccf8d1a649f59106d74e88609184e72a000822710a047617600000000000000000000000000000000000000000000000000000000001ca08691ab40e258de3c4f55c868c0c34e780e747158a1d96ca50186dfd3305abd78a042269c981d048a7b791aafc8f4e644232740c1a1cceb5b6d05568827a64c0664c0f8c8f8c4a0637c8a6cdb907fac6f752334ab79065bcc4e46cd4f4358dbc2a653544a20eb31a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a022a36c1a1e807e6afc22e6bb53a31111f56e7ee7dbb2ee571cefb152b514db4da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcfd784533f1cf980a0000000000000000000000000000000000000000000000000e153d743fa040b18c0c0f8c8f8c4a07b2536237cbf114a043b0f9b27c76f84ac160ea5b87b53e42c7e76148964d450a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07a3be0ee10ece4b03097bf74aabac628aa0fae617377d30ab1b97376ee31f41aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fbfe884533f1ce880a0000000000000000000000000000000000000000000000000f3deea84969b6e95c0c0f8c8f8c4a0d2ae3f5dd931926de428d99611980e7cdd7c1b838273e43fcad1b94da987cfb8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a00b5b11fcf4ee12c6812f9d01cf0dff07c72cd7e02e48b35682f67c595407be14a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833faffd84533f1ce280a00000000000000000000000000000000000000000000000005fcbc97b2eb8ffb3c0c0f8c8f8c4a094d615d3cb4b306d20985028c78f0c8413d509a75e8bb84eda95f734debad2a0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a04b8fd1b98cf5758bd303ff86393eb6d944c1058124bddce5d4e04b5395254d5ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fbfec84533f1c7680a000000000000000000000000000000000000000000000000079fe3710116b32aac0c0f8c8f8c4a09424a07a0e4c05bb872906c40844a75b76f6517467b79c12fa9cc6d79ae09934a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a02dbe9ff9cbbc4c5a6ff26971f75b405891141f4e9bce3c2dc4200a305138e584a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcfdf84533f1c3b80a0000000000000000000000000000000000000000000000000e0a6f8cf1d56031bc0c0f8c8f8c4a009aabea60cf7eaa9df4afdf4e1b5f3e684dab34fc9a9180a050085a4131ceedfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0436da067f9683029e717edf92da46c3443e8c342974f47a563302a0678efe702a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfd684533f1bfc80a00000000000000000000000000000000000000000000000005bc88c041662ffdac0c0f8c8f8c4a0f8b104093483b7c0182e1bba2ce3340d14469d3a3ee7646821223a676c680ac1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0d482e71cde61190a33ca5aeb88b6b06276984e5a14253a98df232e8767167221a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefd184533f1bce80a00000000000000000000000000000000000000000000000004aeb31823f6a1950c0c0f8c8f8c4a0dd1f0aba02c2bb3b5a2b6cb1cc907ea70912bd46dc7a78577f2cae6cdbcbe5f3a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a058ab6df33d7cbeb6a735a7e4ccf4f28143e6a1742e45dda8f8cf48af43cb66c0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd084533f1b9f80a0000000000000000000000000000000000000000000000000577042b0858b510bc0c0f8c8f8c4a0a287bb7da30f04344976abe569bd719f69c1cbea65533e5311ca5862e6eaa504a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07e0537009c23cb1152caf84a52272431f74b6140866b15805622b7bcb607cd42a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934783400fd384533f1b6180a000000000000000000000000000000000000000000000000083d31378a0993e1ac0c0f8c8f8c4a063483cff8fbd489e6ce273326d8dc1d54a31c67f936ca84bf500e5419d3e9805a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07737d08564819d51f8f834a6ee4278c23a0c2f29a3f485b21002c1f24f04d8e4a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd484533f1b5780a0000000000000000000000000000000000000000000000000bb586fe6de016e14c0c0f8c8f8c4a0975c8ed0c9197b7c018e02e1c95f315acf82b25e4a812140f4515e8bc827650ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ad51229abead59e93c80db5ba160f0939bc49dcee65d1c081f6eb040ff1f571fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefd984533f1b4e80a0000000000000000000000000000000000000000000000000548f02c6ceb26fd4c0c0f8c8f8c4a05844082e41f7c1f34485c7902afa0aa0979a6a849100fc553cd946f4a663929ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a01bc726443437c4c062be18d052278e4ef735b8fe84387c8a4fc85fb70d5078e0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd884533f1b1080a0000000000000000000000000000000000000000000000000cc1e528f54f22bdac0c0f8c8f8c4a0ba06ba81c93faaf98ea2d83cbdc0788958d938b29a9eb2a92ffbd4a628b3d52ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a05053bfe1c0f1f0dd341c6df35e5a659989be041e8521027cc90f7605eb15fbb9a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefdd84533f1b0380a0000000000000000000000000000000000000000000000000bcf9df2fec615ecac0c0f8c8f8c4a083732d997db15109e90464c24b7c959a78881d827c55a0d668a66a2736be5d87a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a054f4012cba33a2b80b0dca9dd52f56b2c588133bd71700863f8cb95127176634a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffdc84533f1a4680a00000000000000000000000000000000000000000000000006920a1dc9d915d0ec0c0f8c8f8c4a052e2fba761c2d0643170ef041c017391e781190fe715ae87cdae8eee1d45d95ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ee2c82f77d7afd1f8dbe4f791df8477496c23e5504b9d66814172077f65f81f2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefe184533f1a3880a0000000000000000000000000000000000000000000000000ae86da9012398fc4c0c0f8c8f8c4a055703ba09544f386966b6d63bfc31033b761a4d1a6bb86b0cf49b4bb0526744ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a01684c03a675b53786f0077d1651c3d169a009b13a6ee2b5047be6dbbe6d957ffa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfea84533f1a2f80a00000000000000000000000000000000000000000000000003247320d0eb639dfc0c0f8c8f8c4a05109a79b33d81f4ee4814b550fb0002f03368d67570f6d4e6105fce2874d8b72a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ae72e8c60a3dcfd53deecdb2790d18f0cc710f77cf2c1ed76e7da829bde619dca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcff784533f1a1d80a000000000000000000000000000000000000000000000000040e0bc9bc9bcf295c0c0f8c8f8c4a03961e4bbba5c95fad3db0cffa3a16b9106f9ea3e8957993eab576b683c22f416a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0e9c6cf457bbe64d6bda67852a276cdbadb4f384a36d496e81801a496cfd9b7b5a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfee84533f19df80a0000000000000000000000000000000000000000000000000dbb3fd6c816776d8c0c0f8c8f8c4a06b8265a357cb3ad744e19f04eb15377f660c10c900cc352d24f9b09073a363d6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07ba07e1bc6a20ffa44ae6080d30982b9faa148faf6b1ec15e32d89ac853ac291a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefe984533f198d80a00000000000000000000000000000000000000000000000005171325b6a2f17f1c0c0f8c8f8c4a0dcdc0347bb87ce72d49ac2e4e11f89069509b129a2536bf3d57c6bca30894032a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ca24447aa0cedb4b561c7810461eef19b16a827c27352e5e01f914e9d7c78247a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffe884533f194680a0000000000000000000000000000000000000000000000000da4714cfed9d8bbcc0c0f8c8f8c4a047f2dd6c15ea4082b3e11e5cf6b925b27e51d9de68051a093e52ef465cffbb8ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a05a7206edddf50fcfeeaa97348a7112fc6edd0b5eacb44cf43d6a6c6b6609b459a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefed84533f193e80a0000000000000000000000000000000000000000000000000ffafba4bf8dc944ec0c0f8c8f8c4a04d5ad6d860772145872f6660ecefcb0b0b2056e0aa3509a48bf4c175459e5121a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a00f4659d09bb2ced56e7fd9c4d3d90daca8b4f471307b7c4385fd34a41016b0b2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdff684533f192580a000000000000000000000000000000000000000000000000090620e5e59a39fe5c0c0f8c8f8c4a0c1725c58d1bf023af468e0088db3cf642ae097cf2c58c2ece2fc746980acc7e6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0be19a182ea1584050deb0a79abdc11be896ce8d00a282bcfaf9ffcd65fd64d6aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833feff184533f189080a000000000000000000000000000000000000000000000000076f17f4199bccd12c0c0f8c8f8c4a0bd521a20a18ca6ca7115065065a1aa20067ee580fb11e2963d1e3a681e8302afa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a011be45633350e39475a1a07712ba72de4602d9eebf639ccd5422a389095ccaf1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdffa84533f187b80a00000000000000000000000000000000000000000000000000c71b81c4a4cb82cc0c0f8c8f8c4a07c6d2d56e9c87f1553e4d06705af61a7c19a6046d2c39f8ed1417988783d3b1da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a012f5f0668063509e33a45a64eb6a072b2d84aa19f430f49f159be5008a786b2ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fd00684533f186080a0000000000000000000000000000000000000000000000000b3f962892cfec9e6c0c0f8c8f8c4a07154f0f8ecc7f791d22eec06ec86d87a44b2704f015b3d2cff3571a3d01ae0f6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a079536abf8e163cf8aa97f0d52866d04363902d591fd7c36aa35fc983d45fefd6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdffd84533f182f80a0000000000000000000000000000000000000000000000000736716e42499890fc0c0f8c8f8c4a0bf2fb1ee988ac4e17eae221a24176649774333fab25b6fc96c6081527fb6f121a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a041578daae7bcccd4976340aeb19e4132d2fe4193a0d92f87744c82bfe113502fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fd00984533f182b80a00000000000000000000000000000000000000000000000001c62fa76645942c6c0c0f8c8f8c4a07f84873e2679d40458b9dda9900478a78871044e08f6b47dad659b9b60ff8d48a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0597d3f4160770c0492333f90bad739dc05117d0e478a91f09573742e432904e8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fe00184533f17f680a0000000000000000000000000000000000000000000000000e24d8b1140fb34d5c0c0f8c8f8c4a0fd77bd13a8cde1766537febe751a27a2a31310a04638a1afcd5e8ad3c5485453a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0473b2b248d91010ba9aec2696ffc93c11c415ed132832be0fd0578f184862e13a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833feffc84533f17ca80a0000000000000000000000000000000000000000000000000fb5b65bac3f0d947c0c0f8c8f8c4a0518916dfb79c390bd7bff75712174512c2f96bec42a3f573355507ad1588ce0ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a08599d2ec9e95ec62f41a4975b655d8445d6767035f94eb235ed5ebea976fb9eaa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fe00484533f17b880a0000000000000000000000000000000000000000000000000bc27f4b8a201476bc0c0f90319f8c4a0ab6b9a5613970faa771b12d449b2e9bb925ab7a369f0a4b86b286e9d540099cfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0990dc3b5acbee04124361d958fe51acb582593613fc290683940a0769549d3eda09bfe4817d274ea3eb8672e9fe848c3885b53bbbd1d7c26e6039f90fb96b942b0833ff00084533f16b780a000000000000000000000000000000000000000000000000077377adff6c227dbf9024ff89d80809400000000000000000000000000000000000000008609184e72a000822710b3606956330c0d630000003359366000530a0d630000003359602060005301356000533557604060005301600054630000000c5884336069571ca07f6eb94576346488c6253197bde6a7e59ddc36f2773672c849402aa9c402c3c4a06d254e662bf7450dd8d835160cbb053463fed0b53f2cdd7f3ea8731919c8e8ccf9010501809400000000000000000000000000000000000000008609184e72a000822710b85336630000002e59606956330c0d63000000155933ff33560d63000000275960003356576000335700630000005358600035560d630000003a590033560d63000000485960003356573360003557600035335700b84a7f4e616d65526567000000000000000000000000000000000000000000000000003057307f4e616d655265670000000000000000000000000000000000000000000000000057336069571ba04af15a0ec494aeac5b243c8a2690833faa74c0f73db1f439d521c49c381513e9a05802e64939be5a1f9d4d614038fbd5479538c48795614ef9c551477ecbdb49d2f8a6028094ccdeac59d35627b7de09332e819d5159e7bb72508609184e72a000822710b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d0aceee7e5ab874e22ccf8d1a649f59106d74e81ba0d05887574456c6de8f7a0d172342c2cbdd4cf7afe15d9dbb8b75b748ba6791c9a01e87172a861f6c37b5a9e3a5d0d7393152a7fbe41530e5bb8ac8f35433e5931bc0"; + byte[] payload = Hex.decode(blocksMsg); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + RLPList.recursivePrint(rlpList); + // TODO: add some asserts in place of just printing the rlpList + } + + @Test /* hello msg */ + public void test14(){ + + String helloMsg= "f8 91 80 0b 80 b8 46 45 74 68 65 72 65 75 6d 28 2b 2b 29 2f 5a 65 72 6f 47 6f 78 2e 70 72 69 63 6b 6c 79 5f 6d 6f 72 73 65 2f 76 30 2e 34 2e 32 2f 52 65 6c 65 61 73 65 2d 57 69 6e 33 32 2f 57 69 6e 64 6f 77 73 2f 56 53 32 30 31 33 07 82 76 5f b8 40 ea 99 2c 13 68 7c 20 e7 90 a9 ff a6 df 8b 1a 16 86 88 e2 a8 87 36 5d 7a 50 21 86 fa 0d 62 20 e8 3e 11 3a 1f e7 7d c0 68 9d 55 ba 2e 8a 83 aa 8e 20 42 18 f4 d8 e7 32 82 5b d7 80 cf 94 ed 5c c3"; + byte[] payload = Hex.decode(helloMsg); + + RLPList rlpList = new RLPList(); + RLP.parseObjects(payload, rlpList); + + RLPList.recursivePrint(rlpList); + // TODO: add some asserts in place of just printing the rlpList + } + +} + + diff --git a/ethereumj-core/src/test/java/org/ethereum/serpent/TestCompile.java b/ethereumj-core/src/test/java/org/ethereum/serpent/TestCompile.java new file mode 100644 index 00000000..3997827a --- /dev/null +++ b/ethereumj-core/src/test/java/org/ethereum/serpent/TestCompile.java @@ -0,0 +1,1080 @@ +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 +*/ +public class TestCompile { + + +/* bin_expr + ['+', 2, 1, ['<1>', '<0>', 'ADD']], V + ['-', 2, 1, ['<1>', '<0>', 'SUB']], V + ['*', 2, 1, ['<1>', '<0>', 'MUL']], V + ['/', 2, 1, ['<1>', '<0>', 'DIV']], V + ['^', 2, 1, ['<1>', '<0>', 'EXP']], V + ['%', 2, 1, ['<1>', '<0>', 'MOD']], V + ['#/', 2, 1, ['<1>', '<0>', 'SDIV']], V + ['#%', 2, 1, ['<1>', '<0>', 'SMOD']], V +*/ + + @Test /* Test one symbol */ + public void test0() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A", retVal.getTemplate().toString()); + + } + + + + @Test /* Test ADD 1*/ + public void test1() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A + B"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A B ADD", retVal.getTemplate().toString()); + + } + + @Test /* Test ADD 2*/ + public void test2() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A + B + C1"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A B ADD C1 ADD", retVal.getTemplate().toString()); + + } + + @Test /* Test SUB 1*/ + public void test3() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A - B"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A B SUB", retVal.getTemplate().toString()); + + } + + @Test /* Test MUL 1*/ + public void test4() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A * B"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A B MUL", retVal.getTemplate().toString()); + + } + + + @Test /* Test DIV 1*/ + public void test5() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A / B"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A B DIV", retVal.getTemplate().toString()); + + } + + @Test /* Test EXP 1*/ + public void test6() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A ^ B"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A B EXP", retVal.getTemplate().toString()); + + } + + @Test /* Test MOD 1*/ + public void test7() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A % B"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A B MOD", retVal.getTemplate().toString()); + } + + @Test /* Test SDIV 1*/ + public void test8() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A #/ B"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A B SDIV", retVal.getTemplate().toString()); + + } + + @Test /* Test SMOD 1*/ + public void test9() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A #% B"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A B SMOD", retVal.getTemplate().toString()); + + } + + + @Test /* Test multi binary operators 1*/ + public void test10() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A / B - C + D * ET"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("A B DIV C SUB D ADD ET MUL", retVal.getTemplate().toString()); + + } + + @Test /* Test multi binary operators 2*/ + public void test11() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A / B - C + D * ET % ET2 ^ RO + RO2 #/ COOL #% HOT"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + 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", + retVal.getTemplate().toString()); + + } + + +/* + ['==', 2, 1, ['<1>', '<0>', 'EQ']], V + ['<', 2, 1, ['<1>', '<0>', 'LT']], V + ['<=', 2, 1, ['<1>', '<0>', 'GT', 'NOT']], V + ['>', 2, 1, ['<1>', '<0>', 'GT']], V + ['>=', 2, 1, ['<1>', '<0>', 'LT', 'NOT']], V + ['!', 1, 1, ['<0>', 'NOT']], V +*/ + + @Test /* Test '==' 1*/ + public void test12() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A + B == B + A"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.cond_expr_return retVal = parser.cond_expr(); + + Assert.assertEquals("A B ADD B A ADD EQ", + retVal.getTemplate().toString()); + + } + + @Test /* Test '<' 1*/ + public void test13() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A + C < C + A"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.cond_expr_return retVal = parser.cond_expr(); + + Assert.assertEquals("A C ADD C A ADD LT", + retVal.getTemplate().toString()); + + } + + @Test /* Test '<=' 1*/ + public void test14() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A + C <= C + A"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.cond_expr_return retVal = parser.cond_expr(); + + Assert.assertEquals("A C ADD C A ADD GT NOT", + retVal.getTemplate().toString()); + + } + + + @Test /* Test '>' 1*/ + public void test15() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A + C > C + A"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.cond_expr_return retVal = parser.cond_expr(); + + Assert.assertEquals("A C ADD C A ADD GT", + retVal.getTemplate().toString()); + + } + + + @Test /* Test '>=' 1*/ + public void test16() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A + C >= C + A"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.cond_expr_return retVal = parser.cond_expr(); + + Assert.assertEquals("A C ADD C A ADD LT NOT", + retVal.getTemplate().toString()); + + } + + @Test /* Test '!' 1 */ + public void test17() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "!A"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.unr_expr_return retVal = parser.unr_expr(); + + Assert.assertEquals("A NOT", + retVal.getTemplate().toString()); + + } + + + @Test /* Test '!' 2 */ + public void test18() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "!!A"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.unr_expr_return retVal = parser.unr_expr(); + + Assert.assertEquals("A NOT NOT", + retVal.getTemplate().toString()); + + } + + @Test /* Test '!' 3 */ + public void test19() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.unr_expr_return retVal = parser.unr_expr(); + + Assert.assertEquals("A NOT NOT", + retVal.getTemplate().toString()); + + } + + @Test /* Test '!' 4 */ + public void test20() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "!!!!!!!!!A"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.unr_expr_return retVal = parser.unr_expr(); + + Assert.assertEquals("A NOT", + retVal.getTemplate().toString()); + + } + + + @Test /* Test set var '=' 1 */ + public void test21() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A=10 \n B=20 \n C=30"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.program_return retVal = parser.program(); + + Assert.assertEquals("10 0 MSTORE 20 32 MSTORE 30 64 MSTORE", + retVal.getTemplate().toString().trim()); + + } + + @Test /* Test set var '=' 2 */ + public void test22() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "A=10 \n B=20 \n A=30 \n B=40"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.program_return retVal = parser.program(); + + Assert.assertEquals("10 0 MSTORE 20 32 MSTORE 30 0 MSTORE 40 32 MSTORE", + retVal.getTemplate().toString().trim()); + + } + + @Test /* Test if stmt 1 */ + public void test23() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "if a==10:\n b=20 \nelse: \n b=30"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.if_else_stmt_return retVal = parser.if_else_stmt(); + + Assert.assertEquals("", + retVal.getTemplate().toString().trim()); + + } + + @Test /* Test contract.storage[x] 1 */ + public void test24() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "contract.storage[0]"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.storage_load_return retVal = parser.storage_load(); + + Assert.assertEquals("0 SLOAD", + retVal.getTemplate().toString().trim()); + } + + @Test /* Test contract.storage[x] 2 */ + public void test25() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "contract.storage[100]"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.storage_load_return retVal = parser.storage_load(); + + Assert.assertEquals("100 SLOAD", + retVal.getTemplate().toString().trim()); + } + + @Test /* Test contract.storage[x]=y 1 */ + public void test26() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "contract.storage[100]=200"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.storage_save_return retVal = parser.storage_save(); + + Assert.assertEquals("200 100 SSTORE", + retVal.getTemplate().toString().trim()); + } + + @Test /* Test contract.storage[x]=y 1_ */ + public void test26_1() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "contract.storage[3+4]=200"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.storage_save_return retVal = parser.storage_save(); + + Assert.assertEquals("200 3 4 ADD SSTORE", + retVal.getTemplate().toString().trim()); + } + + + @Test /* Test contract.storage[x]=y 2 */ + public void test27() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "contract.storage[100]=200+100"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.storage_save_return retVal = parser.storage_save(); + + Assert.assertEquals("200 100 ADD 100 SSTORE", // todo: have to optimize it somewhere in the future + retVal.getTemplate().toString().trim()); + } + + @Test /* Test msg.data[x] 1 */ + public void test28() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "msg.data[0]"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.msg_load_return retVal = parser.msg_load(); + + Assert.assertEquals("0 32 MULL CALLDATALOAD", + retVal.getTemplate().toString().trim()); + } + + @Test /* Test msg.data[x] 2 */ + public void test29() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "msg.data[10+ 20]"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.msg_load_return retVal = parser.msg_load(); + + Assert.assertEquals("10 20 ADD 32 MUL CALLDATALOAD", + retVal.getTemplate().toString().trim()); + } + + @Test /* Test msg.data[x] 3 */ + public void test30() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "msg.data[0] + msg.data[2]"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.bin_expr_return retVal = parser.bin_expr(); + + Assert.assertEquals("0 32 MUL CALLDATALOAD 2 32 MUL CALLDATALOAD ADD", + retVal.getTemplate().toString().trim()); + } + + + @Test /* Test multi */ + public void test31() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "contract.storage[msg.data[0]] = msg.data[1]\n" + + ""); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.storage_save_return retVal = parser.storage_save(); + + Assert.assertEquals("1 32 MUL CALLDATALOAD 0 32 MUL CALLDATALOAD SSTORE", + retVal.getTemplate().toString().trim()); + } + + @Test /* Test multi */ + public void test32() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "!contract.storage[msg.data[0]]"); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.unr_expr_return retVal = parser.unr_expr(); + + Assert.assertEquals("0 32 MUL CALLDATALOAD SLOAD NOT", + retVal.getTemplate().toString().trim()); + } + + @Test /* Test get_var 1 */ + public void test33() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "a=20\nb=20\nb=="); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.test_1_return retVal = parser.test_1(); + + Assert.assertEquals("20 0 MSTORE 20 32 MSTORE 32 MLOAD", + retVal.getTemplate().toString().trim()); + } + + @Test /* Test get_var 2 */ + public void test34() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "a1=20\nb4=20\n\na4=20\na4=="); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.test_1_return retVal = parser.test_1(); + + Assert.assertEquals("20 0 MSTORE 20 32 MSTORE 20 64 MSTORE 64 MLOAD", + retVal.getTemplate().toString().trim()); + } + + @Test /* Test if_stmt with (!)cond */ + public void test35() throws FileNotFoundException, RecognitionException { + + CharStream stream = + new ANTLRStringStream("" + + "if !contract.storage[msg.data[0]]:\n" + + " contract.storage[msg.data[0]] = msg.data[1]\n" + + " return(1)\n" + + "else:\n" + + " return(0)\n"); + + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.if_else_stmt_return retVal = parser.if_else_stmt(); + + Assert.assertEquals("", + retVal.getTemplate().toString().trim()); + } + + + @Test /* Test complex contract with if_else_stmt inside else body */ + public void test36() throws FileNotFoundException, RecognitionException { + + + CharStream stream = + new ANTLRStringStream("" + + " contract.storage[0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826] = 1000000\n" + + " if msg.datasize == 1:\n" + + " addr = msg.data[0]\n" + + " return(contract.storage[addr])\n" + + " else:\n" + + " from = msg.sender\n" + + " fromvalue = contract.storage[from]\n" + + " to = msg.data[0]\n" + + " value = msg.data[1]\n" + + " if fromvalue >= value:\n" + + " contract.storage[from] = fromvalue - value\n" + + " contract.storage[to] = contract.storage[to] + value\n" + + " return(1)\n" + + " else:\n" + + " return(0)\n"); + + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.gen_body_return retVal = parser.gen_body(); + + Assert.assertEquals("", + retVal.getTemplate().toString().trim()); + } + + + @Test /* Test for hex number */ + public void test37() throws FileNotFoundException, RecognitionException { + + String hexNum = "0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826"; + + CharStream stream = + new ANTLRStringStream(hexNum); + + SerpentLexer lex = new SerpentLexer(stream); + 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"; + + StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), + AngleBracketTemplateLexer.class); + parser.setTemplateLib(template); + + SerpentParser.hex_num_return retVal = parser.hex_num(); + + Assert.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 new file mode 100644 index 00000000..aafd0487 --- /dev/null +++ b/ethereumj-core/src/test/java/org/ethereum/transaction/TransactionTest.java @@ -0,0 +1,128 @@ +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 + */ +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 cowPrivKey = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4"; + + 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_)); + + + + } + + + + @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)); + System.out.println(txHash); + + + + + + } + +}