The GG Programming Language - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

The GG Programming Language

Description:

The GG Programming Language We give it to you. The Authors Kierstan Bell Documentation and Front-end Elizabeth Mutter Front-end Jake Porway Testing and Front ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 36
Provided by: JonahP9
Category:

less

Transcript and Presenter's Notes

Title: The GG Programming Language


1
The GG Programming Language
  • We give it to you.

2
The Authors
  • Kierstan Bell
  • Documentation and Front-end
  • Elizabeth Mutter
  • Front-end
  • Jake Porway
  • Testing and Front-end
  • Jonah Tower
  • Back-end

3
Language Overview
  • Jonah

4
Why GG?
5
it makes things easy!
  • Sockets
  • I/O
  • Threads

6
Sockets a Simple Client
  • include ltstdio.hgt
  • include ltstdlib.hgt
  • include ltstring.hgt
  • include ltunistd.hgt
  • include ltsignal.hgt
  • include lterrno.hgt
  • include ltsys/types.hgt
  • include ltsys/socket.hgt
  • include ltsys/wait.hgt
  • include ltnetinet/in.hgt
  • / sklar need to define socklen_t for cunix not
    needed for linux /
  • / typedef int socklen_t /
  • define TERM '\n'
  • /------------------------------------------------
    --------------------
  • client_sock()
  • creates a socket and then attempts to make a
    connection to that
  • socket
  • ------------------------------------------------
    ------------------/
  • int client_sock ( int port )
  • int ss, optval 1
  • struct sockaddr_in sin
  • / (1) create an endpoint for communication
    /
  • if (( ss socket( PF_INET, SOCK_STREAM, 0 ))
    -1)
  • sysabort( "client/socket" )
  • / (1a) set socket options /
  • if ( setsockopt( ss,

7
This is Really Simple
  • / (2) make a connection to the server socket /
  • if ( connect( ss,(struct sockaddr
    )sin,(socklen_t)sizeof(sin) ) -1 )
  • printf("foobar\n")
  • sysabort( "client/connect" )
  • / return the socket descriptor /
  • return( ss )
  • / end of client_sock() /
  • /------------------------------------------------
    --------------------
  • echo_client()
  • ------------------------------------------------
    ------------------/
  • void echo_client ( int port )
  • int sock, olen, nwritten, nread, more
  • unsigned char i
  • p0 TERM
  • p1 '\0'
  • else
  • printf( "client writing message s\n",p
    )
  • i strlen( p )
  • if (( nwritten write( sock, i, sizeof( i ) ))
    -1 )
  • sysabort( "client/write" )
  • if (( nwritten write( sock, p, strlen(p) ))
    -1 )
  • sysabort( "client/write" )
  • if ( more )
  • if (( nread read( sock, i, sizeof( i )))
    lt 0 )
  • sysabort( "client/read" )
  • fprintf( stdout,"client id\n",i )
  • fflush( stdout )

8
Still going
  • / end of echo_client() /
  • /------------------------------------------------
    --------------------
  • main()
  • ------------------------------------------------
    ------------------/
  • int main( int argc, char argv )
  • int port
  • if ( argc lt 2 )
  • printf( "usage client.x ltportgt\n" )
  • exit( 1 )
  • sscanf( argv1,"d",port )
  • echo_client( port )
  • return( 0 )
  • / end of main() /

9
And now in GG
  • void main(string arg1, string arg2)
  • sockconnect(arg1, stoi(arg2))
  • while(1)
  • send(getline())
  • print(recv())

10
File I/O (in Java)
  • File f new File(foobar.txt)

11
File I/O (in Java)
  • File f new File(foobar.txt)
  • FileReader fr new FileReader(f)

12
File I/O (in Java)
  • File f new File(foobar.txt)
  • FileReader fr new FileReader(f)
  • BufferedReader in new BufferedReader(fr)

13
File I/O (in Java)
  • File f new File(foobar.txt)
  • FileReader fr new FileReader(f)
  • BufferedReader in new BufferedReader(fr)
  • String line in.readLine()

14
but wait!
  • try
  • File f new File(foobar.txt)
  • FileReader fr new FileReader(f)
  • BufferedReader in new BufferedReader(fr)
  • String line in.readLine()
  • Catch(IOException e)
  • System.err.println(Oh no!)

15
Look at our Cool Version
  • file f foobar.txt
  • string line fgetline(f)

16
And, GG lets youthread things
  • WOW!

17
Syntax and Semantics
  • Kierstan

18
This is Like C, Baby!
  • Functional language
  • NOT Object Oriented
  • C-like syntax

int x int foo(int i) int y y i
1 return y
void main() int z x 10 z foo(x)
19
Data Types
  • boolean
  • boolean b true
  • boolean b false
  • char
  • char a a
  • file
  • file myFile myFile.txt
  • int
  • int i 0
  • string
  • string hi hi

20
Control Flow
  • while statement
  • if

while(ltbooleangt) statements
if(ltbooleangt) statements
21
Built-in Functions
  • string fgetline(file f)
  • void fprint(file f, string option, string line)
  • int getint()
  • string getline()
  • string getlocalhost()
  • int getTime()
  • void print(string line)
  • string recv()
  • string recv(int port)
  • void send(file file)
  • void send(file file, int port)
  • void send(string line)
  • void send(string line, int port)
  • void socketclose()
  • void socketclose(int port)
  • int socketcreate()
  • int socketcreate(int port)
  • int socketconnect(int port)
  • int socketconnect(string host, int port)

22
Threaded Functions
  • threaded void funcA()
  • print(a)
  • threaded void funcB()
  • print(b)

23
The Compiler
  • Elizabeth

24
(No Transcript)
25
Lexer/Parser
  • Both written in ANTLR
  • Lexer
  • Parses a GG file into Tokens
  • Parser
  • Takes the Lexers tokens as input
  • Checks for syntax errors
  • Creates a tree

26
Building the Tree
  • For example -
  • GG assignment statement
  • a myFunc()

27
Walking the Tree
  • Semantic check AND code generation done in one
    pass
  • Uses ANTLRs tree walker
  • Walks the dummy nodes
  • but java code does most of the work
  • Semantic
  • Hashtables keep track of
  • Global variables
  • Local variables
  • Function declarations
  • Keywords
  • Code
  • Prints java code to .java files

28
Code Generation Java Files
  • name-of-file.java
  • Runnable java file
  • name-of-fileMainMethod.java
  • Wrapper class that contains the translated GG
    code
  • name-of-functionThreadedFunction.java
  • Created for each threaded function

29
Testing and Lessons Learned
  • Jake

30
Standard Regression Testing
  • No surprises here
  • Small modules tested against base cases using
    script
  • Syntactic tests run with Lexer/Parser
  • Semantic tests run with Tree Walker
  • Generated code checks run by hand

31
Syntactic Error Checking
  • Checks syntax in Lexer/Parser
  • Basic syntactic errors introduced into correct
    reference cases
  • Resulting trees are compared
  • Base Case
  • void main()
  • int a 3 ? (FUNC_DECL void
    main (BODY ( a 3)))
  • Error
  • void main()
  • int a 3 ? Expected SEMI
    found CCURLY

32
Semantic Error Checking
  • Only need to check select semantic errors, since
    most egregious errors are syntactic
  • Keep log of test results, check for failure
  • void main()
  • int a Not a string
  • Prints to log file
  • test1-typecheck-incorrect.gg
  • Result Expected type int but got Not a
    string

33
Code Correctness
  • Not done with automated checking
  • No mortal should have to hand-generate the Java
    base case for a client/server program
  • Instead, functionality is checked thoroughly, not
    code

34
Lessons Learned!
  • Roles are great, but dont be afraid to
    diversify
  • Meetings, meetings, and more meetings! Theres
    comfort in consistency
  • Clairvoyance Who knew ANTLR would be so hard
  • Ctrl-1-0-0 Who put this in Emacs?

35
THE END
Write a Comment
User Comments (0)
About PowerShow.com