Permalink
Browse files

Reorganizing repository, step two.

  • Loading branch information...
1 parent cebabbe commit c40f183790a0df585559a8c383f8b0cc3ebb6852 @bl0b committed Sep 9, 2012
View
No changes.
View
No changes.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,46 +0,0 @@
-/* Tinya(J)P : this is not yet another (Java) parser.
- * Copyright (C) 2007 Damien Leroux
- *
- * 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 2
- * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-import java.lang.*;
-import java.awt.*;
-import javax.swing.*;
-import javax.swing.tree.*;
-import java.awt.event.*;
-
-import tinyajp.AstNode;
-import tinyajp.Parser;
-
-public class Demo {
- static public void main(String[] args) {
- Panneau demo=new Panneau();
- JFrame frame=new JFrame("TinyaJP demo");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- frame.setContentPane(demo);
- frame.setSize(400,600);
- frame.pack();
-
- try {
- java.io.FileReader fGram=new java.io.FileReader("math.CC.gram");
- String cbuf=new String();
- int c=0;
- while((c=fGram.read())!=-1) cbuf+=(char)c;
- demo.setGrammar(cbuf);
- } catch(java.io.IOException e) {}
- frame.setVisible(true);
- }
-}
View
@@ -1,101 +0,0 @@
-/* Tinya(J)P : this is not yet another (Java) parser.
- * Copyright (C) 2007 Damien Leroux
- *
- * 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 2
- * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-import tinyajp.AstNode;
-import tinyajp.Parser;
-
-public class Interpreter {
- static String readString() {
- String ret=new String();
- char c;
-
- try {
-
- c=(char)System.in.read();
- while(c!='\n') {
- ret+=c;
- c=(char)System.in.read();
- }
-
- } catch(java.io.IOException e) {}
-
- return ret;
- }
-
-
- static double test_math_ast(AstNode n) {
- if(n==null||(!n.isOp())) {
- return 0;
- } else if(n.getOperator().equals("Number")) {
- return Double.valueOf(n.getOperand(0).getString());
- } else if(n.getOperator().equals("MathMinus")) {
- return - test_math_ast(n.getOperand(0));
- } else if(n.getOperator().equals("MathExpr")) {
- return test_math_ast(n.getOperand(0));
- } else if(n.getOperator().equals("MathAdd")) {
- return test_math_ast(n.getOperand(0))
- + test_math_ast(n.getOperand(1));
- } else if(n.getOperator().equals("MathSub")) {
- return test_math_ast(n.getOperand(0))
- - test_math_ast(n.getOperand(1));
- } else if(n.getOperator().equals("MathMul")) {
- return test_math_ast(n.getOperand(0))
- * test_math_ast(n.getOperand(1));
- } else if(n.getOperator().equals("MathDiv")) {
- return test_math_ast(n.getOperand(0))
- / test_math_ast(n.getOperand(1));
- } else {
- System.out.println("opérateur inconnu "+n.getOperator());
- return 0;
- }
- }
-
- static void dump_node_rec(AstNode n, String ofs) {
- if(n==null) {
- System.out.println(ofs+"#nil");
- } else if(n.isString()) {
- System.out.println(ofs+n.getString());
- } else {
- System.out.println(ofs+" [");
- /* n.isList()==true */
- for(int i=0;i<=n.getOperandCount();i++) {
- dump_node_rec(n.getOperand(i),ofs+" ");
- }
- System.out.println(ofs+" ]");
- }
- }
-
- /* proxy pour dump_node_rec */
- static void dump_nodes(AstNode n) {
- dump_node_rec(n,"");
- }
-
-/* static String readString() {
- String str=new String();
- int ret;
- try {
- ret=System.in.read();
- while(ret!=-1&&ret!='\n') {
- str+=(char)ret;
- ret=System.in.read();
- }
- } catch(java.io.IOException ioe) {
- }
- return str;
- }
-*/
-}
View
@@ -1,64 +0,0 @@
-TARGET=libtinyajp_Native.so
-
-JAR_TARGET=tinyajp.jar
-
-OBJECTS=../ast.o ../bootstrap.o ../tokenizer.o ../serialize.o ../tinyap.o
-SOURCES=$(subst .o,.c,$(OBJECTS))
-
-# java lacks pkg-config support
-JINC=$(shell ./javaconfig.sh --include)
-JAVAC=$(shell which javac||echo "erreur : pas de javac dans le PATH"&&exit -1)
-JAVAH=$(shell which javah||echo "erreur : pas de javah dans le PATH"&&exit -1)
-JAR=$(shell which jar||echo "erreur : pas de jar dans le PATH"&&exit -1)
-
-
-JAR_SOURCES=Demo.java Interpreter.java Panneau.java
-JAR_CLASSES=$(subst .java,.class,$(JAR_SOURCES))
-
-JAR_FILES= \
- $(JAR_CLASSES) \
- $(JAR_LIB_CLASSES) \
- tinyajp/AstNode.class \
- tinyajp/Parser.class \
- tinyajp/Native.class
-
-
-#CARGS=$(JINC) -ggdb
-CARGS=$(JINC) -O3
-CC=gcc
-C=$(CC) $(CARGS) $(CADD)
-
-LDARGS=-shared
-LD=gcc
-L=$(LD) $(LDARGS)
-
-all: $(OBJECTS) $(JAR_TARGET)
-
-$(OBJECTS):
- cd ..&&make $(subst ../,,$(OBJECTS))
-
-tinyajp/Native.class: tinyajp/Native.java
- $(JAVAC) $<
-
-tinyajp_Native.h: tinyajp/Native.class
- $(JAVAH) tinyajp.Native
-
-$(TARGET):lib%.so: %.c %.h $(OBJECTS)
- $C -c $< -o $<.o
- $L $<.o $(OBJECTS) -o $@
-
-$(JAR_LIB_CLASSES) $(JAR_CLASSES):%.class:%.java
- $(JAVAC) $<
-
-.PHONY: clean
-
-clean:
- rm -f $(OBJECTS) $(JAR_FILES) libparsing.so *.class *~ .*.sw? *.bak
-
-mr-proper:
-
-$(JAR_TARGET): $(JAR_FILES) $(TARGET)
- @rm -f $@
- $(JAR) cvf $@ -m $(JAR_FILES)
-
-
View
@@ -1,182 +0,0 @@
-/* Tinya(J)P : this is not yet another (Java) parser.
- * Copyright (C) 2007 Damien Leroux
- *
- * 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 2
- * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-import tinyajp.AstNode;
-import tinyajp.Parser;
-import java.lang.*;
-import java.awt.*;
-import javax.swing.*;
-import javax.swing.tree.*;
-import java.awt.event.*;
-
-public class Panneau extends JPanel {
- private JTree resultAST;
- private JTextArea result;
- private DefaultMutableTreeNode astRoot;
- private JTextArea grammar;
- private JTextField input;
- private JPanel resultPanel;
- private JSplitPane splitPane;
- private Font font;
-
- private String prettyNode(AstNode n) {
- String name;
- if(n.isString()) {
- name=n.getString();
- } else if(n.isList()) {
- name=n.getElementAt(0).getString();
- } else {
- name="oups";
- }
- return name+" ["+n.getRow()+","+n.getCol()+"]";
- }
-
- private class HeadPhones implements ActionListener {
- public void actionPerformed(ActionEvent ae) {
- String expr;
-
- expr=Panneau.this.input.getText();
- if(expr.equals("quit")) {
- System.exit(0);
- }
-
- Parser parser=new Parser();
-
- parser.setGrammar("CamelCasing")
- .setSourceBuffer(Panneau.this.grammar.getText())
- .parseAsGrammar();
-
- if(!parser.parsedOK()) {
- Panneau.this.showError(parser.getErrorRow(),parser.getErrorCol(),parser.getError());
- return;
- }
-
- parser.setSourceBuffer(expr).parse();
-
- if(!parser.parsedOK()) {
- Panneau.this.showError(parser.getErrorRow(),parser.getErrorCol(),parser.getError());
- return;
- } else {
- AstNode n;
- double d;
- String resultats=new String();
- for(int i=0;i<parser.getOutput().getSize();i++) {
- n=parser.getOutput().getElementAt(i);
- if(n!=null) {
- d=Interpreter.test_math_ast(n);
- //dump_nodes(n);
- //System.out.println(" = "+d);
- resultats+=" = "+d+"\n";
-
- }
- }
- Panneau.this.showResult(parser.getOutput(),resultats);
- }
- }
- }
-
- public Panneau() {
- font=new Font("courier",0,12);
- JPanel inputPanel = new JPanel();
- setLayout(new BorderLayout());
-
- //resultPanel.setPreferredSize(new Dimension(350,500));
-
- grammar = new JTextArea();
- grammar.setFont(font);
- //grammar.setSize(300,100);
-
- input = new JTextField();
-
- inputPanel.setLayout(new BorderLayout());
- inputPanel.add(input,BorderLayout.SOUTH);
- inputPanel.add(new JLabel(
- "Enter an expression that will be parsed according to the above grammar, or 'quit' to quit"),
- BorderLayout.NORTH);
-
- input.addActionListener(new HeadPhones());
-
- //add(grammar,BorderLayout.NORTH);
- splitPane = new JSplitPane(
- JSplitPane.HORIZONTAL_SPLIT,
- new JPanel(), new JScrollPane(grammar));
- add(splitPane,BorderLayout.CENTER);
- //add(new JScrollPane(resultAST),BorderLayout.CENTER);
- //add(new JScrollPane(grammar),BorderLayout.EAST);
- add(inputPanel,BorderLayout.SOUTH);
- setVisible(true);
-
- setPreferredSize(new Dimension(800,600));
- }
-
- public void setGrammar(String g) {
- grammar.setText(g);
- }
-
- private void showRes_rec(DefaultMutableTreeNode p,AstNode n) {
- if(n.isString()) {
- p.add(new DefaultMutableTreeNode(prettyNode(n)));
- } else if(n.isList()) {
- DefaultMutableTreeNode op;
- if(n.getElementAt(0).isString()) {
- op=new DefaultMutableTreeNode(prettyNode(n));
- //System.out.println("w/ op");
- } else {
- op=new DefaultMutableTreeNode(new String("<nop>"));
- //System.out.println("w/o op");
- }
- //System.out.println("n.size = "+n.getSize());
- for(int i=1;i<n.getSize();i++) {
- showRes_rec(op,n.getElementAt(i));
- }
- p.add(op);
- } else if(n.isNil()) {
- p.add(new DefaultMutableTreeNode(new String("(nil)")));
- } else {
- System.out.println("oups");
- }
- }
-
- public void showResult(AstNode n,String res) {
- astRoot=new DefaultMutableTreeNode(new String("Result"));
- resultAST=new JTree(astRoot);
- result = new JTextArea();
- result.setEditable(false);
- result.setFont(font);
-
- //resultPanel.remove(resultAST);
- if(!(n==null||n.isNil())) {
- for(int i=0;i<n.getSize();i++) {
- showRes_rec(astRoot,n.getElementAt(i));
- }
- }
- result.setText(input.getText()+"\n"+res);
- result.repaint();
- input.setText("");
- resultPanel = new JPanel();
- resultPanel.setLayout(new BorderLayout());
- resultPanel.add(new JScrollPane(resultAST),BorderLayout.CENTER);
- resultPanel.add(result,BorderLayout.SOUTH);
- splitPane.setLeftComponent(resultPanel);
- resultPanel.repaint();
- }
-
- public void showError(int l,int c,String err) {
- showResult(AstNode.nil,"Parser : error at line "+l+", column "+c+" :\n"+err);
- }
-}
-
Oops, something went wrong.

0 comments on commit c40f183

Please sign in to comment.