[EMAIL PROTECTED]:
>One thing that I always think about but never get around to trying is to run
>iyacc against the Unicon grammar and have it drive a mockup of the Unicon
>virtual machine.  You would wind up with an "interpreted translated
>interpreter" (or something like that) which would probably not have stellar
>performance, but might be decent and general for not-too-complex expressions. 
> 
>
>I wonder if anyone has attempted such a feat.

In Ruby these days, metaprogramming and DSLs are big.  In order to rely
less on eval (even though Ruby has it), they've been implementing
methods for the common cases.  E.g.,

  v1 = 'a'
  v2 = 'b'

  iv1 = "@#{v1}".intern  # => :@a
  iv2 = "@#{v2}".intern  # => :@b

  class Blob; end
  blob = Blob.new
  blob.instance_variable_set(iv1, 1)
  blob.instance_variable_set(iv2, 20*60*60*1000)

  # (not really eval, just changes scope)
  Blob.class_eval {
    define_method(v2.intern) { instance_variable_get(iv2) }
    define_method("#{v2}=".intern) {|x| instance_variable_set(iv2, x) }
  }

  blob.b       # => 72000000
  blob.b = 42
  blob.b       # => 42

It's not very pretty, but I think it might not be too hard to implement
similar things in Unicon.

Steve

>On Wed, 30 Aug 2006 07:07:15 -0700, Steve Wampler wrote:
>
>> 
>> Lu Song wrote:
>> > Dear Everyone,
>> >  
>> > I have a quesiton.
>> >  
>> > Can Unicon run the Unicon source code reading from input file?
>> > for example,
>> > --------------------------------
>> > a:=1
>> > b:=20*60*60*1000
>> > --------------------------------
>> >  
>> > I learned that Lisp could do it.
>> 
>> As Clint reports, there is no full equivalent of Lisp's eval function
>> (One of the problems is that Unicon has a *much* richer syntax
>> than Lisp and so an embedded parser isn't as simple to implement.
>> In this day and age of huge RAM, it would certainly be doable
>> however.)
>> 
>> For simple subsets of the language, such as the simple expressions
>> and assignments in your example, it's really easy to write your
>> own parser, however.  I think there is at least one such solution
>> in the IPL - you might check there to see if anything suits
>> your needs.
>> 
>> I also think I remember code that ran an external Icon
>> translator on source code strings and then could execute
>> the result - you might see if that's available in the IPL.
>> It's an awkward approach in some respects, but nice in
>> the fact that it doesn't require writing your own parser/
>> code generator.
>> 
>> Hmmm, that might be an interesting project - extending
>> that solution (of running the Unicon icont externally) so
>> it could be invoked in a new 'thread' as a translation pipe.
>> 
>> -Steve
>> 
>> -- 
>> Steve Wampler -- [EMAIL PROTECTED]
>> The gods that smiled on your birth are now laughing out loud.
>
>-------------------------------------------------------------------------
>Using Tomcat but need to do more? Need to support web services, security?
>Get stuff done quickly with pre-integrated technology to make your job easier
>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>_______________________________________________
>Unicon-group mailing list
>Unicon-group@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/unicon-group
>

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Unicon-group mailing list
Unicon-group@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to