Permalink
Browse files

initial import.

C API is at alpha stage
Java API is at beta stage
C++ API doesn't exist yet


git-svn-id: https://tinyap.googlecode.com/svn/trunk@2 26adf5cf-fd31-0410-b5e7-cb6bf36da140
  • Loading branch information...
damien.leroux
damien.leroux committed Jun 3, 2007
1 parent 18cb91f commit 93c530494e97284de087d74afe051e907f2a483b
Showing with 4,715 additions and 0 deletions.
  1. +340 −0 COPYING
  2. +1,252 −0 Doxyfile
  3. 0 Java/.clean
  4. +340 −0 Java/COPYING
  5. +45 −0 Java/Demo.java
  6. +99 −0 Java/Interpreter.java
  7. +71 −0 Java/Makefile
  8. +184 −0 Java/Panneau.java
  9. +20 −0 Java/demo.sh
  10. +22 −0 Java/javaconfig.sh
  11. +96 −0 Java/parsing/AST.java
  12. +43 −0 Java/parsing/TinyaJP.java
  13. +170 −0 Java/parsing_AST.c
  14. +85 −0 Java/parsing_AST.h
  15. +13 −0 Java/parsing_AST_Node.h
  16. +192 −0 Java/parsing_TinyaJP.c
  17. +53 −0 Java/parsing_TinyaJP.h
  18. +4 −0 Java/test.math
  19. +27 −0 Makefile
  20. +40 −0 ast.c
  21. +209 −0 ast.h
  22. +102 −0 bootstrap.c
  23. +26 −0 bootstrap.h
  24. +301 −0 main.c
  25. +68 −0 math.gram
  26. +38 −0 notes.txt
  27. +262 −0 serialize.c
  28. +533 −0 tokenizer.c
  29. +80 −0 tokenizer.h
View
340 COPYING

Large diffs are not rendered by default.

Oops, something went wrong.
View
1,252 Doxyfile

Large diffs are not rendered by default.

Oops, something went wrong.
View
No changes.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,45 @@
+/* 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 parsing.AST;
+import parsing.TinyaJP;
+import java.lang.*;
+import java.awt.*;
+import javax.swing.*;
+import javax.swing.tree.*;
+import java.awt.event.*;
+
+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.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
@@ -0,0 +1,99 @@
+/* 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 parsing.AST;
+import parsing.TinyaJP;
+
+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(AST.Node n) {
+ if(n.getNodeAt(0).getString().equals("number")) {
+ return Double.valueOf(n.getNodeAt(1).getString());
+ } else if(n.getNodeAt(0).getString().equals("m_minus")) {
+ return - test_math_ast(n.getNodeAt(1));
+ } else if(n.getNodeAt(0).getString().equals("m_expr")) {
+ return test_math_ast(n.getNodeAt(1));
+ } else if(n.getNodeAt(0).getString().equals("m_add")) {
+ return test_math_ast(n.getNodeAt(1))
+ + test_math_ast(n.getNodeAt(2));
+ } else if(n.getNodeAt(0).getString().equals("m_sub")) {
+ return test_math_ast(n.getNodeAt(1))
+ - test_math_ast(n.getNodeAt(2));
+ } else if(n.getNodeAt(0).getString().equals("m_mul")) {
+ return test_math_ast(n.getNodeAt(1))
+ * test_math_ast(n.getNodeAt(2));
+ } else if(n.getNodeAt(0).getString().equals("m_div")) {
+ return test_math_ast(n.getNodeAt(1))
+ / test_math_ast(n.getNodeAt(2));
+ } else {
+ System.out.println("opérateur inconnu "+n.getNodeAt(0).getString());
+ return 0;
+ }
+ }
+
+ static void dump_node_rec(AST.Node 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.size();i++) {
+ dump_node_rec(n.getNodeAt(i),ofs+" ");
+ }
+ System.out.println(ofs+" ]");
+ }
+ }
+
+ /* proxy pour dump_node_rec */
+ static void dump_nodes(AST.Node 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
@@ -0,0 +1,71 @@
+TARGETS=libparsing_TinyaJP.so libparsing_AST.so
+
+JAR_TARGET=tinyajp.jar
+
+OBJECTS=../ast.o ../bootstrap.o ../tokenizer.o ../serialize.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_LIB_SOURCES =$(TARGETS) libparsing.so
+JAR_FILES= \
+ $(JAR_CLASSES) \
+ $(JAR_LIB_SOURCES) \
+ $(JAR_LIB_CLASSES) \
+ parsing/AST.class \
+ parsing/TinyaJP.class
+
+
+#CARGS=$(JINC) -ggdb
+CARGS=$(JINC) -O3
+CC=gcc
+C=$(CC) $(CARGS) $(CADD)
+
+LDARGS=-shared
+LD=gcc
+L=$(LD) $(LDARGS)
+
+all: $(JAR_TARGET)
+
+parsing/AST.class: parsing/AST.java
+ $(JAVAC) $<
+
+parsing/TinyaJP.class: parsing/TinyaJP.java
+ $(JAVAC) $<
+
+parsing_AST.h: parsing/AST.class
+ $(JAVAH) parsing.AST
+
+parsing_TinyaJP.h: parsing/TinyaJP.class
+ $(JAVAH) parsing.TinyaJP
+
+$(TARGETS):lib%.so: %.c %.h libparsing.so
+ $C -c $< -o $<.o
+ $L $<.o libparsing.so -o $@
+
+libparsing.so: $(OBJECTS)
+ $L $(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) parsing/AST$$Node.class Panneau$$HeadPhones.class
+ @rm -f $@
+ $(JAR) cvf $@ -m $(JAR_FILES) parsing/AST\$$Node.class Panneau\$$HeadPhones.class
+
+
Oops, something went wrong.

0 comments on commit 93c5304

Please sign in to comment.