aboutsummaryrefslogtreecommitdiffstats
path: root/c_lexer/src
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-02-07 18:10:15 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-02-07 18:10:15 +0000
commitd1bb4f42bd6ab8e8f0d0dfe7acb45183e4629760 (patch)
treebed66cf902367f0d28e152e0d5612480e873ca52 /c_lexer/src
parent1a89a34dfc04a32ec5c25f6bb6d91173acf31679 (diff)
downloadCompiler-d1bb4f42bd6ab8e8f0d0dfe7acb45183e4629760.tar.gz
Compiler-d1bb4f42bd6ab8e8f0d0dfe7acb45183e4629760.zip
Went about the issue with yyleng being of weird type
Diffstat (limited to 'c_lexer/src')
-rw-r--r--c_lexer/src/c_lexer.flex13
-rw-r--r--c_lexer/src/main.cpp2
2 files changed, 14 insertions, 1 deletions
diff --git a/c_lexer/src/c_lexer.flex b/c_lexer/src/c_lexer.flex
index c2a42c4..6c7a424 100644
--- a/c_lexer/src/c_lexer.flex
+++ b/c_lexer/src/c_lexer.flex
@@ -11,6 +11,8 @@ int lineCount = 1;
int spaceCount = 1;
int sourceLineCount = 1;
+int charLength = 0;
+
std::string fileName;
%}
@@ -49,53 +51,63 @@ ALL .
{KEYWORD} {
yylval = new std::string(yytext);
+ charLength = (int)yyleng;
return Keyword;
}
{IDENTIFIER} {
yylval = new std::string(yytext);
+ charLength = (int)yyleng;
return Identifier;
}
{OPERATOR} {
yylval = new std::string(yytext);
+ charLength = (int)yyleng;
return Operator;
}
{FRACTIONALCONSTANT}{EXPONENTPART}?{FLOATINGSUFFIX}? {
yylval = new std::string(yytext);
+ charLength = (int)yyleng;
return Constant;
}
([0-9]+){EXPONENTPART}{FLOATINGSUFFIX}? {
yylval = new std::string(yytext);
+ charLength = (int)yyleng;
return Constant;
}
{HEXCONSTANT}{INTEGERSUFFIX}? {
yylval = new std::string(yytext);
+ charLength = (int)yyleng;
return Constant;
}
{DECIMALCONSTANT}{INTEGERSUFFIX}? {
yylval = new std::string(yytext);
+ charLength = (int)yyleng;
return Constant;
}
{OCTALCONSTANT}{INTEGERSUFFIX}? {
yylval = new std::string(yytext);
+ charLength = (int)yyleng;
return Constant;
}
{CHARCONSTANT} {
std::string tmp(yytext);
yylval = new std::string(tmp.substr(1, tmp.length()-2));
+ charLength = (int)yyleng;
return Constant;
}
{STRINGLITERAL} {
std::string tmp(yytext);
yylval = new std::string(tmp.substr(1, tmp.length()-2));
+ charLength = (int)yyleng;
return StringLiteral;
}
@@ -125,6 +137,7 @@ ALL .
{ALL} {
yylval = new std::string(yytext);
+ charLength = (int)yyleng;
return Invalid;
}
diff --git a/c_lexer/src/main.cpp b/c_lexer/src/main.cpp
index 8b20098..1e45bbd 100644
--- a/c_lexer/src/main.cpp
+++ b/c_lexer/src/main.cpp
@@ -65,7 +65,7 @@ int main() {
printf("%s,\n", toJson(classType, text, streamLine, sourceCol, sourceLine, fileName).c_str());
- spaceCount += yyleng;
+ spaceCount += charLength;
}
printf("{}\n]\n");