modified example programs, added strings to lexer

git-svn-id: svn://anubis/jtlc/trunk@6 f5bc74b8-7b62-4e90-9214-7121d538519f
This commit is contained in:
josh committed 2010-01-12 20:23:08 +00:00
1 parent e83a2f1f08
commit bb982b62b8
5 files changed
+41 -7

No files matched your search

+32
View File
@@ -5,9 +5,14 @@
%{
#include "parser.tab.hh"
#include <string>
using namespace std;
static string build_string;
%}
%x str
%%
/* operators */
@@ -66,6 +71,8 @@ int return INT;
uint return UINT;
long return LONG;
ulong return ULONG;
float return FLOAT;
double return DOUBLE;
/* keywords */
import return IMPORT;
@@ -76,6 +83,31 @@ struct return STRUCT;
/* identifiers */
[a-zA-Z_][a-zA-Z_0-9]* {
return IDENTIFIER;
}
/* strings */
\" build_string = ""; BEGIN(str);
<str>{
\" {
/* end of the string literal */
BEGIN(INITIAL);
return STRING_LITERAL;
}
\\x[0-9A-Fa-f]{2} {
/* hexadecimal escape code */
unsigned int val;
(void) sscanf(yytext + 2, "%x", &val);
build_string += (char) val;
}
\\n build_string += '\n';
\\t build_string += '\t';
\\r build_string += '\r';
\\b build_string += '\b';
\\f build_string += '\f';
\\(.|\n) build_string += yytext[1];
[^\\\"]+ build_string += yytext;
}
/* whitespace */
+3
View File
@@ -59,6 +59,7 @@ int yywrap()
/* literals */
%token INT_LITERAL;
%token REAL_LITERAL;
%token STRING_LITERAL;
/* primitive types */
%token BYTE;
@@ -71,6 +72,8 @@ int yywrap()
%token UINT;
%token LONG;
%token ULONG;
%token FLOAT;
%token DOUBLE;
/* keywords */
%token IMPORT;