KiCad PCB EDA Suite
main.cpp
Go to the documentation of this file.
1 /*
2  This file is part of libeval, a simple math expression evaluator
3 
4  Copyright (C) 2017 Michael Geselbracht, mgeselbracht3@gmail.com
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19 
20 #include <stdio.h>
21 #include <assert.h>
22 
23 #include "numeric_evaluator.h"
24 
25 int main()
26 {
27  NumericEvaluator eval;
28 
29  eval.process("2.54mm+50mil");
30  if (eval.isValid()) printf("%s\n", eval.result());
31 
32  eval.process("x=1; y=5;");
33  if (eval.isValid()) printf("%s\n", eval.result());
34  eval.process("x+y");
35  if (eval.isValid()) printf("%s\n", eval.result());
36 
37  eval.setVar("posx", -3.14152);
38  bool retval = eval.process("posx");
39  assert(retval == eval.isValid());
40  if (eval.isValid()) printf("%s\n", eval.result());
41 
42  eval.process("x=1; y=2");
43  eval.setVar("z", 3);
44  eval.process("x+y+z");
45  printf("x+y+z=%s\n", eval.result());
46 
47  eval.process("1\"");
48  printf("1\" = %s\n", eval.result());
49  eval.process("12.7 - 0.1\" - 50mil");
50  printf("12.7 - 0.1\" - 50mil = %s\n", eval.result());
51 }
52 
int main()
Definition: main.cpp:25