Skip to content

Commit

Permalink
More tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
halogenandtoast committed Aug 12, 2014
1 parent 8da09be commit 8b514ae
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions ruby.l
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
%{
#include <stdio.h>
#define VTYPE(type, value) printf("%s(%s)\n", type, value)
#define TYPE(type) printf("%s\n", type)
%}

%option noyywrap

NUMBER [0-9](_[0-9]|[0-9])*

%%
[0-9]+ { printf("NUMBER: %s\n", yytext); }
#.*$ {}
\"([^"]|\\.)*\" { VTYPE("STRING", yytext); }
\'([^']|\\.)*\' { VTYPE("STRING", yytext); }
{NUMBER}(\.{NUMBER}|(\.{NUMBER})?[eE][+-]?{NUMBER}) { VTYPE("FLOAT", yytext); }
{NUMBER} { VTYPE("NUMBER", yytext); }
[a-z_][a-zA-Z0-9_]* { VTYPE("ID", yytext); }
[A-Z][a-zA-Z0-9_]* { VTYPE("CONSTANT", yytext); }
"=" { TYPE("EQUAL"); }
">" { TYPE("GT"); }
"<" { TYPE("LT"); }
">=" { TYPE("GTE"); }
"<=" { TYPE("LTE"); }
"!=" { TYPE("NEQUAL"); }
"+" { TYPE("PLUS"); }
"-" { TYPE("MINUS"); }
"*" { TYPE("MULT"); }
"/" { TYPE("DIV"); }
"%" { TYPE("MOD"); }
"!" { TYPE("EMARK"); }
"?" { TYPE("QMARK"); }
"&" { TYPE("AND"); }
"|" { TYPE("OR"); }
"[" { TYPE("LSBRACE"); }
"]" { TYPE("RSBRACE"); }
"(" { TYPE("LPAREN"); }
")" { TYPE("RPAREN"); }
"{" { TYPE("LBRACE"); }
"}" { TYPE("RBRACE"); }
"@" { TYPE("AT"); }
"." { TYPE("DOT"); }
"," { TYPE("COMMA"); }
":" { TYPE("COLON"); }
[\t ] {}
\n {}
. { fprintf(stderr, "Unknown token %s\n", yytext); }
. { fprintf(stderr, "Unknown token '%s'\n", yytext); }

0 comments on commit 8b514ae

Please sign in to comment.