View previous topic :: View next topic |
Author |
Message |
Brent Site Admin
Joined: 01 Jul 2005 Posts: 800
|
Posted: Jan 19th, 2014, 5:28am Post subject: Experiment - Quine |
|
|
I was looking at Rosetta Code today and happened upon the Quine task, which inspired me to try to write one in ViviFire. I decided to use some features that I've considered but haven't yet implemented in the parser. If you all find this syntax agreeable, I'll probably add support in the next EXE release.
Code: | Dim a$()={"Dim a$()={","#null a$(0)+$34+a$(0)+$34+$44+$34+a$(1)+$34+$125+$NL+a$(1)+$NL"}
#null a$(0)+$34+a$(0)+$34+$44+$34+a$(1)+$34+$125+$NL+a$(1)+$NL |
The features include:- Implicit dimensioning and initialization of arrays by using a list of elements inside curly braces
- String constants by ASCII code/Unicode offset by preceding a number with a dollar sign, including all number bases (e.g. $42, $H2A, $O52, $B101010).
- Similarly, string constants by (abbreviated) name, such as the $NL above which represents the platform-dependent newline character/sequence.
Semantically, the above code implies that the #Null object has a default method that sends a string to some output buffer such as stderr or a debugger's output window. I'm also considering naming this #Debug instead.
What do you think? _________________ Brent |
|
Back to top |
|
|
nukesrus21 Junior Member
Joined: 19 Oct 2010 Posts: 13 Location: Southbury, CT
|
Posted: Jan 20th, 2014, 4:44pm Post subject: Re: Experiment - Quine |
|
|
Brent,
These would all be great features!!
I would definitely change the #Null to #Debug though as I always think of the null character when I see something like #Null. #Debug would help to ensure that the user knows whatever comes afterward will be sent to an output of some kind. I assume you'll automatically detect if a (the) debugger is open and send it to that; otherwise I think you may need another variable to tell the language where the output is to be sent.
Just my thoughts on it....
{:0)
Brandon |
|
Back to top |
|
|
STPendl Full Member
Joined: 20 Aug 2007 Posts: 161 Location: Austria
|
Posted: Jan 20th, 2014, 6:37pm Post subject: Re: Experiment - Quine |
|
|
I think that #null should be reserved to represent nothing or uninitialized.
#debug would be simple and understandable as triggering debug output. _________________ Stefan
Any code I post can be freely used, just give credit. |
|
Back to top |
|
|
Brent Site Admin
Joined: 01 Jul 2005 Posts: 800
|
Posted: Jan 20th, 2014, 11:52pm Post subject: Re: Experiment - Quine |
|
|
Thanks for the comments. I just added support for the mentioned constructs. But then I discovered that my example has a syntax error.
The second line begins #null a$(0), which is parsed as a normal method call rather than the expected anonymous method call. After this, the parser expects a line break, but finds a + instead, causing the "oh so helpful" error -- line 2 col 12: this symbol not expected in Newline. I probably should do something about that.
The correct code follows. Code: | Dim a$()={"Dim a$()={","#debug (a$(0)+$34+a$(0)+$34+$44+$34+a$(1)+$34+$125+$NL+a$(1)+$NL)"}
#debug (a$(0)+$34+a$(0)+$34+$44+$34+a$(1)+$34+$125+$NL+a$(1)+$NL) |
_________________ Brent |
|
Back to top |
|
|
STPendl Full Member
Joined: 20 Aug 2007 Posts: 161 Location: Austria
|
Posted: Jan 21st, 2014, 8:49am Post subject: Re: Experiment - Quine |
|
|
What I still see as strange is the missing closing curly brace in the first line of code.
If this is the supported syntax, it is fully on the contrary to what one is used from other languages utilizing curly braces. _________________ Stefan
Any code I post can be freely used, just give credit. |
|
Back to top |
|
|
Brent Site Admin
Joined: 01 Jul 2005 Posts: 800
|
Posted: Jan 21st, 2014, 4:52pm Post subject: Re: Experiment - Quine |
|
|
Stefan, the closing curly brace is represented by $125 which translates into LB as Chr$(125). The second line cannot contain any quotes, otherwise they'd need to be escaped in the first line. This makes the code simpler. _________________ Brent |
|
Back to top |
|
|
|