From ce3d82fcd2d1bf59ca6effac687b70ce2c73e466 Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Mon, 24 Oct 2022 23:31:13 +0300 Subject: Demo parser to show associativity with bison --- demo/bison/associativity/lexer.lex | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 demo/bison/associativity/lexer.lex (limited to 'demo/bison/associativity/lexer.lex') 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 +#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; +} + -- cgit v1.3.1-26-gb76a