Here's the sample code of an OCaml parser:
%{ open Ast %}
%token PLUS MINUS TIMES DIVIDE EOF
%token <int> LITERAL
%left PLUS MINUS
%left TIMES DIVIDE
%start expr
%type < Ast.expr> expr
%%
expr:
expr PLUS expr { Binop($1, Add, $3) }
| expr MINUS expr { Binop($1, Sub, $3) }
| expr TIMES expr { Binop($1, Mul, $3) }
| expr DIVIDE expr { Binop($1, Div, $3) }
| LITERAL { Lit($1) }
I have the code for the scanner and AST (Abstract Syntax Tree) too. What does $1 and $3 here indicate?
ADDENDUM: I want to assign a value to a variable. I also want to store the values of all the variables in an array. How can I do that?