0
我有下面的代碼也有更多像expr:int {} |布爾{}等,但我不知道什麼是我應該寫在這種解析器的類型,我有一個計算器的例子,與int一起工作,類型是int,但在我的程序中我有浮動字符串等。我正在嘗試用ocamlyacc作爲語言的解析器,但我應該放什麼類型?
%{
dont know what to write here
%}
%token <int> INT
%token <float> FLOAT
%token <char> CHAR
%token <bool> BOOL
%token <string> IDENT
%token PLUS Div Bigger Smaller MINUS TIMES
%token TYPE
%token DEF DD
%token Equals Atribuicao SoE BoE And Or
%token IF ELSE BEGIN END WHILE RETURN PV SEQ TO BY OF
%token RP LP LB RB
%token EOL
%left Bigger Smaller SoE BoE Equals Atribuicao Or And
%left PLUS MINUS
%left TIMES Div
%nonassoc UMINUS OF
%start main
%type <> main /* what should be in here ? */
main:
| expr EOL { $1 }
expr:
INT { }
| BOOL { }
| FLOAT { }
| CHAR { }
| expr OF expr { }
| BEGIN expr END { }
| RETURN expr PV { $2 }
| LP expr RP { $2 }
| LB expr RB { $2 }
| expr PLUS expr { }
| expr MINUS expr { }
| expr TIMES expr { }
%%
let main() = begin
Printf.printf "Hello yo\n" ;
end;;