Re: Announcing Interactive JScript

  • From: "tribble" <lauraeaves@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 8 Feb 2008 13:11:03 -0500

Hi marlon -- I know Sina has volunteered to assist, and indeed he is a great 
source of knowledge, but if you have questions and post them to the list, I 
would also be willing to contribute to your expertise in this area. My 
background comes from doing extensive work on parsing for early C++, which 
(at least while I was working on it) is a bear to parse, compared to C, due 
to the syntax added to C that introduced ambiguities that needed some nifty 
tricks to solve, given the original parser was written using yacc, which is 
not sophisticated enough to handle the ambiguous parts of the grammer 
without some significant overhead.
(Hope you could parse that last sentence...*smile*)
One thing you might consider is to get hold of yacc or bison or some parser 
generator, which typically takes a grammar specification and translates that 
into C or C++ code that implements the parser.  (You don't need to look at 
this code, only worry about the grammar spec.)
You also need a lexical analyzer to scan the text file containing the 
program and translate it into "tokens", or chunks of related characters --  
for example, consecutive alphabetical characters might be put in a chunk 
called IDENTIFIER, where IDENTIFIER is some integer representing all tokens 
of that type.  You also might consider specializing some character sequences 
as individual keywords -- such as FLOAT or EXTERN rather than a plain 
IDENTIFIER.  Of course numbers, character strings and characters (in the 
case of C/C++) would translate in your lexer to specific types of tokens.
You get the idea.
You then write the parser generator file(for example the yacc file) using 
the names of tokens as elements in the grammar. To understand the grammar, 
you should understand the basics of grammar syntax and composition -- each 
statement in the grammar consists of one "production", which specifies how 
the syntax of a construct is laid out.  An example would help:

You want to specify in yacc how an expression looks:

expression : IDENTIFIER
    | NUMBER
    | "(" expression "+" expression ")"
    ;

Here there are 3 productions separated by vertical bars with the group of 
productions being terminated by a semicolon.
So what will parse using this parser? Well, some good examples are

    x   // ok
    (X+2)   // ok
    x+y  // not ok since the grammar requires parentheses around the binary 
operator.

To really understand the grammar fully you need to read up on a little 
theory, such as what BNF is and what an LR(1) grammar is.  Note the grammar 
and the parser are not interchangeable; the grammar is an abstract 
specification defining what is legal or illegal in your file of text.  (Note 
also that you can use yacc to parse non-text files assuming the tokenizer 
knows how to read that file and translate it into tokens for the grammar to 
use.)
If you want to write the parser not using yacc, you need to keep track of 
where you are and what the "follor set" is for that state -- where a follow 
set is the list of tokens that are legal at the state you are in, and define 
what actions to take in what situation.
This is probably getting in too far.  If you start with yacc you can play 
around with grammars before diving into any intense code.

Again, this is a crash course intro to parser and theory.  Hope it helps, 
but if you have questions, I will take a stab at demystifying the subject. 
I'm always happy to talk about parsing as I had my head into it for a long 
time, back in the mid 80s to early 90s.

Happy hacking.
--le


----- Original Message ----- 
From: "Marlon Brandão de Sousa" <splyt.lists@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, February 08, 2008 11:49 AM
Subject: Re: Announcing Interactive JScript


Hello Sina,
Well for me reading a source code and learning from it is harder than
understanding the algorithm and figuring out how to write a already
well underwstood and planned thing. I don't know nothing about
parsers, like if you ask me now to do a c++ syntax analyzer I don't
think I can do it right now, because I can't figure out by my self
what steps are necessary and how to implement it. I have been looking
for tutorials on it, but most part of them use graphycal
representations of concepts or are more concentrated to show "how to
do" and not "how it works".
As Jamal is a nice guy in terms of helping I wanted to study his code
and ask him questions, but a book on the subject would be cool. I am
not a bite counter, and I am better in using logic then in pure math.
I am also a programmer used to do medium level programming, so it
would need to be a not advansed, but not so basic book or something
similar.
I am not doing parsers in my work, this is a subject I am just
interested for but I ahve not still been able to find helpfull
material. I would like to try first doing simple parsers, but after
this when I am good at it I really would like to implement a pre
processor like the C one to parse other language files, but this is a
pretty advansed thing I plan to do latter.
Marlon

2008/2/8, Sina Bahram <sbahram@xxxxxxxxx>:
> Marlon,
>
> What kinds of questions do you have about parsers?
>
> Take care,
> Sina
>
>
> -----Original Message-----
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Marlon Brandão
> de Sousa
> Sent: Friday, February 08, 2008 6:39 AM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Re: Announcing Interactive JScript
>
> Jamal,
> you wrote the parser or it is just a wrapper to a ms compiler / 
> interpreter?
> If you wrote the parser please write me off list, because I have been
> looking for a parser written by someone known and try understanding it, as
> no tutorials shelped me to understand how to build a parser.
> Thanks
> Marlon
>
> 2008/2/8, Jamal Mazrui <empower@xxxxxxxxx>:
> > Thanks, Laura -- with your background, that's particularly meaningful!
> > Jamal
> >  On Thu, 7 Feb 2008, tribble wrote:
> >
> > > Date: Thu, 7 Feb 2008 12:04:28 -0500
> > > From: tribble <lauraeaves@xxxxxxxxx>
> > > Reply-To: programmingblind@xxxxxxxxxxxxx
> > > To: programmingblind@xxxxxxxxxxxxx
> > > Subject: Re: Announcing Interactive JScript
> > >
> > > Cool -- sounds quite useful -- great job
> > >
> > > ----- Original Message -----
> > > From: "Jamal Mazrui" <empower@xxxxxxxxx>
> > > To: <programmingblind@xxxxxxxxxxxxx>; <program-l@xxxxxxxxxxxxx>;
> > > <guispeak@xxxxxxxxxxxxx>
> > > Sent: Thursday, February 07, 2008 7:13 AM
> > > Subject: Announcing Interactive JScript
> > >
> > >
> > > Now available at
> > > http://www.EmpowermentZone.com/ijs.zip
> > >
> > > Interactive JScript
> > > Version 1.0
> > > February 7, 2008
> > > Copyright 2008 by Jamal Mazrui
> > > Modified GPL License
> > >
> > > I have wanted to build a JScript .NET interpreter.  I recently found
> > > an article with code by Andrew Norris that got me started:
> > >
> > > "A Simple JavaScript Command Line Interpreter for Windows in
> JScript.Net"
> > > http://listeningtoreason.blogspot.com/
> > > The original code has now been rewritten and extended considerably.
> > >
> > > Interactive JScript (IJS) is a console mode environment that can
> > > dynamically execute code in the JScript .NET language.  The source
> > > code is in a single file, ijs.js.  a batch file, build.bat, calls
> > > the JScript compiler, jsc.exe, which is distributed with the .NET
> > > Framework.  The resulting executable, ijs.exe, is about 40K in size.
> > > It may be run from any directory on a computer that has the .NET
> > > Framework 2.0 (or above) installed.
> > >
> > > IJS may be used to run or test code in either standard JavaScript or
> > > the enhanced Microsoft JScript 8.0, which also serves as the script
> > > language for web development with ASP.NET.  The home page of the
> > > language is at
> > > http://msdn2.microsoft.com/en-us/library/72bd815a(VS.80).aspx
> > >
> > >   For example, a .js file can define a sophisticated snippet that
> > > may be invoked with the Alt+V command of the EdSharp editor,
> > > available at http://www.EmpowermentZone.com/edsetup.exe
> > >
> > > JScript code can also be evaluated by IronCOM, a COM server that
> > > provides traditional Win32 applications with access to functionality
> > > of the .NET Framework, available at
> > > http://www.EmpowermentZone.com/comsetup.exe
> > >
> > > The HomerKit library for JAWS
> > > http://www.EmpowermentZone.com/kitsetup.exe
> > >  includes a function called JSEval that wraps a JScript call via
> > > IronCOM, thereby enabling JAWS scripts to make .NET calls for
> > > functionality not available in the native scripting language.
> > >
> > > IJS may also be helpful for programming in .NET languages other than
> > > JScript.  Built in commands are defined for inquiring about
> > > available methods, properties, and events via reflection.  You can
> > > explore an object model, test expressions, save working code, and
> > > then convert it to the syntax of another .NET language.
> > >
> > > Reflecting on a COM object requires that a DLL be registered on the
> > > computer, described in the article "Inspect COM Components Using the
> > > TypeLib Information Object"
> > > http://msdn.microsoft.com/msdnmag/issues/1200/TypeLib/
> > >
> > > Registering this DLL (included in the archive) may be done at a
> > > command prompt as follows:
> > > RegSvr32 TlbInf32.dll
> > > Installing EdSharp does this automatically, and makes IJS
> > > conveniently available with the Go to Environment command,
> Control+Shift+G.
> > >
> > > IJS works well with a screen reader, since new output to the console
> > > is automatically read.  Periodically, the cls command is useful for
> > > clearing the screen and eliminating extra verbiage.  IJS may also be
> > > used as a simple, speech-friendly calculator, since most algebraic,
> > > trigonometric, and date calculations may be done with JScript.
> > >
> > > Below is the online documentation, available by entering the help
> > > command in Interactive JScript.  Questions, comments, or code
> > > contributions are welcome.
> > >
> > > Jamal
> > >
> > > Type a JScript statement, followed by Enter (a closing semicolon is
> > > not needed).
> > > Use UpArrow to repeat a command.
> > >  End a line of input with a space and underline ( _) to continue a
> > > multiline block of code.
> > > The prompt then changes from a > to _ character.
> > >
> > > Most classes of the .NET Framework 2.0 may be used in expressions.
> > > Variable types are inferred.
> > > To ease typing, the following namespaces are imported (there classes
> > > may be referenced without a namespace prefix):
> > > Microsoft.VisualBasic
> > > System
> > > System.Collections
> > > System.Data
> > > System.Diagnostics
> > > System.IO
> > > System.Reflection
> > > System.Text
> > > System.Windows.Forms
> > >
> > > In addition, the following built-in commands are available:
> > > quit = end this program
> > > cls = clear the screen
> > > eval FileName = execute a JScript file eval clipboard = execute
> > > JScript code on the clipboard cmd = pass any statement to the
> > > Windows command interpreter (cmd.exe) dos = execute a console-mode
> > > command and display its output log FileName = log output to a file
> > > log off = suspend logging log on = continue logging net Object =
> > > list members of a .NET object constructors Object = list its
> > > constructors only events Object = list its events only fields Object
> > > = list its fields only methods Object = list its methods only
> > > properties Object = list its properties only com Object = list
> > > members of a COM object dir Object = directory of members of either
> > > a .NET or COM object
> > >
> > > __________
> > > View the list's information and change your settings at
> > > //www.freelists.org/list/programmingblind
> > >
> > >
> > > __________
> > > View the list's information and change your settings at
> > > //www.freelists.org/list/programmingblind
> > >
> > __________
> > View the list's information and change your settings at
> > //www.freelists.org/list/programmingblind
> >
> >
>
>
> --
> When you say "I wrote a program that crashed Windows," people just stare 
> at
> you blankly and say "Hey, I got those with the system, for free."
> Linus Torvalds
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>


-- 
When you say "I wrote a program that crashed Windows," people just
stare at you blankly and say "Hey, I got those with the system, for
free."
Linus Torvalds
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: