Skip to content

Instantly share code, notes, and snippets.

@JeonghunLee
Last active July 6, 2017 14:31
Show Gist options
  • Save JeonghunLee/3380b5186636ba737e9e776138927b3a to your computer and use it in GitHub Desktop.
Save JeonghunLee/3380b5186636ba737e9e776138927b3a to your computer and use it in GitHub Desktop.
calc.l
/*
  Refer to https://github.com/meyerd/flex-bison-example
  Definitions
C코드 삽입시 %{, }% 기호
*/
%option noyywrap // flex
%{
#include <stdio.h>
#define YY_DECL int yylex()
#include "calc.tab.h"
%}
/*
Rules
Pattern과 Action으로 표현이되어짐
C코드는 {, }로 감싸서 표시함
*/
%%
[ \t] ; // ignore all whitespace
[0-9]+\.[0-9]+ {yylval.fval = atof(yytext); return T_FLOAT;}
[0-9]+ {yylval.ival = atoi(yytext); return T_INT;}
\n {return T_NEWLINE;}
"+" {return T_PLUS;}
"-" {return T_MINUS;}
"*" {return T_MULTIPLY;}
"/" {return T_DIVIDE;}
"(" {return T_LEFT;}
")" {return T_RIGHT;}
"exit" {return T_QUIT;}
"quit" {return T_QUIT;}
%%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment