Commit e3712199 authored by Peter Faber's avatar Peter Faber
Browse files

init t-09

parent 0b2310dd
*.o
parser.cpp
parser.hpp
tokens.cpp
tokens.hpp
tokens
parser
all: tokens
OBJS = tokens.o
LLVMCONFIG = llvm-config-6.0
CPPFLAGS = -g `$(LLVMCONFIG) --cppflags` -std=c++11
LDFLAGS = `$(LLVMCONFIG) --ldflags` -rdynamic
LIBS = `$(LLVMCONFIG) --libs`
clean:
$(RM) -rf tokens.cpp tokens.hpp tokens $(OBJS)
tokens.cpp: tokens.l
flex --header-file=$(subst .cpp,.hpp,$@) -o $@ $^
tokens.hpp: tokens.cpp
%.o: %.cpp
$(CXX) -c $(CPPFLAGS) -o $@ $<
tokens: $(OBJS)
$(CXX) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
test: tokens example.txt
cat example.txt | ./$^
distclean: clean
$(RM) -rf .depend ./tokens.cpp ./tokens.hpp
.PHONY: clean distclean
depend: .depend
.depend: tokens.cpp tokens.hpp
$(CXX) `$(LLVMCONFIG) --cppflags` $(FLAGS) $(INCLUDE) -M *.cpp > .depend || true
$(CXX) `$(LLVMCONFIG) --cppflags` $(FLAGS) $(INCLUDE) -M *.hpp >> .depend || true
-include .depend
extern int printi(int val);
int do_math(int a) {
int x = a * 5;
return x + 3;
}
printi(do_math(8)-1);
%{
#include <cstdio>
#include <string>
/* Will later be replaced by parser definitions! */
int yylval;
enum token_t
{
TINT_T = 258,
TVOID_T = 259,
TIDENTIFIER = 260,
TINTEGER = 261,
TASSIGN = 262,
TNE = 263,
TLT = 264,
TLE = 265,
TGT = 266,
TGE = 267,
TEQ = 268,
TLPAREN = 269,
TRPAREN = 270,
TLBRACE = 271,
TRBRACE = 272,
TSEMICOL = 273,
TCOMMA = 274,
TPLUS = 275,
TMINUS = 276,
TMUL = 277,
TDIV = 278,
TRETURN = 279,
TEXTERN = 280,
TIF = 281,
TELSE = 282,
UMINUS = 283,
TNONE = 0
};
%}
%option noyywrap
%option yylineno
%%
%%
int main(){
int token;
while(TNONE!=(token=yylex())){
printf("read '%s' of length %d -- which is of type %d (value is %d)\n",yytext,yyleng,token,yylval);
}
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment