[Gambas-user] RE: C or Gambas? thats the question!

R Onstenk ronstk at ...239...
Wed Sep 3 17:51:34 CEST 2003


Hi Nelson

Well The .bas file is a Basic file (program).
Lexical detection is may be wrong bit it checks the grammar
and construction of the script.
Not what we are saying but how it is done.
It read the file to find the basic key words like FOR NEXT etc.
In my example it checks the grammar of language Basic if it is
correct for keywords and symbols and return every word it finds.
At this stage you can see it as a pre processor before the
real interpreter get the text to handle.
It is only a trial for using C as programming language.

Interpreting basic programs I have already made once.
The same way you can do with for example a SQL line.
Bring it back to basic constuction.

  SELECT field1, field2 FROM table1, table2 WHERE table1.idx=table2.idx
  The keywords are here in uppercase and the symbols in lowercase.

As the SQL Language constuction (grammar) says there are 1 or more
fields (symbols) for the keywords SELECT, FROM and WHERE.

Reading the symbols and punctation after WHERE is a recursieve loop
to get the 1 or more relation conditions.
Think the same as IF condition THEN in the basic grammar.

When this method is understand then you can easy transfer the symbols to
array's
Give the keyword a token (p-code) then you know what to expect and handle
the information i.e.

typedef instruction
	command=integer   /* code to use for SELECT
	arFields=array[]  /* store of field names
endtype

With Split and Join on the array you can easy asemble and disasemble
the line parts for human readability and for the program not needed.

For the WHERE statement the same
WHERE (condition relation condition) [ relation (condition relation
condition) [...]]

This way I made a form to create SQL lines.
In a cell there are several dropdown boxes.
Each cell has 1 for table,field,sort,condition etc.
By selection in the combobox you define what symbol is used
and the combobox position tells where in the SQL line it must be.
This form is a webpage and sends only the arrays to the server.
The server checks and reconstruct the SQL line and send it to MySQL.

If you don't send the symbol name but the field index in the
the text to send is smaller and charactersets UTF8 or UTF16
doesn't mather so much.
Pro)
  This way you have also a protection agains bad users intentions.
  No nasty hidden '; DELETE * FROM table1' or other at the end.
Against)
  The admin should not add a new field when there is a user
  working with it. Can be resolved with sessions.

If you know MS Access there it is the graphical query
designer. You build it with those cells and if you ask
the SQL line it does the same to create it.

May be I can convert it to a Gambas application (example).
Could be nice project too for learning how Gambas works.
This way you have rapid SQL line creator for dummys.
Select what you want and the progam makes the correct
SQL line. It's now a set of jscript,php and html code.

This way working is the same as using a form
designer instead of typing the textfile by hand.
Guru's prefer typing by hand but the remaining?

Afterall the basic form/sql line are there and adding
by hand can always be done if you know the grammar.

----------
Ron





More information about the User mailing list