aboutsummaryrefslogtreecommitdiff
path: root/sem3/osc/mm10/opg3.l
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-02-11 12:24:56 +0100
committerJulian T <julian@jtle.dk>2020-02-11 12:24:56 +0100
commit6db1a2cdd3b96731f2e092d55d8c2136eabc52d0 (patch)
tree2be8fae8ce82d708ed9f00f376dda14420850e80 /sem3/osc/mm10/opg3.l
parent57305119e05559c1c37e903aef89cd43f44c42c9 (diff)
Rename and cleanup
Diffstat (limited to 'sem3/osc/mm10/opg3.l')
-rw-r--r--sem3/osc/mm10/opg3.l36
1 files changed, 36 insertions, 0 deletions
diff --git a/sem3/osc/mm10/opg3.l b/sem3/osc/mm10/opg3.l
new file mode 100644
index 0000000..1c4b9c7
--- /dev/null
+++ b/sem3/osc/mm10/opg3.l
@@ -0,0 +1,36 @@
+%{
+
+#include <stdio.h>
+
+#define BEGIN_T 1
+#define END_T 2
+#define NUM_T 3
+#define VAR_T 4
+
+%}
+
+VAR [a-zA-Z][a-zA-Z\_\-0-9]*
+TAL [0-9]+
+
+%%
+
+begin {printf("Found a BEGIN\n"); return BEGIN_T;}
+end {printf("Found a END\n"); return END_T;}
+{VAR} {printf("Found a variable %s\n", yytext); return VAR_T;}
+{TAL} {printf("Found a number %d\n", strtol(yytext, NULL, 10)); return NUM_T;}
+
+%%
+
+int main(void) {
+
+ for(;;) {
+ int t = yylex();
+ printf("yylex: %d\n", t);
+ if( t == END_T ) {
+ break;
+ }
+ }
+
+ return 0;
+
+}