EBNF rule into BNF - bnf

Hi I am having a lot of trouble with this problem and I came across a lot of sites but found this post How to convert BNF to EBNF to be very helpful but I just don't know where to start with this example.
<decimal_literal> --> (0|1|2|3|4|5|6|8|9){0|1|2|3|4|5|6|7|8|9|_}
In this rule the parenthesis and curly braces are metasymbols. It needs more than 1 rule and may need to introduce 1 or more new non-terminals.
This is the textbook I am using http://umsl.edu/~mfrp9/misc/cpl.pdf page 131 shows an example but I can't apply it to this problem. If someone can please explain the solution to this problem step by step so I can learn it to do similar problems is greatly appreciated.

This looks plausible as a translation to the BNF from p131 of the book.
<decimal_literal> ⟶ <decimal_digit>
| <decimal_literal> <decimal_digit_or_underscore>
<decimal_digit> ⟶ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<decimal_digit_or_underscore> ⟶ <decimal_digit> | _

Related

Google Sheets FILTER() and QUERY() not working with SUM()

I'm trying to pull and sum data from one sheet on another. This is GA data being built into a report, so I have sessions split up by landing page and device type, and would like to group them in different ways.
I usually use FILTER() for this sort of thing, but it keeps returning a 0 sum. Thinking this may be an odd edge case with FILTER(), I switched to using QUERY() instead. That gave me an error, but a Google search doesn't offer much documentation about what the error actually means. Taking a guess that it could be indicating an issue with the data type (i.e. not numeric), I changed the format of the source from "Automatic" to "Number", but to no avail.
Maybe it's a lack of coffee, I'm at a loss as to why neither function is working to do a simple lookup and sum by criteria.
FILTER() function
SUM(FILTER(AllData!C:C,AllData!A:A="/chestnut/",AllData!B:B="desktop"))
No error, but returns 0 regardless of filter parameters.
QUERY() function
QUERY(AllData!A:G, "SELECT SUM(C) WHERE A='/chestnut/' AND B='desktop'",1)
Error returned:
Unable to parse query string for Function QUERY parameter 2: AVG_SUM_ONLY_NUMERIC
Sample data:
landingPage | deviceCategory | sessions
-------------|----------------|----------
/chestnut/ | desktop | 4
/chestnut/ | desktop | 2
/chestnut/ | tablet | 5
/chestnut/ | tablet | 1
/maple/ | desktop | 1
/maple/ | desktop | 2
/maple/ | mobile | 3
/maple/ | mobile | 1
I think the summing doesn't work because your numbers are text formatted.
See if any of these work? (change ranges to suit)
using FILTER()
=SUM(FILTER(VALUE(AllData!C:C),AllData!A:A="/chestnut/",AllData!B:B="desktop"))
using QUERY()
=ArrayFormula(QUERY({AllData!A:B, VALUE(AllData!C:C)}, "SELECT SUM(Col3) WHERE Col1='/chestnut/' AND Col2='desktop' label SUM(Col3)''",1))
using SUMPRODUCT()
=SUMPRODUCT(VALUE(AllData!C2:C),AllData!A2:A="/chestnut/",AllData!B2:B="desktop")

How to copy a value from a certain pattern in R?

I have a data file, each row may have different format, but the certain pattern "\\- .*\\| PR", the data set is kind as following:
|- 7 | PR - Easy to post position and search resumes | Improvement - searching of resumes
[ 1387028] | Recommend - 9 | PR - As a recruiter I find a lot qualified resumes for jobs that I am working on.
|- 10 | PR - its easy to use and good candidiates
I want to have a record of the number in this pattern, or the data I offered, I need a record of 7, 9,10. I have no idea about how to do it, is there someone can help?
as.integer(sub('.*- ([0-9]+) \\| PR.*', '\\1', yourvector))

Aligning divs vertically while keeping them ordered in a 'list-style'

I've come to a point where I really can't think of any solutions for this problem anymore. What I want to achieve is:
I fill content in some divs, for example values from 0-10. Then, when showing them, they should be listed in a way that's responsive to the users window size.
On A Big screen it should look like this:
1 | 4 | 7 | 10
2 | 5 | 8
3 | 6 | 9
And on a smaller Screen:
1 | 5 | 9
2 | 6 | 10
3 | 7
4 | 8
I tried it by giving the divs the float: left; Property, which gives me an output like this:
1 | 2 | 3 | 4
5 | 6 | 7 | 8
9 | 10
Problem is: the order is not the same as in the expected output, and: the 'rows' are being filled first, not the cols.
Does anybody know a solution how one can achieve something like this with only css and html?
Modern solution is CSS Multi-column module. You could use it like this:
.content {
-webkit-column-width: 80px;
-webkit-column-gap: 5px;
}
http://jsfiddle.net/EN92F/
Check support, IE10+.
If it is not supported by the browser (IE8 for example) it will gracefully degrade to single column layout, like here http://jsfiddle.net/EN92F/1/, which is not that bad.
Further reading Using CSS multi-column layouts.

TCP/IP communication from the unix server to the Pure Data

I am interested in TCP/IP communication from the Unix server to the Pure Data. I have it realized using sockets on the Unix server side, and netclient on the Pure Data side. I exploited the chat-server tutorial for this (3.Networking > 10.chat_client.pd).
Now the problem lies that the server is streaming the data out as a "string" message delimited with ";"
My question is, is there a way to send something other than string message to Pure Data, like byte-stream or serialized number stream? Can Pure Data receive such messages?
Since string takes too many bytes to transfer, for example number "1024;" is already 5 bytes, while such an integer number is just 4 bytes.
UPDATE: For everyone that stumbles upon this post in search for the answer.
Apparently [netclient] on the Pure Data side cannot receive nothing else than ; delimited messages.
So the solution for the problem posed above:
My question is, is there a way to send something other than string message to Pure Data, like byte-stream or serialized number stream? Can Pure Data receive such messages?
The solution is to use [tcpclient], it can receive byte-stream data.
Now my question is, how do I get four compact numbers to work with?
Now I have a series of bytes, at least in the correct order.
From my UNIX server I am sending a structure
typedef struct {
int var_code;
int sample_time;
int hr;
float hs;
} phy_data;
Sample data might be 2 1000000 51 2000.56
When received and printed in Pure Data I get output like this:
: 0 0 0 2 0 10 114 26 0 0 0 51 0 16 242 78
You can notice number 2 and number 51 clearly, I guess the others are correct as well.
How can I get these numbers back to a usable format?
Maybe some manipulation with [bytes2any] and [route], but I haven't been able to extract the data with it?
here's an outline of what you have to do:
repackage the bytelist to small messages of the correct size for the various types.
since all your elements are 4 byte long, you simply repackage your list (or bytestream, as TCP/IP doesn't guarantee to deliver your 16 bytes as a single list, but could also decide to break it into a list of arbitrary length) to a number of 4 atom lists.
the most stable way, would probably be to 1st serialize the list (check the "serializer" example in the [list] help) and than reassamble that list to 4 elements.
if you can use externals like zexy you could use [repack 4] for that.
if you trust [netclient] to output your messages as complete lists, you could simply use a large [unpack ....] and 4 [pack]s
interpret the raw data for each sublist
integers is rather simple, floats are way more complicated
integers:
|
[unpack 0 0 0 0]
| | | |
[<< 8] | | |
| | | |
[+ ] | |
| | |
[<< 8] | |
| | |
[+ ] |
| |
[<< 8] |
| |
[+ ]
|
floats are left as an exercise to the user :-)
the real solution to your problem would be to use a well-defined application-layer protocol, rather than brew your own.
the most widespread protocol in use for applications like Pd, is certainly OSC.
in order to decode the raw OSC-bytes into Pd-messages, use [unpackOSC] (part of the "mrpeach" library; on Debian, you install it via the pd-osc package)
on the "server" side, you can use liblo for encoding data and sending it.
note
be aware that since OSC is packet-based, you will need a packetizing mechanism for stream-based protocols like TCP/IP. as with OSC-1.2, this should be SLIP. liblo should already take care of this. check the patches accompanying [unpackOSC] for how to do this within Pd.
all this is not needed if you are using a UDP as a transport.

realtime networking for games, interpolation issue

I've been putting some thought lately into networking for real time, fast paced games. It seems that if you interpolate correctly then the hit calculation is done on the state that happened more than (p1.interp+p2.interp+p1.ping/2+p2.ping/2) ago from player2(p2)s points of view when the shooter is player1(p1).
The packet first goes to the server which takes p1.ping/2, then the server calculates it on the game state that has happened p1.interp + p1.ping/2 ago. The result of that calculation is send to the player2 which only sees it p2.interp later. It adds up even further because of the time it takes for all three sides to process things.
player1 server player2
| | |
.------|_1.............actual.....|.....game state......|
| | | ^ |
|intrp |_2 | | |
| | | | |
`----->|_3----ping/2 | | |
`------|_4----ping/2 |
`------5_|-------.
| |
6_| intrp|
| |
7_|<------‘
Excuse my poor ASCII art skills but I couldn't resist.
(I got home where I have Windows installed and I see how shit it looks here but hope you guys get the idea)
Assuming 50ms ping, 100ms interpolation it gives us more than 250ms summed up. This means that a player2 is seen approximately 250ms in the past by player1 but, assuming client prediciton, he sees himself in realtime. Is my logic flawed or is this just not a big deal?
I found this as an answer to a related question. Not sure if this is appropriate as an answer but I can't comment.

Resources