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
mike@0 1 /* lab1/parser.mly */
mike@0 2 /* Copyright (c) 2017 J. M. Spivey */
mike@0 3
mike@0 4 %{
mike@0 5 open Tree
mike@0 6 %}
mike@0 7
mike@0 8 %token <string> IDENT
mike@0 9 %token <float> NUMBER
mike@0 10 %token PLUS MINUS TIMES DIVIDE OPEN CLOSE EQUAL EOF BADTOK
mike@0 11
mike@0 12 %type <string * Tree.expr> equation
mike@0 13
mike@0 14 %start equation
mike@0 15
mike@0 16 %%
mike@0 17
mike@0 18 equation :
mike@0 19 expr EOF { ("it", $1) }
mike@0 20 | IDENT EQUAL expr EOF { ($1, $3) } ;
mike@0 21
mike@0 22 expr :
mike@0 23 term { $1 }
mike@0 24 | expr PLUS term { Binop (Plus, $1, $3) }
mike@0 25 | expr MINUS term { Binop (Minus, $1, $3) } ;
mike@0 26
mike@0 27 term :
mike@0 28 factor { $1 }
mike@0 29 | term TIMES factor { Binop (Times, $1, $3) }
mike@0 30 | term DIVIDE factor { Binop (Divide, $1, $3) } ;
mike@0 31
mike@0 32 factor :
mike@0 33 NUMBER { Number $1 }
mike@0 34 | IDENT { Variable $1 }
mike@0 35 | OPEN expr CLOSE { $2 } ;
mike@0 36