Created
January 11, 2014 23:10
-
-
Save csaunders/8378223 to your computer and use it in GitHub Desktop.
Simple Math State Machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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