Website Summary Files Commits Branches @commit @diff @stats
path: root / demo / bison / associativity / lexer.lex
diff options
context:
space:
mode:
Commitce3d82fcd2d1bf59ca6effac687b70ce2c73e466 (patch)
Author
 Dimitar Trendafilov <trendafilov.dn@gmail.com>
2022-10-24 23:31:13 +0300
Committer
 Dimitar Trendafilov <trendafilov.dn@gmail.com>
2022-10-24 23:31:13 +0300
Files3a5473976be743af18ef2fe6e8516f8db753f10b /demo/bison/associativity/lexer.lex
IPL-ce3d82fcd2d1bf59ca6effac687b70ce2c73e466.tar
IPL-ce3d82fcd2d1bf59ca6effac687b70ce2c73e466.tar.gz
IPL-ce3d82fcd2d1bf59ca6effac687b70ce2c73e466.zip
Parent6c73a13855d76ed32c067564beee9d474f0d7bc1 (diff)
Demo parser to show associativity with bison
1 files changed, 37 insertions, 0 deletions
-rw-r--r--demo/bison/associativity/lexer.lex37
diff --git a/demo/bison/associativity/lexer.lex b/demo/bison/associativity/lexer.lex
new file mode 100644
index 0000000..be84321
--- /dev/null
+++ b/demo/bison/associativity/lexer.lex
@@ -0,0 +1,37 @@
+/* Expression calculator */
+
+%{
+#include <string>
+#include "parser.hpp"
+int current_line = 0;
+#define YY_NO_UNISTD_H
+%}
+/* prevent the lexer from looking for isatty */
+%option never-interactive
+
+digit [0-9]
+number [1-9]{digit}*
+fnumber {digit}+"."{digit}*
+ident [a-zA-Z_][a-zA-Z_0-9]*
+
+%%
+
+{number}|{fnumber} { yylval = yytext; return NUMBER; }
+{ident} { yylval = yytext; return IDENT; }
+"+" { return PLUS; }
+"-" { return MINUS; }
+"*" { return MULT; }
+"/" { return DIV; }
+"=" { return ASSIGN; }
+"(" { return '('; }
+")" { return ')'; }
+[ \t] { }
+\n { ++current_line; }
+
+%%
+
+int yywrap()
+{
+ return 1;
+}
+