c_statement handler printing the string literal!

git-svn-id: svn://anubis/jtlc/trunk@10 f5bc74b8-7b62-4e90-9214-7121d538519f
This commit is contained in:
josh 2010-01-12 21:54:09 +00:00
parent 425ed9d84c
commit 93fe98f7fd
4 changed files with 19 additions and 5 deletions

View File

@ -3,7 +3,10 @@
#define PARSER_H
#include "util/refptr.h"
#include "parser/Node.h"
void parse(const char * fileName);
#define YYSTYPE refptr<Node>
YYSTYPE parse(const char * fileName);
#endif

View File

@ -4,6 +4,7 @@
%{
#include "parser.h"
#include "parser.tab.hh"
#include <string>
using namespace std;
@ -93,6 +94,7 @@ struct return STRUCT;
\" {
/* end of the string literal */
BEGIN(INITIAL);
*yylval = new StringNode(build_string);
return STRING_LITERAL;
}
\\x[0-9A-Fa-f]{2} {

View File

@ -3,8 +3,8 @@
#include <stdio.h>
#include <iostream>
#include "parser.tab.hh" /* bison-generated header with YY[SL]TYPE */
#include "parser.h"
#include "parser.tab.hh" /* bison-generated header with YY[SL]TYPE */
using namespace std;
#define yyerror(msg) errFunc(msg, &yylloc)
@ -20,6 +20,8 @@ int yywrap()
return 1;
}
static YYSTYPE parse_result;
%}
%pure-parser
@ -88,6 +90,10 @@ int yywrap()
%%
program: program_items {
}
;
program_items: /* empty */
| program_item program_items
;
@ -198,24 +204,25 @@ lvalue: IDENTIFIER
;
c_statement: C LPAREN STRING_LITERAL RPAREN SEMICOLON {
printf("c_statement: '%s'\n", $3->getString().c_str());
}
;
%%
void parse(const char * fileName)
YYSTYPE parse(const char * fileName)
{
yyin = fopen(fileName, "r");
if (yyin == NULL)
{
cerr << "Failed to open file '" << fileName << "'" << endl;
return;
}
if (yyparse())
else if (yyparse())
{
cerr << "Aborting." << endl;
exit(1);
}
return parse_result;
}
void errFunc(const char * str, YYLTYPE * yyllocp)

View File

@ -0,0 +1,2 @@
c("This is C to be output by my compiler");