[Pixelle-commit] SF.net SVN: pixelle: [131] trunk/pixelle/etc/Pixelle.g
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-07-04 15:28:00
|
Revision: 131
http://pixelle.svn.sourceforge.net/pixelle/?rev=131&view=rev
Author: dbrosius
Date: 2008-07-04 08:27:48 -0700 (Fri, 04 Jul 2008)
Log Message:
-----------
add unary expression support for - expr and ! expr
Modified Paths:
--------------
trunk/pixelle/etc/Pixelle.g
Modified: trunk/pixelle/etc/Pixelle.g
===================================================================
--- trunk/pixelle/etc/Pixelle.g 2008-07-04 04:23:19 UTC (rev 130)
+++ trunk/pixelle/etc/Pixelle.g 2008-07-04 15:27:48 UTC (rev 131)
@@ -80,10 +80,10 @@
cond_and_expr
( '?'
{
- mv.visitInsn(Opcodes.DCONST_1); //TRUE
+ mv.visitInsn(Opcodes.DCONST_0); //FALSE
mv.visitInsn(Opcodes.DCMPG);
falseLabel = new Label();
- mv.visitJumpInsn(Opcodes.IFNE, falseLabel);
+ mv.visitJumpInsn(Opcodes.IFEQ, falseLabel);
}
expr ':'
{
@@ -249,18 +249,38 @@
)* ;
mul_expr :
- factor
- (op=('*' | '/') factor
+ unaryExpression
+ (op=('*' | '/') unaryExpression
{
mv.visitInsn("*".equals($op.text)?Opcodes.DMUL:Opcodes.DDIV);
}
)* ;
+unaryExpression :
+ '!' unaryExpression
+ {
+ Label falseLabel = new Label();
+ Label continueLabel = new Label();
+ mv.visitInsn(Opcodes.DCONST_0);
+ mv.visitInsn(Opcodes.DCMPG);
+ mv.visitJumpInsn(Opcodes.IFEQ, falseLabel);
+ mv.visitInsn(Opcodes.DCONST_0);
+ mv.visitJumpInsn(Opcodes.GOTO, continueLabel);
+ mv.visitLabel(falseLabel);
+ mv.visitInsn(Opcodes.DCONST_1);
+ mv.visitLabel(continueLabel);
+ }
+ | '-' unaryExpression
+ {
+ mv.visitInsn(Opcodes.DNEG);
+ }
+ | factor ;
+
factor
: NUMBER
{
mv.visitLdcInsn(Double.valueOf($NUMBER.text));
- }
+ }
| '(' expr ')'
| 'p'
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|