Since I need to generate source-level CFG, I used CFG::buildCFG from libclang and can get the following example output:
[B0 (EXIT)]
Preds (2): B1 B2
[B1]
1: n->l->x = n->x
2: traverse(n->l)
3: traverse(n->r)
4: return;
Preds (1): B3
Succs (1): B0
[B2]
1: return;
Preds (1): B3
Succs (1): B0
[B3]
T: if <null expr>
Preds (1): B4
Succs (2): B2 B1
[B4 (ENTRY)]
Succs (1): B3
But I cannot use opt to generate dot file for visible CFG.
So, how can I convert the aforementioned output to visible CFG (i.e., dot file)?
Related
Consider the following state diagram which accepts the alphabet {0,1} and accepts if the input string has two consecutive 0's or 1's:
01001 --> Accept
101 --> Reject
How would I write the production rules to show this? Is it just:
D -> C0 | B1 | D0 | D1
C -> A0 | B0
B -> A1 | C1
And if so, how would the terminals (0,1) be differentiated from the states (A,B,C) ? And should the state go before or after the input? That is, should it be A1 or 1A for example?
The grammar you suggest has no A: it's not a non-terminal because it has no production rules, and it's not a terminal because it's not present in the input. You could make that work by writing, for example, C → 0 | B 0, but a more general solution is to make A into a non-terminal using an ε-rule: A → ε and then
C → A 0 | B 0.
B0 is misleading, because it looks like a single thing. But it's two grammatical symbols, a non-terminal (B) and a terminal 0.
With those modifications, your grammar is fine. It's a left linear grammar; a right linear grammar can also be constructed from the FSA by considering in-transitions rather than out-transitions. In this version, the epsilon production corresponds to final states rather than initial states.
A → 1 B | 0 C
B → 0 C | 1 D
C → 1 B | 0 D
D → 0 D | 1 D | ε
If it's not obvious why the FSM corresponds to these two grammars, it's probably worth grabbing a pad of paper and constructing a derivation with each grammar for a few sample sentences. Compare the derivations you produce with the progress through the FSM for the same input.
Need some help on this cause I'm getting an issue
I've this three columns (Time, R1 and R2) and I'm trying to count the mismatches between R1 and R2 but for each month (on the time column)
I already used a formula but I'm having an issue to add 1.
https://docs.google.com/spreadsheets/d/1bVP79Gbd14lO6xunu2K9POT7y55yrXegD-cTF70Fb4k/edit#gid=0 (the spreadsheet with the values)
=iferror(if(EOMONTH($A64,0)=$A64,SUMPRODUCT(month(Database!$C$2:$C) = month($A64),--(Database!G$2:G <> Database!H$2:H)),""),"Error")
This part "month(Database!$C$4:$C) = month($A5)" is where I compare the information of the months, ( but I'm having an issue cause cause "month(Database!$C$4:$C)" only retrieves 4 that is the month of april)
This part "(Database!G$4:G <> Database!H$4:H)" is where I compare the columns R1 and R2
The part "EOMONTH($A5,0)=$A5" is where I take the month to based myself
Time R1 R2
2020-04-30 BA BU
2020-04-30 BU BA
2020-04-29 BA BU
2020-04-29 BU BA
2020-04-28 BA BU
2020-04-28 AA BA
2020-04-25 AA BA
2020-04-22 BU BA
2020-04-19 AA BU
2020-04-19 AA BA
2020-03-27 BA AA
2020-03-27 BA AA
2020-03-26 BU AA
2020-03-18 BA AA
2020-03-18 AA BU
Approach
In order to validate the answer I created a test Spreadsheet from a copy of your. In this sheet I created two support columns, one which contains the month number: MONTH($A1) and the other one a flag if the two values R1 and R2 are different: IF($B1=$C1,"",1).
In this way I can use this two support structure to validate the numbers obtained by the formula which didn't use any. I will use a much simpler formula this time to compute the sum =SUMIF(D:D,month(<DATE_VALUE>),E:E).
I will link here the test sheet. As you can see the values are the same as the ones obtained by the formula. So, I can confirm that if you are expecting different results, your database is not consistent.
In conclusion the formula: if(EOMONTH($A64,0)=$A64,SUMPRODUCT(month(Database!$C$2:$C) = month($A64),--(Database!G$2:G <> Database!H$2:H)),"") is working correctly.
I have a variable list in my Makefile like that:
varglob := a1 a2 a3 a4 a5 a6
I want to create a new variable from varglob but eliminate some specific elements for example "a3".
I thought about foreach but my problem is that I don't know how I test with ifneq inside the foreach. So I tried to use shell like that:
varglobelim := $(foreach y, $(varglob), $(shell if [$(y) != "a3"]; then echo $y;fi))
But this solution doesn't success. I get an empty message.
Is there any other suggestions?
filter-out is your friend here:
varglob := a1 a2 a3 a4 a5 a6 b7 b8 b-whatever
has-no-ticket := a3 b% # a3 and all the b's didn't pay the ride
varglobelim := $(filter-out $(has-no-ticket),$(varglob))
I'm currently starting a new language (PROLOG) and I came across with a few issues.
I'm developing a simple board game in which I'm required to print the board. I've developed a PrintBoard and initialBoard predicate (as shown below), and I want to be able to run it from the main predicate, just like so:
printBoard([Head|Tail]) :-
printRow(Head),
printBoard(Tail).
printBoard([]).
printRow([Head|Tail]) :-
write(Head),
write(' '),
printRow(Tail).
printRow([]) :- nl.
initialBoard(Board) :- Board = ([
['b0','b0','b0','b0','b1'],
['b0','b0','b0','b0','b0'],
['b0','b0','b0','b0','b0'],
['b0','b0','b0','b0','b0'],
['b2','b0','b0','b0','b0']
]).
main :- Board = initialBoard(Board), printBoard(Board).
By typing main. in the SICStus PROLOG, the program should output the following:
b0 b0 b0 b0 b1
b0 b0 b0 b0 b0
b0 b0 b0 b0 b0
b0 b0 b0 b0 b0
b2 b0 b0 b0 b0
But, instead, it returns nothing. (Returns no).
The only way it seems to work is by inserting the whole list all over again as the variable, just like so:
main :- printBoard(<insert whole list here>).
Even though I'm looking to run it as:
main :- printBoard(initialBoard(Board)).
The portion of code above works, if main is passed the Board argument, but is it possible without passing it?
Functional code:
main(Board) :- printBoard(initialBoard(Board)).
I have a number of text files I'm looking to send to different destinations depending on whether or not the file contains Cyrillic characters using a batch script. For example:
All Files are located in C:\mydocs. The script will be monitoring this file.
File one: contains all English characters > copy to C:\mydocs\English\
File two: Contains some Cyrillic characters > copy to C\mydocs\Contains_Cyrillic\
Is this possible?
It depends on how your text file is encoded. If the file is unicode, then I'm not sure how to test.
But if the file is extended ascii (1 byte per character), then the meaning of bytes > decimal 127 is dependent on the code page. You can't really tell if the file contains Cyrillic, but you can tell if it contains a byte >127 which is likely to be a non-English character.
The following script should work on Windows XP and later - no need to download anything.
It first creates a file that is >= the length of your file, consisting only of the character "A". Then it uses FC to do a binary comparison and pipes the result to FINDSTR which looks for a value >= 0x80. If one is found, then it returns ERRORLEVEL 1, else it returns ERRORLEVEL 0.
#echo off
call :HasExtendedASCII %1 && (echo English) || echo Not English
exit /b
:HasExtendedASCII
setlocal enableDelayedExpansion
set "tempFile=%temp%\dummyFile%random%.txt"
<nul set /p "=A" >"!tempFile!"
set /a dummySize=1
for /l %%N in (1 1 32) do if !dummySize! lss %~z1 (set /a dummySize*=2 & type "!tempFile!" >>"!tempFile!")
fc /b "!tempFile!" %1|findstr /re " [89ABCDEF][0123456789ABCDEF]" >nul&& set rtn=1 || set rtn=0
del "!tempFile!"
exit /b %rtn%
This is not so easy as the cmd works only over the extended ascii table.
Here is a file that contains the cyrillic alphabet printed with type command:
тхЁЄ·єшюярёфЇуїщъыч№Ўцсэьў∙°■╫▐┘╪▀┬┼╨╥┌╙╚╬╧└╤─╘├╒╔╩╦╟▄╓╞┴═╠ (bulgarian cyrillic- may differs with russian , mongolian and etc...)
unfortunately FINDSTR command does not work well with these.
BUT IF the only specaial characters that these files contains are cyrillic may be there's a chance :-).You can check the cyrillic characters by their HEX codes.There's a certutil command that you can use to encode a file to hex , or dump it to hex.Not win xp native but it can be downloaded from microsoft.com .Here are the hex codes:
ff e2 e5 f0 f2 fa f3 e8 ee ef e0 f1 e4 f4 e3 f5
e9 ea eb e7 fc f6 e6 e1 ed ec f7 f9 f8 fe d7 de
d9 d8 df c2 c5 d0 d2 da d3 c8 ce cf c0 d1 c4 d4
c3 d5 c9 ca cb c7 dc d6 c6 c1 cd cc
and here's the code:
#echo off
certutil -dump my.cirillyc.file | findstr /r ""ff" "e2" "e5" "f0" "f2" "fa" "f3" "e8" "ee" "ef" "e0" "f1" "e4" "f4" "e3" "f5" "e9" "ea" "eb" "e7" "fc" "f6" "e6" "e1" "ed" "ec" "f7" "f9" "f8" "fe" "d7" "de" "d9" "d8" "df" "c2" "c5" "d0" "d2" "da" "d3" "c8" "ce" "cf" "c0" "d1" "c4" "d4" "" "c3" "d5" "c9" "ca" "cb" "c7" "dc" "d6" "c6" "c1" "cd" "cc""
if %errorlevel% EQU 0 (
copy my.cirillyc.file C\mydocs\Contains_Cyrillic\
)
May not work so properly if you file contains some of ╓╞┴═╠... symbols but should be ok in the more cases.To traverse all files in a directory you can surround the this with for /f loop