Skip to content

Latest commit

 

History

History
46 lines (31 loc) · 1.09 KB

README.md

File metadata and controls

46 lines (31 loc) · 1.09 KB

Golang/Goyacc Hello World Compiler

Reads a helloworld file, parses it using goyacc and compiles it to a binary.

Syntax

There are just two productions (this is meant to be simple):

  • helloworld ;, which will generate a "Hello, World!"
  • helloworld "some string";, which will generate a "Hello, some string!"

The scanner discards whitespaces. Used the Go text/scanner for its simplicity. The parsed content is then transpiled to C++ and compiled into a binary using g++ (must be installed).

Build the compiler

$ goyacc hwcompile.y && go build

Compiling helloworld programs

$ cat prog.hw;

helloworld;
helloworld "Bonzo";
helloworld "Robert Plant";
helloworld "James Patrick Page";
helloworld "John Richard Paul Jones Baldwin";
helloworld "helloworld";

$ ./hwcompile prog.hw

$ ls -l prog.out

-rwxr-xr-x 1 rap rap 17240 Dec  9 02:57 prog.out

$ ./prog.out

Hello, World!
Hello, Bonzo!
Hello, Robert Plant!
Hello, James Patrick Page!
Hello, John Richard Paul Jones Baldwin!
Hello, helloworld!