From 4d5d24f1da11a1279da0b5ea9351c4372a74bc43 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 11 Dec 2011 10:01:52 -0700 Subject: Basic parser coming together. --- src/parser.l | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/parser.l (limited to 'src/parser.l') diff --git a/src/parser.l b/src/parser.l new file mode 100644 index 0000000..d5ff735 --- /dev/null +++ b/src/parser.l @@ -0,0 +1,43 @@ +%{ +#include +#include "parser.tab.h" +%} + +%option noyywrap + +%x sitname +%x comment +%x tdqstr tsqstr +%% + +[-{}<>=+/*,();] { return yytext[0]; } + +game { return tokGame; } +function { return tokFunction; } +situation { return tokSituation; } +while { return tokWhile; } +for { return tokFor; } +each { return tokEach; } +in { return tokIn; } +if { return tokIf; } +then { return tokThen; } +else { return tokElse; } +command { return tokCommand; } +goto { return tokGoto; } + +"<<" { BEGIN( sitname ); } +[- a-zA-Z0-9]+ { printf("situation: %s\n", yytext ); return tokSituationName; } +">>" { BEGIN( INITIAL ); } +. REJECT; + +"//"[^\n]* {} + +"/\*" { BEGIN( comment ); } +"\*/" { BEGIN( INITIAL ); } +. {} + +[a-zA-Z_][a-zA-Z0-9_]* { return tokIdent; } + +[ \t\n\r]+ {} + +%% -- cgit v1.2.3