RAMEL

Introduction

RAMEL is a programming language written using Lex, Yacc, and C by yours truly with (a lot of) guidence from Dan Tappan in the CS Department at ISU. This is probably the most difficult program I’ve ever written. It runs on a Java virtual program. RAMEL is more or less useless, but it did help clear up how a compiler can actually work.

Syntax – Lex

Lex is a tool for parsing regular expressions. RAMEL is similar to C, so it is parsed similarly. The syntax of Lex is fairly straightforward, but it helps to look over the documentation. Regular expressions are a subset of context free languages which can be generated using YACC.

Some things, such as strings, are passed modified using some code (such as stripping off the quotes).

Here is a link to the ramel.lex.

It was compiled using flex and generated lex.yy.c which was compiled using gcc.

References:

Semantics – Yacc and C

The Yacc was a bit more complicated than the Lex. It takes care of the semantics of declaring variables, algebra operations, symbol tables, etc. It also keeps track of all sorts of rules like a string cannot be added to an integer.

Here are links to the source code:

ramel.yacc
symbolTable.h
symbolTable.cpp
semantics.h

This was compiled using Bison and gcc.

References:

Target Code Generation

The code generation involves several passes through (more than necessary, some of the steps could be condensed). This generates code that is closer to the machine. Below is the source code:

targetCodeGenerator.h
targetCodeGenerator.cpp

In this case, our machine is just a virtual machine, but it would still be similar if there were actual hardware.

Virtual Machine

The virtual computer takes the generated code (generated by the target code generator) as a text file (cs451.txt) and produces an executable.  Below is the source code:

execute.java

This is written and compiled in Java.

Example Run

Take the example RAMEL code. Again, the syntax is similar to C it should be readable.

{
int x;
x = 17;
if((x > 17))
{
write(x);
}
}

Now use the target code generator. It outputs all x passes to the screen. The final pass generates the necessary code for the virtual machine.

0000 LDVR 5 17
0004 LDRA 500 5
0008 LDAR 2 500
0012 LDVR 3 17
0016 CGT 4 2 3
0020 JMPF 10 4
0024 LDAR 6 500
0028 OUTI 6
0030 NOP
0031 HALT

This code is saved in the same directory as cs481.rml and Execute.java.

java
Execute
More Example RAMEL Programs

The below program demonstrates a conditional written in RAMEL. Note the write function just utilizes the java output.

{
int x;
x = 17;
if((x > 17))
{
write(x);
}
else
{
x = (x + 1);
}
}

The program below demonstrates a loop in RAMEL

{
int x;
x = 0;
while((x < 100))
{
if((x > 17))
{
break;
}
else
{
x = (x + 1);
write(x);
}
x = (x*2);
}
}

If I ever receive any feedback on this I’ll give more examples

Analysis

The reasons RAMEL is not practical – just to name a few:

  • It is extremely slow. It relies on something like 13 passes to generate target code. It basically goes through all this trouble just to write java code that is interpreted and realistically has to be interpreted down to your machine from there.
  • It does nothing new. There is nothing RAMEL gives that has not already been done – much better.
  • The code seems a little buggy. Although it seems to work ok on my laptop, it had an error running on the school’s machines. This bug was fixed. However, RAMEL has never really been tested, so if it were ever to be really used (which it probably never should be other than for educational purposes) some debugging may be necessary.
  • No one uses it so it doesn’t have any libraries – so even the most trivial tasks can be difficult.

Despite these disadvantages, there are, believe it or not, advantages. At least I think there are:

  • RAMEL is extremely simple as far as compilers go. Compilers are complicated devices, and this lets the observer see how one could realistically work.
  • RAMEL is easy to read due to simplicity, so it should be fairly familiar.


Broadcom Wireless and Linux

Here is the “straightforward” way

see (http://ndiswrapper.sourceforge.net/mediawiki/index.php)
for more info.

  • Download this windows driver
  • unzip the file you downloaded.
  • run “ndiswrapper -i FILE” on any .inf files you downloaded.
  • run “ndiswrapper -l” and it should say “driver present hardware present” if not, there is a problem.

type:

depmod -a
modprobe ndiswrapper

try “ethq wlan0 scan” if it worked, this should do something.

Troubleshooting

With Ubuntu for some reason it loads a bad driver you should blacklist. This issue is covered a bit better here: http://ubuntuforums.org/showthread.php?t=285809

Here’s another issue with Edgy. I got this email from a friend. My Wireless stopped working because the latest version was bad. Probably not an issue now, but if you’re having problems you may want to give it a shot.

hey rich
Speaking of the devil, yeah, i just figured that out like 3 minutes ago. From what i can tell, it seems like the new version of ndiswrapper (like 1.7?) screws things up. Or something. So i just downloaded and installed an older version of ndiswrapper. I got ndwiswrapper-1.27. i just downloaded and extracted the file, didn’t use apt-get. after that:

1. cd to the extracted directory of ndiswrapper-1.27
2. sudo make uninstall (ur supposed to do this until there are no errors…)
3. sudo make
4. sudo make install
5. then just do sudo ndiswrapper -i filename.inf for your driver.

Now mine works again, yay. The problem i had thought was i didn’t have the kernel headers so it wouldn’t compile ndiswrapper. i (eventually) did a sudo apt-get install linux-headers-2.6.17-10-386. Now if you’re running a different version of the kernel, then replace that last string with ur version. the command to get ur exact kernel is “uname -r”. so yeah….do that, then do the make uninstall, make, make install, and then it should work again. I don’t have the link for that 1.27 version download, but google should find it pretty quick.

So in summary, the best solution is probably to get rid of piece of shit broadcom chips :)

TCP/IP Drinking Game

This is a preview of what might happen at Chris’s bachelor party (if we get crazy enough). Add your questions here to skew the results! If you’re lucky there may even be a Linux drinking game.

Some of these are stolen from online. Some of them may not seem very hard, but I’m sure they’ll get more and more difficult as we consume more and more alcohol. Also, it’ll be fun to see all the obscure crap I’m sure some of you know just on the top of your head (freakin weirdos).

-What is the minimum length of a tcp packet and why is there a min length?
64 bitsb and so a collision can be detected

-Name at least three official DNS resource record types.
Any three of A, CNAME, HINFO, MX, NS, PTR, SOA, TXT, WKS, RT, NULL,
AXFR, MAILB, MAILA, KX, KEY, SIG, NXT, PX, NSAP, NSAP-PTR, RP, AFSDB,
RT, GPOS, DNAME, AAAA, SRV, LOC, EID, NIMLOC, ATMA, NAPTR, CERT, SINK,
OPT, APL, TKEY, TSIG, IXFR, Deprecated: MB, MD, MF, Experimental:
MINFO, MR, MG, X25

-What is the maximum amount of data in a UDP packet over IPv6?
65487 bytes (65535 – 40 IPv6 header – 8 UDP header).

-What application uses TCP port 666?
Doom

-What does crc stand for?
Cyclic Redundanct check

-What are class D networks used for?
Multicasting

-What is a runt packet?
A packet that is shorter than the minimum packet length as defined
by the protocol it is using.

-As of RFC 1394, how many values can the TOS field in an IPv4 header have?
5 (4 bit wide field, only one may be set at a time, 0 is valid).

-What OSI model layer does IP most closely resemble?
The network layer, layer 3.

-What was the first remotely operated non-computer appliance to be connected to the Internet?
A toaster (controlled using SNMP).

-What is the only field that is different between a regular ARP packet and a gratuitous ARP packet?
The target IP.

-What error is returned if a UDP datagram is received and has a checksum error?
None. It is silently discarded.

-Which parts of the packet does the UDP checksum cover?
UDP pseudoheader, UDP header, UDP data.

-Which parts of the packet does the IP checksum cover?
The IP header.

-How many identical acks need to be received for fast retransmit to occur?
4 (3 duplicate + original).

-How many bytes total are in a standard sized ICMP echo request packet?
84 bytes (56 data, 8 ICMP header, 20 IP header).

-How many bits are in an “A” type DNS resource record?
112, plus the owner name.

-What is the range of class B IP addresses?
128.0.0.0 through 191.255.255.255.

-How many hosts should be on a network with a 255.255.255.192 subnet mask?
62 (64 – (broadcast address and network address))

-Name all 7 layers of the OSI network model.
Physical, Data Link, Network, Transport, Session, Presentation,
and Application.

-In a Christmas tree packet, which TCP flag bits are turned on?
SYN, URG, PSH, and FIN (all of them).

- What service runs on port 6667?
Internet Relay Chat (IRC)

-Name 7 of the 11 states of a socket (one at a time, person who can’t name one has to drink!)
1. LISTEN
2. SYN-SENT
3. SYN-RECEIVED
4. ESTABLISHED
5. FIN-WAIT-1
6. FIN-WAIT-2
7. CLOSE-WAIT
8. CLOSING
9. LAST-ACK
10. TIME-WAIT
11. CLOSED

-What flags are set with a FIN scan?
The FIN flag

-What is the first program able to scan networks using xmas packets?
nmap

-Who wrote nmap?
Fyodor

-Who invented the Internet?
Al Gore. Also acceptable are Bob Kahn and Vint Cerf who invented TCP, or maybe Larry Roberts who started ARPANET. Anyway, Al Gore actually never even said he invented the Internet, but his political contributions actually did probably help.

-What is a Chernobyl Packet?
A Chernobyl packet is a network packet that induces a broadcast storm and/or network meltdown. The term was named after the April 1986 nuclear accident at Chernobyl. Also acceptable is a Chernevog’s mating call.

-What is more common with DNS talk, TCP or UDP?
UDP I think. Although DNS occasionally does use TCP for big things.

-TCP or UDP – IRC?
TCP

-TCP or UDP -SMTP?
TCP

-What does RTT stand for?
Round Trip Time

Matching Regular Expressions that don’t end with…

Regular expressions do not mix well with syntax that requires memory, such as XML. I was trying to add a <br /> tag to every line that did not have a </p> tag. so for example I can print the strings I want with grep -v ‘^.*</P>’

Anyway, this turns out to be a bear, because (?!expression) just isn’t working for me with sed, although I think google says it should.

So what do I do? I make two!

s/(w.*</p>)/1<br />/g

adds a <br /> to every line with a word.

s/(.*</p>)<br />/1/g

take off the <br /> for lines that have a </p>

The good thing about this is it should work with all standard regular expressions, unlike that look ahead stuff which may only work with certain utilities.

You could run this with sed, vim, perl, python, whatever, and it will work.

Follow

Get every new post delivered to your Inbox.