EBNF notation of a requested programming language PL - ebnf

Let a programming language PL. Its variable definition part is described as follows:
At the beginning we have to start with the keyword "var". After writing this keyword we have to write the variable names(one or more) separated by commas ",". Then a colon ":" is inserted and after that we must write the variable type(say real, boolean, integer or char in my example) followed by a semicolon ";". After doing the previous steps there is the potentiality to declare into a new line new variables(variable names separrated by commas "," followed by colon ":" followed by variable type followed by a semicolon ";"), but we must not use the "var" keyword again at the beginning of the new line( the "var" keyword is written once!!!)
E.g.
var number_of_attendants, sum: integer;
ticket_price: real;
symbols: char;
I would like the EBNF of the above descripted programming language PL to understand it better. Ok, I may have read some texts about EBNF, but in my opinion an example is always something very useful.

Related

What does the colon operator in an expr do?

I am looking at a shell script someone wrote and they wrote this:
expr "$myvariable" : '0*$'
What does this mean?
The colon : in an expr is a matching operator. The strings on the left is tested against a regex on the right. Whatever matches is caught by the regex group ( ). The regex replaces itself with a count of characters, then the : acts kind of like an array indexing operation - you get the left-side string from that location onward (like somestring[n:] in Python)
The '0*$' is matching a zero, any stuff, end of line. I don't know what's in myvariable, but I guess no fireworks unless its value starts with a zero character.
An example of a similar line of shell script - except in assigning the result to a variable, and different specific strings - is explained in http://docstore.mik.ua/orelly/unix3/upt/ch36_23.htm (from O'Reilly Unix Power Tools)
See also http://pubs.opengroup.org/onlinepubs/7908799/xcu/expr.html about halfway down

VBScript SQL select query clarification and variable substitution

I have read this entry (http://stackoverflow.com/questions/8513185/vbscript-to-correctly-re-format-a-delimited-text-file) many times and still do not understand the .Execute section.
WScript.Echo oTDb.Execute(Replace("SELECT * FROM [#T]", "#T", sTbl1)) _
.GetString( adClipString, , "|", vbCrLf, "" )
The pieces I am having trouble with are the [#T] and "#T".
I know it is the "#T" that is reading the filename in the schema file and and the [#T] must be using the "#T" as a substitute. What I cannot find out is where this is mentioned/spoken about.
Some addition questions I have are:
1. If the filename can be substituted with a variable then what else can?
2. What are the rules for maintaining variables
Do they have to start with the # symbol
Are there any reserved words
If they have to start with the # symbol, does the next character have to be a letter
As I am responsible for #Milton's worry/puzzlement:
There is no variable interpolation/substitution in VBScript. Other languages - e.g. Perl - will splice variables or even expression results into string literals when you mark the replacements with special symbols. No such funny letters in VBScript.
SQL dialects allow parameterized commands in which parts to be replaced are marked by ? and/or names prefixed by symbols like #. But here ADO never sees the #T - VBScript's Replace() function has interpolated the table name before the resulting strings is send to .Execute().
Building complex strings from parts (SQL statements, commandlines for .Run or .Exec, ...) by concatenation is cumbersome. The most important drawback is that you can't (proof) read the string anymore for all those " and &.
A simple workaround is to use Replace(), as in
[sResult = ] Replace("SELECT * FROM [#T]", "#T", sTbl1)
I used the # just for letting the placeholder stand out. As you would have to stack/nest the Replace() calls when you need more substitutions on the template, other strategies are worth considering:
writing a function that takes a template string and a dictionary of replacements to apply Regexp.Replace() to the string
using .NET's System.Text.StringBuilder and its .AppendFormat to do the slicing in a sprintf like style

What is the tick or apostrophe character for in Ada?

Very basic question, but just reading through source code and trying to tell what the ' is for and how it differs from .
The ' character is used to introduce an attribute.
For example, Integer'Last is the largest value of type Integer, and Float'Digits is the decimal precision of type Float.
The complete list of language-defined attributes is in Annex K of the Ada Reference Manual.
It's also part of the syntax of qualified expressions, such as Some_Type'(expression).
The . character is used, among other things, to introduce a record component name, such as Obj.Comp, where Obj is a record variable and Comp is a component of that record.
Attributes are defined by the language or by the implementation; component names are defined when the record type is defined.
The apostrophe is also used to delimit character literals: 'x'.

Significance of an ampersand in VB6 function name?

I just got a bunch of legacy VB6 (!) code dumped on me and I keep seeing functions declared with an ampersand at the end of the name, for example, Private Declare Function ShellExecute& . . ..
I've been unable to find an answer to the significance of this, nor have I been able to detect any pattern in use or signature of the functions that have been named thusly.
Anyone know if those trailing ampersands mean anything to the compiler, or at least if there's some convention that I'm missing? So far, I'm writing it off as a strange programmer, but I'd like to know for sure if there's any meaning behind it.
It means that the function returns a Long (i.e. 32-bit integer) value.
It is equivalent to
Declare Function ShellExecute(...) As Long
The full list of suffixes is as follows:
Integer %
Long &
Single !
Double #
Currency #
String $
As Philip Sheard has said it is an indentifier type for a Long. They are still present in .Net, see this MSDN link and this VB6 article
From the second article:
The rules for forming a valid VB variable name are as follows:
(1) The first character must be a letter A through Z (uppercase or
lowercase letters may be used). Succeeding characters can be letters,
digits, or the underscore (_) character (no spaces or other characters
allowed).
(2) The final character can be a "type-declaration character". Only
some of the variable types can use them, as shown below:
Data Type Type Declaration Character
String $
Integer %
Long &
Single !
Double #
Currency #
Use of type-declaration
characters in VB is not encouraged; the modern style is to use the
"As" clause in a data declaration statement.

What's the syntax for this kind of declaration in MASM32?

szCaption db 'System Information', 0
I now understand such declarations:
var_name type default_value
Which has 3 parts. But what's the syntax for the declarations above?
Actually, a better description is:
var_name type comma-separated list of values
In your example, each character in the string is a byte. And so is the trailing zero. MASM allows either characters or numbers.
Your example forms a null-terminated string.
db actually stands for 'define bytes' and can accept as arguments quoted strings (single or double quotes) and numbers, separated by commas.

Resources