%{
#include <math.h>
#include <stdlib.h>
+#include <string.h>
+#include <iostream>
#include "tree.h"
#include "parser.hpp"
#include "globals.h"
-#define YY_DECL int yylex YY_PROTO(( YYSTYPE* yylval ))
+#define YY_DECL int yylex(YYSTYPE* yylval)
#define YY_INPUT(buf, result, max_size) \
{ \
input->read(buf, max_size); \
result = input->gcount(); \
}
+
+std::string last_docucomment;
+std::string original_file;
+std::string current_file;
+int offset_lnum;
+
+int getCurrentLine()
+{
+ return yylineno - offset_lnum;
+}
%}
%%
+#[ \t]+[0-9]+[ \t]+.* {
+ int lnum;
+ char file[1024];
+ if(sscanf(yytext, "# %d \"%1023[^\"]\"", &lnum, file) == 2) {
+ offset_lnum = yylineno - lnum + 1;
+ current_file = file;
+ if(original_file == "")
+ original_file = file;
+ } else {
+ std::cerr << "Warning: Parse error in processor info directive.\n";
+ }
+}
#.* /* ignore preprocessor directives */
[[:space:]]+ /* eat spaces */
-\/\*.*\*\/ /* eat comment */
-\/\/[^\n]*\n /* eat comment */
+\/\*.*\*\/ {
+ if(yytext[2] == '*' && yytext[3] != '/') { // It's a docu comment...
+ last_docucomment = std::string(yytext+3, strlen(yytext)-5);
+ }
+}
+\/\/[^\n]*\n {
+ if(yytext[2] == '/') { // it's a docu comment...
+ last_docucomment = std::string(yytext+3, strlen(yytext)-4);
+ }
+}
class { return T_CLASS; }
struct { return T_STRUCT; }
static { return T_STATIC; }