summaryrefslogtreecommitdiff
path: root/obcl/lex.l
diff options
context:
space:
mode:
authorMarius Nita <marius@cs.pdx.edu>2003-04-14 06:04:49 +0000
committerMarius Nita <marius@cs.pdx.edu>2003-04-14 06:04:49 +0000
commit7aae14e9b83242c2778e57c069fb8f299b8172f3 (patch)
tree80892567a99c251b0ae957c51309645b6d27dc98 /obcl/lex.l
parent69854023a4f36deb80c7c3dee891acc48f8ae6da (diff)
beginning of obcl. the parser works with semicolons after statements
for now, there is much left to change and do.
Diffstat (limited to 'obcl/lex.l')
-rw-r--r--obcl/lex.l86
1 files changed, 86 insertions, 0 deletions
diff --git a/obcl/lex.l b/obcl/lex.l
new file mode 100644
index 00000000..33a3c61a
--- /dev/null
+++ b/obcl/lex.l
@@ -0,0 +1,86 @@
+%{
+#include "obcl.h"
+#include "parse.h"
+%}
+
+%option yylineno
+
+DGT [0-9]
+ID [a-zA-Z_][a-zA-Z_\.\-0-9]*
+
+
+ /* string bummy */
+%x str
+%%
+
+ char str_buf[1024];
+ char *str_buf_ptr;
+ int str_char;
+
+ /* begin a string */
+[\"\'] {
+ str_buf_ptr = str_buf;
+ str_char = yytext[0];
+ BEGIN(str);
+ }
+
+ /* end a string */
+<str>[\"\'] {
+ if (yytext[0] == str_char) {
+ BEGIN(INITIAL);
+ *str_buf_ptr = '\0';
+ yylval.string = g_strdup(str_buf);
+ return TOK_STRING;
+ } else {
+ *str_buf_ptr++ = yytext[0];
+ }
+ }
+
+ /* can't have newlines in strings */
+<str>\n {
+ printf("Error: Unterminated string constant.\n");
+ BEGIN(INITIAL);
+ }
+
+ /* handle \" and \' */
+<str>"\\"[\"\'] {
+ if (yytext[1] == str_char)
+ *str_buf_ptr++ = yytext[1];
+ else {
+ *str_buf_ptr++ = yytext[0];
+ *str_buf_ptr++ = yytext[1];
+ }
+ }
+
+ /* eat valid string contents */
+<str>[^\\\n\'\"]+ {
+ char *yptr = yytext;
+ while (*yptr) {
+ *str_buf_ptr++ = *yptr++;
+ }
+ }
+
+ /* numberz */
+{DGT}+ {
+ yylval.num = atof(yytext);
+ return TOK_NUM;
+ }
+
+ /* real numbers */
+{DGT}+"."{DGT}* {
+ yylval.num = atof(yytext);
+ return TOK_NUM;
+ }
+
+ /* identifiers -- names without spaces and other crap in them */
+{ID} {
+ yylval.string = g_strdup(yytext);
+ return TOK_ID;
+ }
+
+ /* skip comments */
+"#".*\n ;
+ /* skip other whitespace */
+[ \n\t]+ ;
+. { return yytext[0]; }
+%%