PC_graph/main.c
2024-10-14 22:10:32 +02:00

60 lines
1.3 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include "lex.h"
#include "parser.h"
#include "ps_graph.h"
int main(int argc, char *argv[]) {
struct lexer *lex;
struct expr_node *node;
if (argc < 2) {
printf("Usage: %s <expression>\n", argv[0]);
return 1;
}
/*
//struct lexer *lex = lex_create("x* sin (x ^ 2) * 5.5e+2* cosh (x )");
//struct lexer *lex = lex_create("-1 + -2 - 3 + 4");
*/
lex = lex_create(argv[1]);
node = parse_expression(lex);
lex_free(lex);
//if (node) {
// double x;
// node_debug_print(node);
// printf("polygon(");
// for (x = -10.0; x < 10.0; x += 0.1) {
// printf("(%.2f,%.2f),", x, node_eval(node, x));
// }
// printf("(10, -1000),(-10,-1000))\n");
//}
if (node) {
FILE *file;
struct graph_range graph;
//graph.xmin = -10.0;
//graph.xmax = 10.0;
//graph.ymin = -10.0;
//graph.ymax = 10.0;
//graph.step = 0.1;
graph.xmin = -3.14;
graph.xmax = 3.14;
graph.ymin = -1;
graph.ymax = 1;
graph.step = 0.01;
file = fopen("out.ps", "w");
ps_export_graph(file, node, &graph);
fclose(file);
}
node_free(node);
return 0;
}