How could I recognise the Pikachu language in yacc? - parsing

I am trying to do a simple lex&yacc program that can recognise the three sound of pikachu: pi, pika and pikachu. My only rule is that one token can not appear 3 times in a row in line. I have tried this:
%token PI PIKA PIKACHU
%%
program : program line '\n'
|
;
line: PI piWords
| PIKA pikaWords
| PIKACHU pikachuWords
;
piWords: PI
| PI pikaWords
| PI pikachuWords
;
pikaWords: PIKA
| PIKA piWords
| PIKA pikachuWords
;
pikachuWords: PIKACHU
| PIKACHU piWords
| PIKACHU pikaWords
;
%%
but this doesn't work on all combinations, for example Pika Pikachu pikachu. How could I rewrite this?
Also tried limiting the tokens in lex like {0,2} but when I write pi pi pi for example it still works even if it shouldn't.
UPDATE.
Based on ideas below, I did managed to finish this. I was pretty close, all I needed was to keep track is there was 2 repetitions also. I did smth like this:
program : program line '\n'
|
;
line: piWords
| pikaWords
| pikachuWords
;
piWords: PI
| PI pikaWords
| PI PI pikaWords
| PI pikachuWords
| PI PI pikachuWords
;
pikaWords: PIKA
| PIKA piWords
| PIKA PIKA piWords
| PIKA pikachuWords
| PIKA PIKA pikachuWords
;
pikachuWords: PIKACHU
| PIKACHU piWords
| PIKACHU PIKACHU piWords
| PIKACHU pikaWords
| PIKACHU PIKACHU pikaWords
;

Your grammar here is on the right track, but needs a little tuning.
Intuitively, each of your nonterminals keeps track of the last terminal you’ve seen so that you don’t allow for the same string to appear twice in a row. You can expand on this idea by having nonterminals keep track of the following information: what was the last terminal I saw, and how many copies of it did I see? So, for example, you’d have two nonterminals for when the last terminal was PI, one for when the PI read was the first PI and one for when the PI read was the second PI. Think about how the productions would transition between these different nonterminals based on what’s been read so far.

Related

What would be a causing no response from ESP-01 when using AT commands from Raspberry Pi Pico

I have a Raspberry Pi Pico and I'm trying to get it Wifi Connected.
I'm using an ESP-01 with the sock firmware and confirmed AT commands are working through the Arduino serial monitor on both 115200 and 9600 Baud. To connect to my PC I am using an ESP-01S USB adapter I've gotten on amazon.
AT
OK
AT+GMR
AT version:1.2.0.0(Jul 1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
v1.0.0
Mar 11 2018 18:27:31
OK
+--------------------------+
| Both NL & CR | 9600 Baud |
+--------------------------+
Once I get everything wired up to the Raspberry Pi Pico there is now a blue light on the ESP-01, which wasn't on with the USB serial adapter. And I do not get a response from the ESP-01.
+-------------------+ +-------------------+
| | 3.3v PS | |
| Raspberry Pi | = | | ESP-01 |
| Pico | | +------+ 3.3v |
| | | | |
| GPIO 0 +----------------> RXD |
| | | | |
| GPIO 1 <----------------+ TXD |
| | | | |
| GND +-------+--------+ GND |
| | | |
| | | |
+-------------------+ +-------------------+
from machine import UART
uart = UART(0, baudrate=9600)
def write(msg):
print("Sending %s" % msg)
uart.write(msg)
write('AT\r\n')
while True:
if t:
print(t)
else:
t = uart.readline()
print('.', end="")
Tried with multiple baudrates as well as UART 0 and UART 1 (TX=0, RX=1 and TX=4, RX=5).
ESP-01 is supplied with 3.3v and not using power from the Raspberry Pi.
What could be going on that would prevent a response?

How do I create a docker container with two network interfaces but on the same network

I need to reproduce a scenario where there are two machines on a network. Machine 1 has two network interfaces (say for control and data traffic), both on the same network.
------------- -------------
| M 1 | | M 2 |
| eth0 eth1 | | eth0 |
1.1.1.1 1.1.1.2 | 1.1.1.3 |
| | | | | | |
------------- -------------
| | |
+------+--network 1.1.1.0/24----+
I see there are solutions to have two networks on a docker container, but is it possible to have two interfaces on the same network in docker?

Forward SSH connections based on user name

I found numerous sites explaining ssh port forwarding, ssh reverse proxy, ssh multiplexing etc. involving sshpiper, sslh, running a ssh socks server, just configuring the local SSH server an so on..
so I'm quite puzzled right now and might ask a very common and/or simple question:
As you might already guess from the title I want to set up a git server (GitLab) inside a docker container listening for SSH connections on port 22 without having to use a different port for default ssh operations (terminal, scp, etc..) on the host (as suggested here)
I.e.
ssh alice#myserver.org should still be possible as well as
git clone git#myserver.com:path/to/project
and I don't want to do any setup on the client computer
If you prefer a picture:
+------ myserver.org --------+
| +----+ +- typical -+ |
+--------+ alice#myserver.org:22 | | | | SSH | |
| client | ----------------------> -+--+----+---->| service | |
+--------+ all names but `git` | | ? | +-----------+ |
| | | |
| | ? | +- docker --+ |
+--------+ git#myserver.org:22 | | | | with | |
| client | ----------------------> -+--+----+---->| GitLab | |
+--------+ only user `git` | | | | | |
| +----+ +-----------+ |
+----------------------------+
Can you tell me what's the recommended/most common way to do this? This question sounds promising but the answer seems to configure the client (which I want to avoid)
This project may help you.
https://github.com/tg123/sshpiper.
SSH Piper works as a proxy-like ware, and route connections by username, src ip , etc.
+---------+ +------------------+ +-----------------+
| | | | | |
| Bob +----ssh -l bob----+ | SSH Piper +-------------> Bob' machine |
| | | | | | | |
+---------+ | | | | +-----------------+
+---> pipe-by-name--+ |
+---------+ | | | | +-----------------+
| | | | | | | |
| Alice +----ssh -l alice--+ | +-------------> Alice' machine |
| | | | | |
+---------+ +------------------+ +-----------------+
Downstream SSH Piper Upstream
First of all, thanks for reading TheDockerExperts blog , hope our articles help you! Let me explain how we do SSH proxy in our company.
We have HAproxy that listens TCP 22 port and sends traffic to GitLab server, on host we have custom SSH port. Unfortunately as we use TCP balancing in this case, there is no way to create balancer based on domain names and users. You can take small VPS , spin up HAproxy on it and use it to balance your GIT traffic.
Hope this will help you!

How to know a process is running under docker?

I may be asking a very beginner level question but I need a way to distinguish process under docker and that under non-docker in a box. The 'ps' command command output gives me a feeling that process is running in linux box and cannot confirm if same is under hood of docker.
In the same context is it possible / feasible that process under docker be started with docker root file system.
Is the same feasible or there any other solution for same?
You can identify Docker process via the process tree on the Docker host (or on the VM if using docker for mac/windows)
The parent process to 2924(haproxy) is 2902
The parent process to 2902(haproxy-start) is 2881
2881 will be docker-container which is managed by a dockerd process
To view your process listing in a tree format use ps -ejH or pstree (available in the psmisc package)
To get a quick list of whats running under dockerd
/ # pstree $(pgrep dockerd)
dockerd-+-docker-containe-+-docker-containe-+-java---17*[{java}]
| | `-8*[{docker-containe}]
| |-docker-containe-+-sinopia-+-4*[{V8 WorkerThread}]
| | | |-{node}
| | | `-4*[{sinopia}]
| | `-8*[{docker-containe}]
| |-docker-containe-+-node-+-4*[{V8 WorkerThread}]
| | | `-{node}
| | `-8*[{docker-containe}]
| |-docker-containe-+-tinydns
| | `-8*[{docker-containe}]
| |-docker-containe-+-dnscache
| | `-8*[{docker-containe}]
| |-docker-containe-+-apt-cacher-ng
| | `-8*[{docker-containe}]
| `-20*[{docker-containe}]
|-2*[docker-proxy---6*[{docker-proxy}]]
|-docker-proxy---5*[{docker-proxy}]
|-2*[docker-proxy---4*[{docker-proxy}]]
|-docker-proxy---8*[{docker-proxy}]
`-28*[{dockerd}]
Show the parents of a PID (-s)
/ # pstree -aps 3744
init,1
`-dockerd,1721 --pidfile=/run/docker.pid -H unix:///var/run/docker.sock --swarm-default-advertise-addr=eth0
`-docker-containe,1728 -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim ...
`-docker-containe,3711 8d923b3235eb963b735fda847b745d5629904ccef1245d4592cc986b3b9b384a...
`-java,3744 -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp/zookeeper/bin/../build/cl
|-{java},4174
|-{java},4175
|-{java},4176
|-{java},4177
|-{java},4190
|-{java},4208
|-{java},4209
|-{java},4327
|-{java},4328
|-{java},4329
|-{java},4330
|-{java},4390
|-{java},4416
|-{java},4617
|-{java},4625
|-{java},4629
`-{java},4632
Show all children of docker, including namespace changes (-S):
/ # pstree -apS $(pgrep dockerd)
dockerd,1721 --pidfile=/run/docker.pid -H unix:///var/run/docker.sock --swarm-default-advertise-addr=eth0
|-docker-containe,1728 -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim ...
| |-docker-containe,3711 8d923b3235eb963b735fda847b745d5629904ccef1245d4592cc986b3b9b384a...
| | |-java,3744,ipc,mnt,net,pid,uts -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp/zookeeper/bin/../build/cl
| | | |-{java},4174
| | | |-{java},4175
| | | |-{java},4629
| | | `-{java},4632
| | |-{docker-containe},3712
| | `-{docker-containe},4152
| |-docker-containe,3806 49125f8274242a5ae244ffbca121f354c620355186875617d43876bcde619732...
| | |-sinopia,3841,ipc,mnt,net,pid,uts
| | | |-{V8 WorkerThread},4063
| | | |-{V8 WorkerThread},4064
| | | |-{V8 WorkerThread},4065
| | | |-{V8 WorkerThread},4066
| | | |-{node},4062
| | | |-{sinopia},4333
| | | |-{sinopia},4334
| | | |-{sinopia},4335
| | | `-{sinopia},4336
| | |-{docker-containe},3814
| | `-{docker-containe},4038
| |-docker-containe,3846 2a756d94c52d934ba729927b0354014f11da6319eff4d35880a30e72e033c05d...
| | |-node,3910,ipc,mnt,net,pid,uts lib/dnsd.js
| | | |-{V8 WorkerThread},4204
| | | |-{V8 WorkerThread},4205
| | | |-{V8 WorkerThread},4206
| | | |-{V8 WorkerThread},4207
| | | `-{node},4203
The command lxc-ls and the command lxc-ps may be installable on your Linux distribution. This will allow you to list the running LXC containers and the processes running within those containers respectively. You should be able to link the output from lxc-ls to lxc-ps using streams and get a list of all containerized processes.
The big caveat is that you specified Docker and not every Docker instance is running on LXC nor is it necessarily a localhost process. Docker defines an API that can be called to list remote Docker instances, so this technique will not help with enumerating processes on remote machines as well.
In windows docker behave little bit different.
It's processes are not run as child of parent process, but running as separate process on the host.
They can be viewed by (for example), powershell, like
Get-Process powershell
For example, getting processes on the host when running microsoft/iis container will include additional powershell process (since ms/iis container runs powershell as a main executable process).

why those two IP prefixes, which are the same to me, map to the different AS number

I use the whois command to try to map two ip prefixes address to the AS numbers. The results are given blow:
$ whois -h whois.cymru.com " -v 1.0.4.0/22 "
AS | IP | BGP Prefix | CC | Registry | Allocated | AS Name
56203 | 1.0.4.0 | 1.0.4.0/24 | AU | apnic | 2011-04-12 | BIGRED-NET-AU Big Red Group
$ whois -h whois.cymru.com " -v 1.0.0.0/24 "
AS | IP | BGP Prefix | CC | Registry | Allocated | AS Name
15169 | 1.0.0.0 | 1.0.0.0/24 | AU | apnic | 2011-08-11 | GOOGLE - Google Inc.
My question is why those two prefixes have different AS number. It seems to me that those two are same, so the AS number should be also exact same number.
Many thanks for your help!
narisu
The two listings are on different subnets. This is caused by different subnet masks (the trailing /22 or /24 above).

Resources