Home | History | Annotate | Download | only in polydiff
      1 tree grammar PolyDifferentiator;
      2 options {
      3 	tokenVocab=Poly;
      4     language=ObjC;
      5 	ASTLabelType=CommonTree;
      6 	output=AST;
      7 //	rewrite=true; // works either in rewrite or normal mode
      8 }
      9 
     10 poly:	^('+' poly poly)
     11 	|	^(MULT INT ID)		-> INT
     12 	|	^(MULT c=INT ^('^' ID e=INT))
     13 		{
     14 		NSString *c2 = [NSString stringWithFormat:@"\%d", $c.int*$e.int];
     15 		NSString *e2 = [NSString stringWithFormat:@"\%d", $e.int-1];
     16 		}
     17 							-> ^(MULT[@"*"] INT[c2] ^('^' ID INT[e2]))
     18 	|	^('^' ID e=INT)
     19 		{
     20 		NSString *c2 = [NSString stringWithFormat:@"\%d", $e.int];
     21 		NSString *e2 = [NSString stringWithFormat:@"\%d", $e.int-1];
     22 		}
     23 							-> ^(MULT[@"*"] INT[c2] ^('^' ID INT[e2]))
     24 	|	INT					-> INT[@"0"]
     25 	|	ID					-> INT[@"1"]
     26 	;
     27