annotate lab0/parser.mly @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 /* lab1/parser.mly */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 /* Copyright (c) 2017 J. M. Spivey */
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 %{
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 open Tree
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 %}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 %token <string> IDENT
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 %token <float> NUMBER
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 %token PLUS MINUS TIMES DIVIDE OPEN CLOSE EQUAL EOF BADTOK
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 %type <string * Tree.expr> equation
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 %start equation
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 %%
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 equation :
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 expr EOF { ("it", $1) }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 | IDENT EQUAL expr EOF { ($1, $3) } ;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 expr :
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 term { $1 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 | expr PLUS term { Binop (Plus, $1, $3) }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 | expr MINUS term { Binop (Minus, $1, $3) } ;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 term :
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 factor { $1 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 | term TIMES factor { Binop (Times, $1, $3) }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 | term DIVIDE factor { Binop (Divide, $1, $3) } ;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 factor :
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 NUMBER { Number $1 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 | IDENT { Variable $1 }
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 | OPEN expr CLOSE { $2 } ;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36