Creating scripting language with JavaCC



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

.



Relevant Pages

  • Re: Creating scripting language with JavaCC
    ... I want to create a simple scripting language - something like VBScript ... How do I create an AST for this, ... with their own tree. ... identifier() identifier ...
    (comp.compilers.tools.javacc)
  • Absolute beginner - Need some pointers
    ... My long term goal is to write a scripting language similar to lua to ... implemented an interpreter what acted as a calculator. ... Write a parser to parse the tree structure into bytecode. ...
    (comp.compilers)
  • Re: [Q] How Is AST structured for entire program??
    ... An AST is usually abstract (throwing away unimportant details), ... a parse tree is also an AST (where the set of details thrown away ... A branch of tree is a tree. ... Bob Morgan's compiler construction book and then Steve Muchnik's if you ...
    (comp.compilers)
  • Re: RM and abstract syntax trees
    ... Abstract Syntax Tree (AST), concluding that RM is poorly suited. ... of the parse tree, not the AST. ...
    (comp.databases.theory)
  • Re: Formelparser
    ... >> Abstract Syntax Tree (AST) und Expression Parsing. ... Der Begriff Token ist leider auch im Compilerbau relativ überladen. ... >> wird nahezu immer Parser gennant. ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)