To help us all solve the same problem, I'm submitting this as a syntax. I mix lexical and syntactic, and imply that whitespace is ignored between tokens. I also assume */ is higher than +-. Please comment.
john
Program := SourceLine*
SourceLine := Statement* (Newline | Eof)
Statement := (Variable | Free | Assignment | Output) ';'
Newline := '\\r'? '\\n'
Eof :=
Variable := "var" Identifier ('=' Expression)?
Free := "free" '(' Identifier ')'
Assignment := Identifier '=' Expression
Output := "output" '(' Expression ')'
Identifier := [a-zA-Z][A-Za-z0-9]*
P1: M3 - Parallelized Parser Formula Interpreter
Please place link to Rules as sticky thread
Gripe:
You have this niceThreading Challenge forum, which is easy to get to, but to get a copy of the rules for the particular challenge you have several click hoop jumps to find the rules. Can you please place in each threading challenge forum a sticky thread containing current and revised rules for that challenge. Example:
Official rules (PDF):http://software.intel.com/file/36890
Jim Dempsey
Input clarification
The .PDF filerules state the line termination character is semicolon (;) and makes no reference as to what constitutes an inputline, in particularis it CR, LF, CRLF or the aformentioned are considered whitespace. Meaning
---------------------
var x=50;var y=10
; var z = 9;
---------------------
is valid input. I will have to assume since this is not mentioned that this is left as an implementation detail
Note, in your "Valid keywords and functions" table, section "var", lines 3 and 4, column Examples has
var decimal =
345.212312321;
Input encoding
Can we get more specifics on input encoding? There is some mention of "entities" regaridng quotes. Does that mean UTF-8 is possible? UTF-16 with BOM? HTML or XML entity codes other than quote?
Integer division
Since javascript and standard datatypes in other languages are both mentioned, integer division is a gray area. In C,
means i = 2. This is what is expected if the standard int datatype is used. In javascript, however,int i = 5 / 2;
gives us i = 2.5. Which of these is valid?var i = 5 / 2;
Variable initialization/assignment questions
1) Is it possible to define a variable and initialize it later?
For example, var x;
x = 1;
2) Can type of variable change after its first definition?
For example, var i = 1;
i = 2;
i = 2.0;
i = "i";
Definition of value
What is definition of value mentioned in, for example, string(variableName | value)? Are value and expression same? It looks like that value can take the form 32 * 12 * multiplier.
What can be value of right hand side of arithmetic = operator?
behaviour on error
there are various errors that may occur - syntax errors, type coercion errors (using a number where a string is expected), arithmetic errors (divide by 0), and possibly others (overflow?) I guess the error message, line number etc. is written to stderr. What output is expected to be written to the output file when these errors occur? Is the output ignored, oor should it contain all output statements up to the point of the line that is in error?
entities and syntax clarification
The text mentions javascript and also the XML entities " and " Is the parser expected to handle these entities or are these just by way of example/clarification/obfuscation?
If entities are to be recognised, is it just specifically these two, or should all XML entities and character references be recognised, e.g. & and other character refereneces, say A for 'A'.
What is allowed within a string?Will quotes appear within strings? Are entities within strings allowed?
Multiprecision needed?
do we have to deal with arbitrary precision numbers
