Skip to content

Commit

Permalink
Use FAUST prefix in lex/yacc parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Feb 27, 2023
1 parent 8380fe0 commit cb8d0a2
Show file tree
Hide file tree
Showing 12 changed files with 651 additions and 638 deletions.
6 changes: 3 additions & 3 deletions compiler/errors/errormsg.cpp
Expand Up @@ -30,7 +30,7 @@
#include <iostream>
using namespace std;

const char* yyfilename = "????";
const char* FAUSTfilename = "????";

void faustassertaux(bool cond, const string& file, int line)
{
Expand Down Expand Up @@ -61,10 +61,10 @@ void lexerror(const char* msg)
throw faustexception(fullmsg);
}

void yyerror(const char* msg)
void FAUSTerror(const char* msg)
{
stringstream error;
error << yyfilename << " : " << yylineno << " : ERROR : " << msg << endl;
error << FAUSTfilename << " : " << FAUSTlineno << " : ERROR : " << msg << endl;
gGlobal->gErrorCount++;
throw faustexception(error.str());
}
Expand Down
7 changes: 4 additions & 3 deletions compiler/errors/errormsg.hh
Expand Up @@ -24,8 +24,9 @@

#include "tlib.hh"

extern int yylineno;
extern const char* yyfilename;
// Globals for flex/bison parser
extern int FAUSTlineno;
extern const char* FAUSTfilename;

// associate and retrieve file and line properties to a symbol definition
void setDefProp(Tree sym, const char* filename, int lineno);
Expand All @@ -41,7 +42,7 @@ int getUseLineProp(Tree sym);

// Parsing error
void lexerror(const char* msg);
void yyerror(const char* msg);
void FAUSTerror(const char* msg);

// three levels or errors, warnings and remarks are provided during evaluation
void evalerror(const char* filename, int linenum, const char* msg, Tree exp);
Expand Down
12 changes: 6 additions & 6 deletions compiler/evaluate/eval.cpp
Expand Up @@ -201,7 +201,7 @@ static Tree real_a2sb(Tree exp)
return abstr;

} else {
evalerror(yyfilename, -1, "a2sb : internal error : not an abstraction inside closure (1)", exp);
evalerror(FAUSTfilename, -1, "a2sb : internal error : not an abstraction inside closure (1)", exp);
// Never reached since evalerror throws an exception
return 0;
}
Expand Down Expand Up @@ -720,7 +720,7 @@ static double eval2double(Tree exp, Tree visited, Tree localValEnv)
int numInputs, numOutputs;
getBoxType(diagram, &numInputs, &numOutputs);
if ((numInputs > 0) || (numOutputs != 1)) {
evalerror(yyfilename, yylineno, "not a constant expression of type : (0->1)", exp);
evalerror(FAUSTfilename, FAUSTlineno, "not a constant expression of type : (0->1)", exp);
// Never reached since evalerror throws an exception
return 1;
} else {
Expand Down Expand Up @@ -749,7 +749,7 @@ static int eval2int(Tree exp, Tree visited, Tree localValEnv)
int numInputs, numOutputs;
getBoxType(diagram, &numInputs, &numOutputs);
if ((numInputs > 0) || (numOutputs != 1)) {
evalerror(yyfilename, yylineno, "not a constant expression of type : (0->1)", exp);
evalerror(FAUSTfilename, FAUSTlineno, "not a constant expression of type : (0->1)", exp);
// Never reached since evalerror throws an exception
return 1;
} else {
Expand Down Expand Up @@ -1160,7 +1160,7 @@ static Tree applyList(Tree fun, Tree larg)

// Here fun is a closure, we can test the content of abstr
if (isBoxEnvironment(abstr)) {
evalerrorbox(yyfilename, -1, "an environment can't be used as a function", fun);
evalerrorbox(FAUSTfilename, -1, "an environment can't be used as a function", fun);
}

if (isBoxIdent(abstr)) {
Expand All @@ -1170,7 +1170,7 @@ static Tree applyList(Tree fun, Tree larg)
}

if (!isBoxAbstr(abstr, id, body)) {
evalerror(yyfilename, -1, "(internal) not an abstraction inside closure (2)", fun);
evalerror(FAUSTfilename, -1, "(internal) not an abstraction inside closure (2)", fun);
}

// Here abstr is an abstraction, we can test the content of abstr.
Expand Down Expand Up @@ -1223,7 +1223,7 @@ static Tree revEvalList(Tree lexp, Tree visited, Tree localValEnv)
static Tree larg2par(Tree larg)
{
if (isNil(larg)) {
evalerror(yyfilename, -1, "empty list of arguments", larg);
evalerror(FAUSTfilename, -1, "empty list of arguments", larg);
}
if (isNil(tl(larg))) {
return hd(larg);
Expand Down
12 changes: 6 additions & 6 deletions compiler/global.cpp
Expand Up @@ -106,9 +106,9 @@

using namespace std;

// Globals for lex/yack parser
extern FILE* yyin;
extern const char* yyfilename;
// Globals for flex/bison parser
extern FILE* FAUSTin;
extern const char* FAUSTfilename;

// Garbageable globals
list<Garbageable*> global::gObjectTable;
Expand Down Expand Up @@ -614,9 +614,9 @@ void global::init()

PROPAGATEPROPERTY = symbol("PropagateProperty");

// yyfilename is defined in errormsg.cpp but must be redefined at each compilation.
yyfilename = "";
yyin = nullptr;
// FAUSTfilename is defined in errormsg.cpp but must be redefined at each compilation.
FAUSTfilename = "";
FAUSTin = nullptr;

gLatexheaderfilename = "latexheader.tex";
gDocTextsDefaultFile = "mathdoctexts-default.txt";
Expand Down
10 changes: 6 additions & 4 deletions compiler/parser/Makefile
Expand Up @@ -3,16 +3,18 @@ OUT = faustlexer.cpp faustparser.cpp faustparser.hpp
YACC = bison
LEX = flex
PREFIX := FAUST
#OPTIONS:= -I -P$(PREFIX)
LEX_OPTIONS:= -P$(PREFIX)
YACC_OPTIONS:= -p$(PREFIX)

code : $(OUT)

faustparser.hpp : faustparser.y
faustparser.cpp : faustparser.y
$(YACC) -d -o faustparser.cpp $(OPTIONS) faustparser.y
$(YACC) -d -o faustparser.cpp $(YACC_OPTIONS) faustparser.y

faustlexer.cpp : faustlexer.l
$(LEX) -I -ofaustlexer.cpp $(OPTIONS) faustlexer.l
$(LEX) -I -ofaustlexer.cpp $(LEX_OPTIONS) faustlexer.l

clean:
rm -f $(OUT)
rm -f $(OUT)

0 comments on commit cb8d0a2

Please sign in to comment.