added VARREF in lexer matching $[a-zA-Z_][a-zA-Z_0-9]*, added VarRefNode class

git-svn-id: svn://anubis/fart/branches/scene-file-scripting@325 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2010-09-29 20:59:26 +00:00
parent 35d6e536ae
commit 442a7bdeda
3 changed files with 16 additions and 4 deletions

View File

@ -168,10 +168,7 @@ class IdentifierNode : public Node
{
public:
IdentifierNode(const std::string & str) { m_string = str; }
std::string getString()
{
return m_string;
}
std::string getString() { return m_string; }
protected:
std::string m_string;
};
@ -442,5 +439,14 @@ class BinOpNode : public ExpressionNode
refptr<Node> two;
};
class VarRefNode : public Node
{
public:
VarRefNode(const std::string & str) { m_string = str; }
std::string getString() { return m_string; }
protected:
std::string m_string;
};
#endif

View File

@ -85,6 +85,10 @@ width return WIDTH;
*yylval = new IdentifierNode(yytext);
return IDENTIFIER;
}
\$[a-zA-Z_][a-zA-Z_0-9]* {
*yylval = new VarRefNode(yytext+1);
return VARREF;
}
#.*\n yylloc->first_line++; yylloc->last_line++;
\n yylloc->first_line++; yylloc->last_line++;

View File

@ -101,6 +101,7 @@ static refptr<Node> parsed_scene_node;
%token WIDTH;
%token IDENTIFIER;
%token VARREF;
%left PLUS MINUS
%left TIMES DIVIDE
@ -583,6 +584,7 @@ term: factor { $$ = $1; }
;
factor: number { $$ = $1; }
| VARREF { $$ = $1; }
| LPAREN expression RPAREN { $$ = $2; }
;