what kind of scripting language is this? - scripting-language

I have to modify a scr.file at work. The script was purchased externally several years ago. I can unterstand the code to some extent, but i can't recognize what scripting language it's written in.
Heres a code snippet:
main()
{
_ErrLevel->Set(0);
_ErrExecLevel->Set(1);
_ErrExecTraceLevel->Set(2);
_ActualLevel->Set($_ErrExecTraceLevel);
_ExtSysID->Set("TDM");
local tString sScriptName("NFORG.scr");
env->PutEnv("DB_protID", "NFORG");
local tInt iMsgCounter(0);
local tInt iError(0);
local tDateTime datetime();
local tString sDateTime();
local tSql sqlTmp();
msg->SetMsgOutputToDB(139);
sqlTmp->Execute(,0, "delete from DB_prot
where DB_prot.protID = 'NFORG'
and DB_prot.protTIMESTAMP < ($THISTIMESTAMP - 86400)");
sqlTmp->Commit();
if($_ActualLevel >= $_ErrExecLevel){iMsgCounter++;msg->Message("Scr: $sScriptName$ / (%03s) START of NFORG loop.", "$iMsgCounter$");}
msg->Sleep(1000);
env->PutEnv("NFORGLOG", "$&DB_CLIENTHOME$\TMP", 1);
_ENVVAR->Set("NFORG");
global tTable tblFile();
if(!tblFile->SetDir("$_ENVVAR", "*.org",0,0,0,"BaseFileName"))
{
msg->Sleep(1000);
if($_ActualLevel >= $_ErrExecLevel){iMsgCounter++;msg->Message("Scr: $sScriptName$ / (%03s) END of NFORG loop.", "$iMsgCounter$");}
msg->ResetMsgOutputToDB();
return SOC_OK;
}
if($tblFile->CountRows == 0)
{
if($_ActualLevel >= $_ErrExecLevel){iMsgCounter++;msg->Message("Scr: $sScriptName$ / (%03s) END of NFORG loop.", "$iMsgCounter$");}
msg->ResetMsgOutputToDB();
return SOC_OK;
}
else
{
if($_ActualLevel >= $_ErrExecLevel){iMsgCounter++;msg->Message("Scr: $sScriptName$ / (%03s)", "$iMsgCounter$");}
}
_DoCopy->Set("1");
Can anyone recognize the language?
I am grateful for any help.

Based on a few searches of functions here, It appears to be a language called Root:
https://en.wikipedia.org/wiki/ROOT
"CERN maintained a program library written in FORTRAN for many years; development and maintenance were discontinued in 2003 in favour of ROOT, written in C++."
Good luck :)

Related

LUA: Using multiple variables in an if-not then statement?

I'm working on a script for a garrysmod server and I'm completly blanking on this, I used to remember but now I can't.
I'm using this block of code,
if ent:IsVehicle() then
if ent:GetModel() ~= { "models/mafia2/shubert_taxi.mdl", "models/mafia2/parry_bus.mdl", "models/mafia2/smith_200_p_pha.mdl" } then
client:Freeze(true)
self.Owner:setAction("Chopping", time, function()
ent:Remove()
nut.item.spawn("carparts", self:GetPos() + Vector(math.Rand(1,20), math.Rand(1,20),20), nil, Angle(0, 0, 0 ))
client:Freeze(false)
self.Owner:notify("You've chopped a car.")
end)
end
originally it was if ent:GetModel() ~= "models/mafia2/shubert_taxi.mdl" and that worked fine, however I want to restrict 3 seperate models. Does anybody know how to do this?
You can use table.hasValue function:
if ent:IsVehicle() then
local models = { "models/mafia2/shubert_taxi.mdl", "models/mafia2/parry_bus.mdl", "models/mafia2/smith_200_p_pha.mdl" }
-- Notice the not keyword.
if not table.hasValue(models, ent:GetModel()) then
....

nodemcu string.format odd results

I need a specific format for a float number: (sign)xx.dd
when trying to set a string.format for thiss format I get odd results.
h= 5.127 --(it should beconverted to +05.13)
print(string.format("%+05.2f",h))
--> 05.13
print(string.format("%+06.2f",h))
--> 005.13
h= -5.127 --(it should beconverted to -05.13)
print(string.format("%05.2f",h))
--> -5.13
print(string.format("%06.2f",h))
--> 0-5.13
Of course, I have an easy workaround, but I think that there is something wrong in this build.
build created on 2018-04-09 15:12
powered by Lua 5.1.4 on SDK 2.2.1(cfd48f3)
BR,
eHc
This is a bug (or undocumented deficiency) in NodeMCU.
Lua implements most of the handling of string.format format specifiers by handing them off to the C standard library's sprintf function. (There are a few things sprintf allows that Lua doesn't, but + ought to work fine.)
NodeMCU has modified Lua to replace most (or all) of the standard library calls with calls to replacement functions defined by NodeMCU (which is normally crazy, but maybe okay in the embedded systems domain). NodeMCU's sprintf implementation doesn't support +.
This is the relevant code from NodeMCU's source (c_stdio.c). Notice that unknown characters in the format specifier are silently ignored:
for (; *s; s++) {
if (strchr("bcdefgilopPrRsuxX%", *s))
break;
else if (*s == '-')
fmt = FMT_LJUST;
else if (*s == '0')
fmt = FMT_RJUST0;
else if (*s == '~')
fmt = FMT_CENTER;
else if (*s == '*') {
// [snip]
// ...
} else if (*s >= '1' && *s <= '9') {
// [snip]
// ...
} else if (*s == '.')
haddot = 1;
}
Similarly, the 0 formatting is not implemented currently for numbers -- as you have noticed, it just pads on the left regardless of sign.

SwaggerUI doesn't show model schema for collection in POST body parameter

I downloaded SwaggerUI in June 2014, it is not easy for me to find out what version it was as I just downloaded the dist folder.
In these months I've been using Swagger for documenting the REST API I am building with Jersey, I found that the UI was not showing the model and model schema in the Data Type column for body parameters that are collections in my case a List, it only shows the word "array".
It seems that this issue is solved in newer versions, however I made several customization to the code and downloading the new version is not an option for me.
I want to know what part of the code I should modify to make this work.
I found the part that needs to be updated in my version of swagger.js is:
SwaggerOperation = (function() {
...
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
parameter = _ref1[_i];
parameter.name = parameter.name || parameter.type || parameter.dataType;
type = parameter.type || parameter.dataType;
// ++++ Add this:
if(type === 'array') {
type = 'array[' + parameter.items.$ref + ']';
}
// ++++
if (type.toLowerCase() === 'boolean') {
parameter.allowableValues = {};
parameter.allowableValues.values = ["true", "false"];
}
...
After that the parameter view looks like this:
I posted this same finding in the SwaggerUI github project issue tracker: https://github.com/wordnik/swagger-ui/issues/400

Any suggestions about how to implement a BASIC language parser/interpreter?

I've been trying to implement a BASIC language interpreter (in C/C++) but I haven't found any book or (thorough) article which explains the process of parsing the language constructs. Some commands are rather complex and hard to parse, especially conditionals and loops, such as IF-THEN-ELSE and FOR-STEP-NEXT, because they can mix variables with constants and entire expressions and code and everything else, for example:
10 IF X = Y + Z THEN GOTO 20 ELSE GOSUB P
20 FOR A = 10 TO B STEP -C : PRINT C$ : PRINT WHATEVER
30 NEXT A
It seems like a nightmare to be able to parse something like that and make it work. And to make things worse, programs written in BASIC can easily be a tangled mess. That's why I need some advice, read some book or whatever to make my mind clear about this subject. What can you suggest?
You've picked a great project - writing interpreters can be lots of fun!
But first, what do we even mean by an interpreter? There are different types of interpreters.
There is the pure interpreter, where you simply interpret each language element as you find it. These are the easiest to write, and the slowest.
A step up, would be to convert each language element into some sort of internal form, and then interpret that. Still pretty easy to write.
The next step, would be to actually parse the language, and generate a syntax tree, and then interpret that. This is somewhat harder to write, but once you've done it a few times, it becomes pretty easy.
Once you have a syntax tree, you can fairly easily generate code for a custom stack virtual machine. A much harder project is to generate code for an existing virtual machine, such as the JVM or CLR.
In programming, like most engineering endeavors, careful planning greatly helps, especially with complicated projects.
So the first step is to decide which type of interpreter you wish to write. If you have not read any of a number of compiler books (e.g., I always recommend Niklaus Wirth's "Compiler Construction" as one of the best introductions to the subject, and is now freely available on the web in PDF form), I would recommend that you go with the pure interpreter.
But you still need to do some additional planning. You need to rigorously define what it is you are going to be interpreting. EBNF is great for this. For a gentile introduction EBNF, read the first three parts of a Simple Compiler at http://www.semware.com/html/compiler.html It is written at the high school level, and should be easy to digest. Yes, I tried it on my kids first :-)
Once you have defined what it is you want to be interpreting, you are ready to write your interpreter.
Abstractly, you're simple interpreter will be divided into a scanner (technically, a lexical analyzer), a parser, and an evaluator. In the simple pure interpolator case, the parser and evaluator will be combined.
Scanners are easy to write, and easy to test, so we won't spend any time on them. See the aforementioned link for info on crafting a simple scanner.
Lets (for example) define your goto statement:
gotostmt -> 'goto' integer
integer -> [0-9]+
This tells us that when we see the token 'goto' (as delivered by the scanner), the only thing that can follow is an integer. And an integer is simply a string a digits.
In pseudo code, we might handle this as so:
(token - is the current token, which is the current element just returned via the scanner)
loop
if token == "goto"
goto_stmt()
elseif token == "gosub"
gosub_stmt()
elseif token == .....
endloop
proc goto_stmt()
expect("goto") -- redundant, but used to skip over goto
if is_numeric(token)
--now, somehow set the instruction pointer at the requested line
else
error("expecting a line number, found '%s'\n", token)
end
end
proc expect(s)
if s == token
getsym()
return true
end
error("Expecting '%s', found: '%s'\n", curr_token, s)
end
See how simple it is? Really, the only hard thing to figure out in a simple interpreter is the handling of expressions. A good recipe for handling those is at: http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm Combined with the aforementioned references, you should have enough to handle the sort of expressions you would encounter in BASIC.
Ok, time for a concrete example. This is from a larger 'pure interpreter', that handles a enhanced version of Tiny BASIC (but big enough to run Tiny Star Trek :-) )
/*------------------------------------------------------------------------
Simple example, pure interpreter, only supports 'goto'
------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <setjmp.h>
#include <ctype.h>
enum {False=0, True=1, Max_Lines=300, Max_Len=130};
char *text[Max_Lines+1]; /* array of program lines */
int textp; /* used by scanner - ptr in current line */
char tok[Max_Len+1]; /* the current token */
int cur_line; /* the current line number */
int ch; /* current character */
int num; /* populated if token is an integer */
jmp_buf restart;
int error(const char *fmt, ...) {
va_list ap;
char buf[200];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
printf("%s\n", buf);
longjmp(restart, 1);
return 0;
}
int is_eol(void) {
return ch == '\0' || ch == '\n';
}
void get_ch(void) {
ch = text[cur_line][textp];
if (!is_eol())
textp++;
}
void getsym(void) {
char *cp = tok;
while (ch <= ' ') {
if (is_eol()) {
*cp = '\0';
return;
}
get_ch();
}
if (isalpha(ch)) {
for (; !is_eol() && isalpha(ch); get_ch()) {
*cp++ = (char)ch;
}
*cp = '\0';
} else if (isdigit(ch)) {
for (; !is_eol() && isdigit(ch); get_ch()) {
*cp++ = (char)ch;
}
*cp = '\0';
num = atoi(tok);
} else
error("What? '%c'", ch);
}
void init_getsym(const int n) {
cur_line = n;
textp = 0;
ch = ' ';
getsym();
}
void skip_to_eol(void) {
tok[0] = '\0';
while (!is_eol())
get_ch();
}
int accept(const char s[]) {
if (strcmp(tok, s) == 0) {
getsym();
return True;
}
return False;
}
int expect(const char s[]) {
return accept(s) ? True : error("Expecting '%s', found: %s", s, tok);
}
int valid_line_num(void) {
if (num > 0 && num <= Max_Lines)
return True;
return error("Line number must be between 1 and %d", Max_Lines);
}
void goto_line(void) {
if (valid_line_num())
init_getsym(num);
}
void goto_stmt(void) {
if (isdigit(tok[0]))
goto_line();
else
error("Expecting line number, found: '%s'", tok);
}
void do_cmd(void) {
for (;;) {
while (tok[0] == '\0') {
if (cur_line == 0 || cur_line >= Max_Lines)
return;
init_getsym(cur_line + 1);
}
if (accept("bye")) {
printf("That's all folks!\n");
exit(0);
} else if (accept("run")) {
init_getsym(1);
} else if (accept("goto")) {
goto_stmt();
} else {
error("Unknown token '%s' at line %d", tok, cur_line); return;
}
}
}
int main() {
int i;
for (i = 0; i <= Max_Lines; i++) {
text[i] = calloc(sizeof(char), (Max_Len + 1));
}
setjmp(restart);
for (;;) {
printf("> ");
while (fgets(text[0], Max_Len, stdin) == NULL)
;
if (text[0][0] != '\0') {
init_getsym(0);
if (isdigit(tok[0])) {
if (valid_line_num())
strcpy(text[num], &text[0][textp]);
} else
do_cmd();
}
}
}
Hopefully, that will be enough to get you started. Have fun!
I will certainly get beaten by telling this ...but...:
First, I am actually working on a standalone library ( as a hobby ) that is made of:
a tokenizer, building linear (flat list) of tokens from the source text and following the same sequence as the text ( lexems created from the text flow ).
A parser by hands (syntax analyse; pseudo-compiler )
There is no "pseudo-code" nor "virtual CPU/machine".
Instructions(such as 'return', 'if' 'for' 'while'... then arithemtic expressions ) are represented by a base c++-struct/class and is the object itself. The base object, I name it atom, have a virtual method called "eval", among other common members, that is the "execution/branch" also by itself. So no matter I have an 'if' statement with its possible branchings ( single statement or bloc of statements/instructions ) as true or false condition, it will be called from the base virtual atom::eval() ... and so on for everything that is an atom.
Even 'objects' such as variables are 'atom'. 'eval()' will simply return its value from a variant container held by the atom itself ( pointer, refering to the 'local' variant instance (the instance variant iself) held the 'atom' or to another variant held by an atom that is created in a given 'bloc/stack'. So 'atom' are 'inplace' instructions/objects.
As of now, as an example, chunk of not really meaningful 'code' as below just works:
r = 5!; // 5! : (factorial of 5 )
Response = 1 + 4 - 6 * --r * ((3+5)*(3-4) * 78);
if (Response != 1){ /* '<>' also is not equal op. */
return r^3;
}
else{
return 0;
}
Expressions ( arithemtics ) are built into binary tree expression:
A = b+c; =>
=
/ \
A +
/ \
b c
So the 'instruction'/statement for expression like above is the tree-entry atom that in the above case, is the '=' (binary) operator.
The tree is built with atom::r0,r1,r2 :
atom 'A' :
r0
|
A
/ \
r1 r2
Regarding 'full-duplex' mecanism between c++ runtime and the 'script' library, I've made class_adaptor and adaptor<> :
ex.:
template<typename R, typename ...Args> adaptor_t<T,R, Args...>& import_method(const lstring& mname, R (T::*prop)(Args...)) { ... }
template<typename R, typename ...Args> adaptor_t<T,R, Args...>& import_property(const lstring& mname, R (T::*prop)(Args...)) { ... }
Second: I know there are plenty of tools and libs out there such as lua, boost::bind<*>, QML, JSON, etc... But in my situation, I need to create my very own [edit] 'independant' [/edit] lib for "live scripting". I was scared that my 'interpreter' could take a huge amount of RAM, but I am surprised that it is not as big as using QML,jscript or even lua :-)
Thank you :-)
Don't bother with hacking a parser together by hand. Use a parser generator. lex + yacc is the classic lexer/parser generator combination, but a Google search will reveal plenty of others.

Why am I getting Divide By Zero Exception on Azure Web Sites?

I've had EPPlus (Office Open XML) working on a Azure Web Role for some time now, but I've been experimenting with Azure Web Sites lately and there I'm getting a very weird error;
[DivideByZeroException: Attempted to divide by zero.]
System.Decimal.FCallDivide(Decimal& d1, Decimal& d2) +0
OfficeOpenXml.Drawing.ExcelDrawing.SetPixelWidth(Int32 pixels, Single dpi) +465
Compliance.Net.CommonCode.PivotGenerator.GeneratePivotTable(ExcelWorksheet dataWorksheet, ExcelWorksheet pivotWorksheet, Int32 endRow)
I am getting this on the same data and code as is running on Azure Web Role.
Edit:
The offending lines look like this:
var chart = pivotWorksheet.Drawings.AddChart("PivotChart", eChartType.ColumnClustered, pivotTable);
chart.SetPosition(endRow + 2, 20, 1, 10);
chart.SetSize(600, 400);
Please note that I have made sure that 'endRow' is > 1.
Any ideas?
Having had the same issue myself I've pulled the EPPlus source and done some sleuthing.
The issue is in ExcelWorkbook.cs line 283 which calls
System.Windows.Forms.TextRenderer.MeasureText(string,Font).Width
which appears to return Zero in an Azure website.
I've just added a line
if (_standardFontWidth == 0) _standardFontWidth = 7;
(7 was the value I was getting locally so it will do as my default - your mileage may vary) meaning I ended up with
public decimal MaxFontWidth
{
get
{
if (_standardFontWidth == decimal.MinValue)
{
var font = Styles.Fonts[0];
System.Drawing.Font f = new System.Drawing.Font(font.Name, font.Size);
_standardFontWidth=(decimal)(System.Windows.Forms.TextRenderer.MeasureText("00", f).Width - System.Windows.Forms.TextRenderer.MeasureText("0", f).Width);
}
if (_standardFontWidth == 0) _standardFontWidth = 7;
return _standardFontWidth;
}
}
Of course this means building EPPlus from source, and you may have a different value for 7, but its a useful workaround for me!

Resources