• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1tree grammar PolyDifferentiator;
2options {
3	tokenVocab=Poly;
4    language=ObjC;
5	ASTLabelType=CommonTree;
6	output=AST;
7//	rewrite=true; // works either in rewrite or normal mode
8}
9
10poly:	^('+' 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