Skip to content

rodolfoap/helloworld-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

A Golang/Goyacc Helloworld language compiler generating a binary (from C++). It is meant to be used as the starting point of further work.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages