[Pixelle-commit] SF.net SVN: pixelle: [9] trunk/pixelle/etc/Pixelle.g
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-06-18 02:30:56
|
Revision: 9
http://pixelle.svn.sourceforge.net/pixelle/?rev=9&view=rev
Author: dbrosius
Date: 2008-06-17 19:30:50 -0700 (Tue, 17 Jun 2008)
Log Message:
-----------
main grammar file
Added Paths:
-----------
trunk/pixelle/etc/Pixelle.g
Added: trunk/pixelle/etc/Pixelle.g
===================================================================
--- trunk/pixelle/etc/Pixelle.g (rev 0)
+++ trunk/pixelle/etc/Pixelle.g 2008-06-18 02:30:50 UTC (rev 9)
@@ -0,0 +1,87 @@
+/*
+ * pixelle - Graphics algorithmic editor
+ * Copyright (C) 2008 Dave Brosius
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+ grammar Pixelle;
+
+@header {
+package com.mebigfatguy.pixelle.antlr;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+}
+
+@lexer::header {
+package com.mebigfatguy.pixelle.antlr;
+}
+
+@members {
+ ClassWriter cw;
+ MethodVisitor mv;
+
+ public PixelleParser(CommonTokenStream tokens, String clsName) {
+ super(tokens, new RecognizerSharedState());
+
+ clsName = clsName.replace('.', '/');
+ cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
+ cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, clsName, null, "java/lang/Object", new String[] {"com/mebigfatguy/pixelle/PixelleExpr"});
+ mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[0]);
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
+ mv.visitInsn(Opcodes.RETURN);
+ mv.visitMaxs(0,0);
+ mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "eval", "(Lcom/mebigfatguy/pixelle/PixelEval;II)D", null, new String[0]);
+ }
+
+ public byte[] getClassBytes() {
+ mv.visitInsn(Opcodes.DRETURN);
+ mv.visitMaxs(0,0);
+ cw.visitEnd();
+ return cw.toByteArray();
+ }
+}
+
+pixelle : expr;
+
+expr
+ : term
+ ('+' term
+ {mv.visitInsn(Opcodes.DADD);}
+ | '-' term
+ {mv.visitInsn(Opcodes.DSUB);})*;
+
+term
+ : factor {}
+ ('*' factor
+ {mv.visitInsn(Opcodes.DMUL);}
+ | '/' factor
+ {mv.visitInsn(Opcodes.DDIV);})*;
+
+factor
+ : NUMBER
+ {mv.visitLdcInsn(Double.valueOf($NUMBER.text));}
+ | 'p' {mv.visitVarInsn(Opcodes.ALOAD, 1);} '[' expr { mv.visitInsn(Opcodes.D2I); } ',' expr { mv.visitInsn(Opcodes.D2I); } ']' '.' spec=('r'|'g'|'b'|'t'|'s') {String s = $spec.text; mv.visitLdcInsn(Character.valueOf(s.charAt(0))); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/mebigfatguy/pixelle/PixelEval", "getValue", "(IIC)D" );}
+ | 'x' {mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitInsn(Opcodes.I2D);}
+ | 'y' {mv.visitVarInsn(Opcodes.ILOAD, 3); mv.visitInsn(Opcodes.I2D);}
+ | 'width' {mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/mebigfatguy/pixelle/PixelEval", "getWidth", "()D" );}
+ | 'height' {mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/mebigfatguy/pixelle/PixelEval", "getHeight", "()D" );};
+
+NUMBER : '0'..'9'+ ( '.' ('0'..'9'+))?;
+
+NEWLINE:'\r'? '\n' ;
+
+
Property changes on: trunk/pixelle/etc/Pixelle.g
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|