blob: bd34bb8c70c50271af8af072a541da5d1b4f00f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
// pushdown.c - Example usage of pushdown.h stack automaton
#include <stdio.h>
typedef double stack_value_t;
#define STACK_IMPLEMENTATION
#include "../include/stack.h"
typedef double pushdown_value_t;
#define PUSHDOWN_IMPLEMENTATION
#include "../include/pushdown.h"
int main() {
pushdown_instruction_t instructions[] = {PUSH, COPY, MUL, END};
stack_t input = {0};
stack_t output = {0};
stack_init(&input);
stack_init(&output);
stack_push(&input, 4.0);
pushdown_run(&output, &input, instructions);
while (output.size) {
printf("%lf\n", stack_pop(&output));
}
stack_free(&input);
stack_free(&output);
}
|