Creating scripting language with JavaCC
- From: harshadchavan@xxxxxxxxx
- Date: 1 Nov 2007 01:35:26 -0700
Hello all,
I want to create a simple scripting language - something like VBScript
or toned down perl/shell script.
How do I create an AST for this, where there are multiple statements
e.g.
-------------
Input
-------------
String ac;
ac = '123132' + '1233223';
-----------------------------------------
I have already built an expression language, so there is no problem
with forming AST for that.
My main expression for parsing is
(
((
LOOKAHEAD(2)
identifier() identifier() //identifier
forms IdentifierNode
|
LOOKAHEAD(3)
identifier() eq() orExpression() // eq() is "="
|
orExpression() // orExpression is
any RValue expression.
)
delimiter()) #StatementNode(true)
)*<EOF>
Now when I execute this with above input , It gives me following
output for dumpTree
StatementNode
IdentifierNode
IdentifierNode
Which tells me that it forms the tree for the first statement only and
not the second one. Now question is how do I get multiple statements
with their own tree.
One thing I can do is maybe (and if there is any option of doing that)
form the tree for each statement and push it in a queue and then
evaluate each tree one by one from the queue.
Is that a good/normal approach?
Can anybody help? or point me to a good resource?
Thanks in advance.
Harshad
.
- Follow-Ups:
- Re: Creating scripting language with JavaCC
- From: Paul Cager
- Re: Creating scripting language with JavaCC
- Next by Date: Re: Creating scripting language with JavaCC
- Next by thread: Re: Creating scripting language with JavaCC
- Index(es):
Relevant Pages
|
|