I am experimenting with DSL and wanted to give a try with Rascal. After installation of Eclipse (oxygen) and Rascal plugin I was able to play around with Rascal code snippets.
When trying to play with the Pico language I have few problems for which I cannot find a proper solution. Maybe somebody has some ideas.
issue 1: when using the example text (below) copied from the rascal website (to me this sounds proper Pico code). It gives an error directly after the last closing end. Removing code from the while do block results an error free
begin declare input : natural,
output : natural,
repnr : natural,
rep : natural;
input := 14;
output := 1;
while input - 1 do
rep := output;
repnr := input;
while repnr - 1 do
output := output + rep;
repnr := repnr - 1
od;
input := input - 1
od
end
issue 2: with proper pico code there is no syntax highlighting shown; all black code.
Has anybody encountered this before and if so have a solution?
It would help if you put some URLs or source code examples of what you are trying to run.
I've tried the code at http://tutor.rascal-mpl.org/Recipes/Basic/Basic.html#/Recipes/Languages/Pico/Syntax/Syntax.html and parsed this with it: http://tutor.rascal-mpl.org/Recipes/Basic/Basic.html#/Recipes/Languages/Pico/Pico.html using this:
rascal>parse(#start[Program], readFile(|project://rascal-test-library/src/hello.pico|), |project://rascal-test-library/src/hello.pico|)
start[Program]: (start[Program]) `begin declare input : natural,
output : natural,
repnr : natural,
rep : natural;
input := 14;
output := 1;
while input - 1 do
rep := output;
repnr := input;
while repnr - 1 do
output := output + rep;
repnr := repnr - 1
od;
input := input - 1
od
end`
So it seems to work for me. Could you show the code that you are running?
Related
I am trying to write a multi conditional IF statement or an IF / AND IF statement in Report Builder Enterprise V20.03 build 182 and I am not having luck.
I am basically nesting IF statements, but output shows as if the first statement is always true. The code sample is below:
begin
if DayCnt9.Value = 'Days' //This if statement and next are the two that should be met for the Value := 90
then begin
if WorkOrders['CompletedDate'] - (Variable1.Value + WorkOrders['GracePeriod']) < 1
then begin
Variable2.Font.Color := cLBlack;
Value := 90;
end
else begin
Variable2.Font.Color := cLRed ;
Value := 100;
end
-note I removed the following code from the original question because it doesn't add to the context of the question. "if (WorkOrders['CompletedDate'] > 2) //This is only looking to see if the WO is complete"
I have written a program which executes properly in plsql but the output is wrong. Logically I donot see any issue with the code. Here is the code:
begin
inpstr := rtrim(ltrim(regexp_replace(inp,'\s{2,}','')));
lastpos := instr(inpstr,' ',-1);
out3 := SUBSTR(inpstr, INSTR(inpstr,' ',-1) + 1);
pos := instr(inpstr,' ');
out1 := substr(inpstr,1,pos);
out2 := substr(inpstr,pos,lastpos);
end;
O/P:
dbms_output.put_line('First Word:: '||out1||' '||'Second Word:: '||out2||' '||'Lastword:: '||out3);
PROCEDURE SPLITWORDS compiled
anonymous block completed
First Word:: Welcome Second Word:: to the world of analyti Lastword:: analytics!
But the second word should retrieve 'to the world of' but it fetches analyti.
Could anyone tell me whats wrong with my code.
Thanks,
Dex.
When you assign out2, you at least have to substract pos from lastPos.
Because lastPos in your sample-text "Welcome to the world of analytics!" will be 24 and pos will have 8, so the substring from pos 8 with a length of 24 is ... right: " to the world of analyti"
The third parameter of the substr function is the length of the substring, not the location of the ending character. Subtracting pos from lastpos (see below) would allow your code to work.
out2 := substr(inpstr, pos, lastpos - pos);
I'm using code from this article:
How to Convert Numbers (Currency) to Words
I can't seem to understand how the following code works exactly.
try
sIntValue := FormatFloat('#,###', trunc(abs(Number)));
sDecValue := Copy(FormatFloat('.#########', frac(abs(Number))), 2);
if (Pos('E', sIntValue) > 0) then // if number is too big
begin
Result := 'ERROR:';
exit;
end;
except
Result := 'ERROR:';
exit;
end;
How is it checking if the number is too big using the Pos() function? Why is it searching for E in an Integer? This make no sense to me. I would apprecaite any explanation (the code works just fine, I just want to understand why and how).
The code is checking for the use of scientific notation. That is where you write a number like 1000 as '1E3'.
The code is faintly ridiculous though. Hard to know why the author did not use the > comparison operator.
OK, so here is what i mean since i couldnt think of a better title, I have 2 editbox's. 1 is for input of a string and the other is for the output.
ive been experimenting with edit2.text := LowerCase (edit1.text); & edit2.text := ReverseString (edit1.text);
i want to use the functions LowerCase & ReverseString at the same time so it both converts the capitals string to lowercase and reverses it also.. i just cant figure out how to do this without throwing all kinds of compiler errors, can anyone help me out
You should do
Edit2.Text := ReverseString(LowerCase(Edit1.Text));
Alternatively, since these functions commute, you can do
Edit2.Text := LowerCase(ReverseString(Edit1.Text));
How about edit2.text := LowerCase(ReverseString(edit1.text)) ?
I'm trying to print directly to a printer using esc/p commands (EPSON TM-T70) without using printer driver. Code found here.
However, if I try to print any strings, they are truncated. For example:
MyPrinter := TRawPrint.Create(nil);
try
MyPrinter.DeviceName := 'EPSON TM-T70 Receipt';
MyPrinter.JobName := 'MyJob';
if MyPrinter.OpenDevice then
begin
MyPrinter.WriteString('This is page 1');
MyPrinter.NewPage;
MyPrinter.WriteString('This is page 2');
MyPrinter.CloseDevice;
end;
finally
MyPrinter.Free;
end;
Would print only "This isThis is"! I wouldn't ordinarily use MyPrinter.NewPage to send a line break command, but regardless, why does it truncates the string?
Also notice in RawPrint unit WriteString function:
Result := False;
if IsOpenDevice then begin
Result := True;
if not WritePrinter(hPrinter, PChar(Text), Length(Text), WrittenChars) then begin
RaiseError(GetLastErrMsg);
Result := False;
end;
end;
If I put a breakpoint there and step through the code, then WrittenChars is set to 14, which is correct. Why does it act like that?
You are using a unicode-enabled version of Delphi. Chars are 2 bytes long. When you call your function with Length(s) you're sending the number of chars, but the function probably expects the size of the buffer. Replace it with SizeOf(s) Length(s)*SizeOf(Char).
Since the size of one unicode char is exactly 2 bytes, when you're sending Length when buffer size is required, you're essentially telling the API to only use half the buffer. Hence all strings are aproximately split in half.
Maybe you can use the ByteLength function which gives the length of a string in bytes.