summaryrefslogtreecommitdiff
path: root/support/rail/lex.l
diff options
context:
space:
mode:
Diffstat (limited to 'support/rail/lex.l')
-rw-r--r--support/rail/lex.l100
1 files changed, 100 insertions, 0 deletions
diff --git a/support/rail/lex.l b/support/rail/lex.l
new file mode 100644
index 0000000000..7b61c0eb30
--- /dev/null
+++ b/support/rail/lex.l
@@ -0,0 +1,100 @@
+/* lex.l - lexical analyzer for rail program */
+
+%{
+
+#include <string.h>
+
+#include "rail.h"
+#include "gram.h"
+
+unsigned line; /* current input line */
+int copy; /* copy to output flag */
+
+#define COPY (copy && fputs(yytext,outf))
+
+extern YYSTYPE yylval;
+
+%}
+
+%%
+
+[a-zA-Z_][0-9a-zA-Z_.]* {
+ COPY;
+ yylval.id=lookup(yytext);
+ return(IDENTIFIER);
+}
+
+[0-9][0-9]* {
+ COPY;
+ yylval.num=atoi(yytext);
+ return(NUMBER);
+}
+
+\\rail@i {
+ COPY;
+ return(RAILI);
+}
+
+\\rail@p {
+ COPY;
+ return(RAILP);
+}
+
+\\rail@t {
+ COPY;
+ return(RAILT);
+}
+
+\\par {
+ COPY;
+}
+
+\\\\ { COPY;
+ return(RAILCR);
+}
+
+\\[a-zA-Z@]+ {
+ COPY;
+ return(CS);
+}
+
+\\[^ \n\t] {
+ COPY;
+ return(CS);
+}
+
+'[^\n\t']*' {
+ COPY;
+ yytext[yyleng-1]='\0';
+ yylval.text=mcheck(strdup(yytext+1));
+ return(STRING);
+}
+
+\[[^\n\t\]]*\] {
+ COPY;
+ yytext[yyleng-1]='\0';
+ yylval.text=mcheck(strdup(yytext+1));
+ return(ANNOT);
+}
+
+\"[^\n\t\"]*\" {
+ COPY;
+ yytext[yyleng-1]='\0';
+ yylval.text=mcheck(strdup(yytext+1));
+ return(STRING);
+}
+
+[ \t]+ {
+ COPY;
+}
+
+\n {
+ COPY;
+ line++;
+}
+
+. {
+ COPY;
+ return(yytext[0]);
+}
+