From ffce78b24da93661b8b83795072994ce59287b29 Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Sat, 2 Jul 2016 17:11:21 +0200 Subject: [PATCH] Added function arguments --- Makefile | 8 ++++---- mumei.y | 34 +++++++++++++++++++++++++--------- test.mtl | 9 +++++---- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 6eff2e1..dd58308 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ CC=gcc CXX=g++ LD=g++ -CFLAGS=-O3 -march=native -fstack-protector=strong -CXXFLAGS=-O3 -march=native-fstack-protector=strong +CFLAGS=-O3 -march=native -fstack-protector-strong -gdwarf-2 +CXXFLAGS=-O3 -march=native -fstack-protector-strong -gdwarf-2 LEX=flex YACC=bison all: mumei @@ -11,10 +11,10 @@ mumei: mumei.tab.o lex.yy.o $(LD) -o $@ $^ -lfl lex.yy.o: lex.yy.c - $(CXX) $(CPPFLAGS) -c -o $@ $^ + $(CXX) $(CXXFLAGS) -c -o $@ $^ mumei.tab.o: mumei.tab.c - $(CXX) $(CPPFLAGS) -c -o $@ $^ + $(CXX) $(CXXFLAGS) -c -o $@ $^ lex.yy.c: mumei.tab.c $(LEX) mumei.l diff --git a/mumei.y b/mumei.y index 74b7281..4246595 100644 --- a/mumei.y +++ b/mumei.y @@ -23,6 +23,19 @@ int getVarID(string name) { nameTable.push_back(name); return nameTable.size()-1; } +vector argTable; +int getArgID(string name) { + auto it=argTable.end(); + for(auto it=argTable.begin(); it!=argTable.end(); it++) { + if(argTable[it-argTable.begin()]==name) { + return (int)(it-argTable.begin())-(int)(argTable.size())-1; + } + } + return 0; +} +void createArg(string arg) { + argTable.push_back(arg); +} ofstream out; %} %union { @@ -48,13 +61,17 @@ program: fh function ef program | fh function ef fh: - FUNCTION VARNAME {out << $2 << ":\n\tbpget\n\tspget\n\tbpset" << endl;} + FUNCTION VARNAME LPARENS args RPARENS {out << $2 << ":\n\tbpget\n\tspget\n\tbpset" << endl;} + | FUNCTION VARNAME LPARENS RPARENS {out << $2 << ":\n\tbpget\n\tspget\n\tbpset" << endl;} +args: + VARNAME COMMA args {createArg($1);} + | VARNAME {createArg($1);} ef: - END {out << "\tbpget\n\tspset\n\tbpset\n\tret"<