diff --git a/pdp7parse/src/main/java/com/khubla/pdp7parse/LabelParseTreeListener.java b/pdp7parse/src/main/java/com/khubla/pdp7parse/LabelParseTreeListener.java new file mode 100644 index 0000000..9e8143d --- /dev/null +++ b/pdp7parse/src/main/java/com/khubla/pdp7parse/LabelParseTreeListener.java @@ -0,0 +1,54 @@ +package com.khubla.pdp7parse; +/* +* Copyright 2016, Tom Everett +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.tree.ErrorNode; +import org.antlr.v4.runtime.tree.ParseTreeListener; +import org.antlr.v4.runtime.tree.TerminalNode; + +import com.khubla.pdp7parse.antlr4.pdp7Parser.LabelContext; + +public class LabelParseTreeListener implements ParseTreeListener { + private final PDP7Metadata pdp7Metadata; + + public LabelParseTreeListener(PDP7Metadata pdp7Metadata) { + this.pdp7Metadata = pdp7Metadata; + } + + @Override + public void visitTerminal(TerminalNode node) { + // TODO Auto-generated method stub + } + + @Override + public void visitErrorNode(ErrorNode node) { + // TODO Auto-generated method stub + } + + @Override + public void enterEveryRule(ParserRuleContext ctx) { + if (ctx instanceof LabelContext) { + LabelContext labelContext = (LabelContext) ctx; + } + } + + @Override + public void exitEveryRule(ParserRuleContext ctx) { + // TODO Auto-generated method stub + } +} diff --git a/pdp7parse/src/main/java/com/khubla/pdp7parse/Opcode.java b/pdp7parse/src/main/java/com/khubla/pdp7parse/Opcode.java new file mode 100644 index 0000000..c449718 --- /dev/null +++ b/pdp7parse/src/main/java/com/khubla/pdp7parse/Opcode.java @@ -0,0 +1,109 @@ +package com.khubla.pdp7parse; + +/* + * Copyright 2016, Tom Everett + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +public class Opcode { + public static int dac = 0040000; + public static int jms = 0100000; + public static int dzm = 0140000; + public static int lac = 0200000; + public static int xor = 0240000; + public static int add = 0300000; + public static int tad = 0340000; + public static int xct = 0400000; + public static int isz = 0440000; + public static int and = 0500000; + public static int sad = 0540000; + public static int jmp = 0600000; + public static int nop = 0740000; + public static int i = 020000; + public static int law = 0760000; + public static int cma = 0740001; + public static int las = 0750004; + public static int ral = 0740010; + public static int rar = 0740020; + public static int hlt = 0740040; + public static int sma = 0740100; + public static int sza = 0740200; + public static int snl = 0740400; + public static int skp = 0741000; + public static int sna = 0741200; + public static int szl = 0741400; + public static int rtl = 0742010; + public static int rtr = 0742020; + public static int cll = 0744000; + public static int rcl = 0744010; + public static int rcr = 0744020; + public static int cla = 0750000; + public static int lrs = 0640500; + public static int lrss = 0660500; + public static int lls = 0640600; + public static int llss = 0660600; + public static int als = 0640700; + public static int alss = 0660700; + public static int mul = 0653323; + public static int idiv = 0653323; + public static int lacq = 0641002; + public static int clq = 0650000; + public static int omq = 0650002; + public static int cmq = 0650004; + public static int lmq = 0652000; + public static int dscs = 0707141; + public static int dslw = 0707124; + public static int dslm = 0707142; + public static int dsld = 0707104; + public static int dsls = 0707144; + public static int dssf = 0707121; + public static int dsrs = 0707132; + public static int iof = 0700002; + public static int ion = 0700042; + public static int caf = 0703302; + public static int clon = 0700044; + public static int clsf = 0700001; + public static int clof = 0700004; + public static int ksf = 0700301; + public static int krb = 0700312; + public static int tsf = 0700401; + public static int tcf = 0700402; + public static int tls = 0700406; + public static int sck = 0704301; + public static int cck = 0704304; + public static int lck = 0704312; + public static int rsf = 0700101; + public static int rsa = 0700104; + public static int rrb = 0700112; + public static int psf = 0700201; + public static int pcf = 0700202; + public static int psa = 0700204; + public static int cdf = 0700501; + public static int lds = 0701052; + public static int lda = 0701012; + public static int wcga = 0704206; + public static int raef = 0700742; + public static int rlpd = 0700723; + public static int beg = 0700547; + public static int spb = 0704401; + public static int cpb = 0704404; + public static int lpb = 0704412; + public static int wbl = 0704424; + public static int dprs = 0704752; + public static int dpsf = 0704741; + public static int dpcf = 0704761; + public static int dprc = 0704712; + public static int crsf = 0706701; + public static int crrb = 0706712; +} diff --git a/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Metadata.java b/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Metadata.java new file mode 100644 index 0000000..6b9fe10 --- /dev/null +++ b/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Metadata.java @@ -0,0 +1,24 @@ +package com.khubla.pdp7parse; + +import java.util.ArrayList; +import java.util.List; + +/* +* Copyright 2016, Tom Everett +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ +public class PDP7Metadata { + public List labels = new ArrayList(); +} diff --git a/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Parse.java b/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Parse.java index d12ebf1..2312287 100644 --- a/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Parse.java +++ b/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Parse.java @@ -1,5 +1,21 @@ package com.khubla.pdp7parse; +/* +* Copyright 2016, Tom Everett +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ import java.io.File; import java.io.FileInputStream; @@ -11,6 +27,8 @@ import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.commons.cli.PosixParser; +import com.khubla.pdp7parse.antlr4.pdp7Parser.ProgContext; + /** * @author tom */ @@ -48,7 +66,9 @@ public class PDP7Parse { final String inputFileName = cmd.getOptionValue(INPUT_FILE_OPTION); final File inputFile = new File(inputFileName); if (inputFile.exists()) { - PDP7Parser.parse(new FileInputStream(inputFile), System.out); + ProgContext progContext = PDP7Parser.parse(new FileInputStream(inputFile), System.out); + PDP7Metadata pdp7Metadata = new PDP7Metadata(); + PDP7Parser.analyse(progContext, pdp7Metadata); } } catch (final Exception e) { e.printStackTrace(); diff --git a/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Parser.java b/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Parser.java index 62aac41..f57e289 100644 --- a/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Parser.java +++ b/pdp7parse/src/main/java/com/khubla/pdp7parse/PDP7Parser.java @@ -1,4 +1,20 @@ package com.khubla.pdp7parse; +/* +* Copyright 2016, Tom Everett +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ import java.io.InputStream; import java.io.InputStreamReader; @@ -7,6 +23,7 @@ import java.io.Reader; import org.antlr.v4.runtime.ANTLRInputStream; import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.tree.ParseTreeWalker; import com.khubla.pdp7parse.antlr4.pdp7Lexer; import com.khubla.pdp7parse.antlr4.pdp7Parser; @@ -28,4 +45,9 @@ public class PDP7Parser { throw new Exception("Exception reading and parsing file", e); } } + + public static void analyse(ProgContext progContext, PDP7Metadata pdp7Metadata) { + ParseTreeWalker parseTreeWalker = new ParseTreeWalker(); + parseTreeWalker.walk(new LabelParseTreeListener(pdp7Metadata), progContext); + } } diff --git a/pdp7parse/src/test/java/com/khubla/pdp7parse/BasicTests.java b/pdp7parse/src/test/java/com/khubla/pdp7parse/BasicTests.java index 49aec60..ade4dea 100644 --- a/pdp7parse/src/test/java/com/khubla/pdp7parse/BasicTests.java +++ b/pdp7parse/src/test/java/com/khubla/pdp7parse/BasicTests.java @@ -1,5 +1,21 @@ package com.khubla.pdp7parse; +/* +* Copyright 2016, Tom Everett +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ import java.io.File; import java.io.FileInputStream; import java.io.InputStream;