[antlr-interest] Example of a scripting language?
Rick Mann
rmann at latencyzero.com
Fri Oct 12 12:32:00 PDT 2007
I'm trying to build a very simple scripting language that has a C++/
Java-like syntax for defining simple and aggregate types. I have a
GUI application that allows the user to type in commands in the
language, but I'm not sure how to wire in the generated parser.
I figure I will call the parser multiple times as the user enters
lines, but I have two types of state to keep track of.
One is the parser's actual state. It would be easiest for me to feed
the parser a line at a time, as the user types it, but I'm not sure
how to do this. One line may not represent a completely parseable
(sp?) set of input (i.e., a statement may span multiple lines).
The other state is the result of multiple input statements. I think I
understand how to maintain this state; it's simply up to the
generated code to put it somewhere it can be kept.
Examples (">> " is my system's prompt):
>> UInt32 foo = 123; // UInt32 is a pre-defined type reprsenting a
32-bit unsigned integer
No output as a result of this parser input.
>> send foo;
Sent 4 bytes // System's output into interpreter window.
>>
>> struct FooT {
No output, the call to the parser has returned, and it needs more, so
the prompt is displayed again:
>> UInt32 field1;
No output, but more inptu is needed:
>> };
No output, but now a new type is defined, "FooT".
>> FooT myFoo;
No output, but FooT is instantiated as myFoo.
>> myFoo.field1 = 123;
myFoo.field1 gets assigned a value.
Etc. This seems like it should be straightforward, but most of the
examples show complete translations. Can someone point me in the
right direction? Thanks!
--
Rick
More information about the antlr-interest
mailing list