Test change - can I push OK?
[kdeedu-porting.git] / kalzium / src / solver / parser.mly
blob41d91f338564632284a733469c616af5ad61120c
1 /***************************************************************************
2  *   Copyright (C) 2004 by Thomas Nagy                                     *
3  *   tnagy2^8@yahoo.fr                                                     *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
19  ***************************************************************************/
21 /* File parser.mly */
26         open Chemset
27         
28         (*let parse_error somestring = Printf.printf "%s \n" somestring;;
29         *)
32 %token <int> INT
33 %token PLUS MINUS
34 %token LPAREN RPAREN LBRACKET RBRACKET
35 %token EOF
36 %token <string> CAPITAL
37 %token <string> MINOR
38 %token ARROW
39 %start main
40 %type <Chemset.listitems> main
43 main:
44     equation EOF { $1 }
48 equation:
49     expr ARROW expr { chem_negate $3; List.append $1 $3 }
52 expr:
53     item { $1::[] }
54     | item PLUS expr { $1::$3 }
57 item:
58     MINOR symbols { {ikey=$1; itbl=$2; sign=1} }
59     | INT symbols { {ikey=string_of_int($1); itbl=$2; sign=1} }
60     | symbols { {ikey="1"; itbl=$1; sign=1}}
63 symbols:
64     qte { $1 }
65     | qte symbols { chem_add $1 $2 }
68 qte:
69     element INT { createchem $1 $2 }
70     | element { createchem $1 1 } 
71     | LPAREN symbols RPAREN INT { chem_mult $2 $4 }
72     | LBRACKET INT PLUS RBRACKET   { createchem "+" $2 }
73     | LBRACKET INT MINUS RBRACKET  { createchem "-" $2 }
74     | LBRACKET PLUS RBRACKET   { createchem "+" 1 }
75     | LBRACKET MINUS RBRACKET  { createchem "-" 1 }
78 element:
79     CAPITAL MINOR { $1 ^ $2 }
80     | CAPITAL { $1 }