Skip to content

Instantly share code, notes, and snippets.

@csaunders
Created January 11, 2014 23:10
Show Gist options
  • Save csaunders/8378223 to your computer and use it in GitHub Desktop.
Save csaunders/8378223 to your computer and use it in GitHub Desktop.
Simple Math State Machine
#include <string.h>
#include <stdio.h>
%%{
machine simplemath;
number = digit+;
operator = '+';
main := (digit operator digit) 0 @{ res = 1; };
}%%
%% write data;
int main(int argc, char **argv) {
int cs, res = 0;
if ( argc > 1 ) {
char *p = argv[1];
char *pe = p + strlen(p) + 1;
%% write init;
%% write exec;
}
printf("result = %i\n", res );
return 0;
}
package main
import (
"os"
)
%%{
machine simplemath;
number = digit+;
operator = '+';
main := (digit operator digit) 0 @{ println("Success!") };
}%%
%% write data;
func main() {
cs, res := 0, 0
if(len(os.Args) > 1) {
data := os.Args[1]
p := 0
pe := len(data) - 1
%% write init;
%% write exec;
}
println("result = ", res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment