CardGhost ——Language design for card game Team member: Yang Jian, yj2220 Xiaoming Guo, gx2158 Yu An, ya2249 Dingding Xi, dx2131 Feng Zhou, fz2168.

Slides:



Advertisements
Similar presentations
Vilmos Zsombori , Shanghai
Advertisements

Chapter 2-2 A Simple One-Pass Compiler
Lesson 6 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
CPSC 388 – Compiler Design and Construction
Semantic Analysis and Symbol Tables
Symbol Table.
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Functions Function: The strength of C language is to define and use function. The strength of C language is that C function are easy to define and use.
1 JavaCUP JavaCUP (Construct Useful Parser) is a parser generator Produce a parser written in java, itself is also written in Java; There are many parser.
Overview of Previous Lesson(s) Over View  Front end analyzes a source program and creates an intermediate representation from which the back end generates.
 Lex helps to specify lexical analyzers by specifying regular expression  i/p notation for lex tool is lex language and the tool itself is refered to.
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
The Symbol Table Lecture 13 Wed, Feb 23, The Symbol Table When identifiers are found, they will be entered into a symbol table, which will hold.
ISBN Chapter 4 Lexical and Syntax Analysis The Parsing Problem Recursive-Descent Parsing.
Environments and Evaluation
1 Problem 2 A Scanner / Parser for Simple C. 2 Outline l Language syntax for SC l Requirements for the scanner l Requirement for the parser l companion.
GodMode Team OneUp 1. Joe Ennever - Systems Integrator Zack Sheppard - Language Guru Nic Borensztein - Project Manager Danny Hertz - Systems Architect.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Owl Andrew Olowude Ben Klingher Belai Lencho Kenneth Cheng Martin Li A language for finite automata Team 20 _________ /_ ___ \ \ \ \__/\___/ / \_\/______/
CSc 453 Semantic Analysis Saumya Debray The University of Arizona Tucson.
Prof. Bodik CS 164 Lecture 51 Building a Parser I CS164 3:30-5:00 TT 10 Evans.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Boardr The Racing Board Game Creation Language. Project Manager: Eric Leung Language and Tools Guru: Shensi Ding System Architect: Seong Jin Park System.
Language Translators - Lee McCluskey LANGUAGE TRANSLATORS: WEEK 21 LECTURE: Using JavaCup to create simple interpreters
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
1 Top Down Parsing. CS 412/413 Spring 2008Introduction to Compilers2 Outline Top-down parsing SLL(1) grammars Transforming a grammar into SLL(1) form.
COMP Parsing 2 of 4 Lecture 22. How do we write programs to do this? The process of getting from the input string to the parse tree consists of.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 8: Semantic Analysis and Symbol Tables.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Flex: A fast Lexical Analyzer Generator CSE470: Spring 2000 Updated by Prasad.
Group 4 Java Compiler Group Members: Atul Singh(Y6127) Manish Agrawal(Y6241) Mayank Sachan(Y6253) Sudeept Sinha(Y6483)
Compiler Construction Dr. Noam Rinetzky and Orr Tamir School of Computer Science Tel Aviv University
Code reading skills LEVEL GAME.  Skeleton has error messages.  Notice the red lines on right slider. Click… you’ll go to an error.  pieces = levels.getPieces();
CS 153: Concepts of Compiler Design September 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CPS 506 Comparative Programming Languages Syntax Specification.
PLT Final Project---COLOGO Lixing Dong, Zhou Ma, Chao Song, Siyuan Lu, Dongyang Jiang.
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Introduction to Compiling
Muhammad Idrees, Lecturer University of Lahore 1 Top-Down Parsing Top down parsing can be viewed as an attempt to find a leftmost derivation for an input.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree.
Yacc. Yacc 2 Yacc takes a description of a grammar as its input and generates the table and code for a LALR parser. Input specification file is in 3 parts.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Lesson 4 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
CS412/413 Introduction to Compilers Radu Rugina Lecture 11: Symbol Tables 13 Feb 02.
More yacc. What is yacc – Tool to produce a parser given a grammar – YACC (Yet Another Compiler Compiler) is a program designed to compile a LALR(1) grammar.
Yi Zhang yz2414(Project manager) Shuaishuai Nie sn2479(Language Guru) Xuanchen Tang xt2128(System Architect) Lewis Flanagan lrf2123(System Integrator)
Comp 311 Principles of Programming Languages Lecture 2 Syntax Corky Cartwright August 26, 2009.
Apache Avro CMSC 491 Hadoop-Based Distributed Computing Spring 2016 Adam Shook.
9-December-2002cse Tools © 2002 University of Washington1 Lexical and Parser Tools CSE 413, Autumn 2002 Programming Languages
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture Ahmed Ezzat.
The eclipse IDE IDE = “Integrated Development Environment”
Parsing 2 of 4: Scanner and Parsing
PROGRAMMING LANGUAGES
Compiling, Assembling and Executing Java using Java
Basic Program Analysis: AST
CSE 3302 Programming Languages
Yacc Yacc.
Appendix B.2 Yacc Appendix B.2 -- Yacc.
Presentation transcript:

CardGhost ——Language design for card game Team member: Yang Jian, yj2220 Xiaoming Guo, gx2158 Yu An, ya2249 Dingding Xi, dx2131 Feng Zhou, fz2168

Overview (System Archtitect:Feng Zhou) Outline of Compiler Frontier(Language Guru: Xiaoming Guo) Back end and Interphase details(System Integrator: Yu An) Language Test(Tester and validator: Dingding Xi) Conclusion & Demo(Project Manager: Yang Jian)

Overview (System Archtitect:Feng Zhou) CardGhost is a language to design card games

Struture of our Compiler: source code is scanned by lexical analyzer and return certain tokens as well as its value(if token have value) to parser. Parser print out corresponding java code to CardGhost.java Java functions are called in CardGhost.java to implement certain operations.

Features of CardGhost Simple——using cardghost, you can program easily without a lot of training Flexible——Programmer can define different rules and standard to win Robust——We design a strongly type language and add error reporter so that our language would be more robust User-friendly——language is very simple for programmers to understand, provide interphase in language lib so that user can design a card game more easily

Development environment Jian yang: ——Windows XP ——Notepad++ ——JLex & Java Cup Guo Xiaoming: ——Windows XP ——Notepad++ ——JLex & Java Cup Xi Dingding: ——Mac OS X ——TextWrangler ——JLex & Java Cup & Java jdk1.6 An yu: ——Mac OS X ——TextWrangler ——Eclipse Zhou Feng: ——Windows 7 & ubuntu ——Notepad++ ——Easy Eclipse & Java jdk1.5

Language specific keywords Data Type: Player: |name, cards| Card:|number, suit| Player[], Card[] Player p1; Card[], acard; p1 = |"Bella", acard|; Built-in Function: shuffle, defaultpile, defaultprior,...

Language Grammar Action code: translate into a java statement Use a Node class to preserve information for each nonterminal:result(java statement), type(type) Type filed of a variale node is null. Each time a variable is declared, it's inserted into the symbole table

Language Grammar expr ::=  expr:e1 ADD expr:e2  {:  if(!((e1.type).equals("int"))) //type checking  {  System.out.println("error:"+e1.type+"!= int");  System.exit(0);  }  if(!((e2.type).equals("int")))  {  System.out.println("error"+e2.type+"!= int");  System.exit(0);  }  else  {  String result = e1.result+"+"+e2.result;  Node a = new Node(result, "int");  RESULT = a;//result assignment  }  :}  | ......

Language Grammar display_expr::=  DISPLAY LPAR var:v RPAR  {:  if(parser.hash.get(v.result) == null)  {  System.out.println("error: " + v.result + "has not been declared!!!\n");  System.exit(0);  }  else if(!parser.hash.get(v.result).equals("String") && !parser.hash.get(v.result).equals("Player") && !parser.hash.get(v.result).equals("Card"))//type checking  {  System.out.println("error: " + parser.hash.get(v.result) + " is not String/Player/Card");  System.exit(0);  }  else  {  String result = "p.g.display(" + v.result +")";  Node a = new Node(result, "void");  RESULT = a;//result assignment  }  :}  | ......

Language Grammar func_def::=  type:t var:n1 LPAR formal_list:fl RPAR block:b END var:n2 SEMI  {:  if((n1.result).equals(n2.result))//error checking  {  String result = "public "+t.type+ " "+n1.result+"("+fl.result+")\n{\n"+b.result + "\n}\n";;  Node a = new Node(result);  parser.hash.put(n1.result, t.type);//insert variable into symbol table  RESULT = a;//result assignment  }  else  {  System.out.println("error_154: function name is not matched.");  System.exit(0);  }  :}  | ...

Language Grammar proc_expr::=//function call  var:v LPAR expr_list:el RPAR  {:  if(parser.hash.get(v.result)==null)//error checking  {  System.out.println("error: function "+ v.result +" has not been defined!!\n");  System.exit(0);  }  else  {  String result = "p."+v.result + "( " + el.result + ")";  String type = parser.hash.get(v.result);  Node a = new Node(result, type);  RESULT = a;//result assignment  }  :}  | ...

Declaration Sample Code: Game Card [] acard; Card c1; int i; c1 =[|5,Diamonds|,|8, Spades|,|9,Clubs|]; i=0; while(i<acard.length) card c1; C1= acard[i]; display (c1); i++; end while; end Game; var_decl ::= type:t var_list:vl SEMI var_list ::= var:v | var:v COMMA var_list:vl | ; Note: 1. Declaration need to be put before any other statement in each block. 2. Can declare a list of variable, Like: int a,b,c; 3. For every declaration, put the variable into symbol table.

Assignment Sample Code: Game Card [] acard; Card c1; int i; c1 =[|5,Diamonds|,|8, Spades|,|9,Clubs|]; i=0; while(i<acard.length) card c1; c1=acard[i]; display (c1); i++; end while; end Game; assign ::= var:v ASSIGN expr:e | card_assign |player_assign |array_assign ; card_assign ::= var ASSIGN card ; player_assign ::= var ASSIGN player ; array_assign ::= var ASSIGN LPAR_SQ var_list RPAR_SQ |card_array_assign |player_array_assign ; card_array_assign ::= var ASSIGN LPAR_SQ card_list RPAR_SQ ; player_array_assign ::= var ASSIGN LPAR_SQ player_list RPAR_SQ;

Assignment Sample Code: Game Card [] acard; Card c1; int i; c1 =[|5,Diamonds|,|8, Spades|,|9,Clubs|]; i=0; while(i<acard.length) card c1; c1=acard[i]; display (c1); i++; end while; end Game; Type check: 1.For variable, check symbol table to get its type and check if right hand and left hand type are equal. 2.For other non terminal symbol: Create node for every symbol which have a attribute of type.

Condition and Loop stat Game Player p1,p2; Card c1,c2; p1=|"Anyu"|; p2=|"Guo xiaoming"|; defaultpile; Defaultprior; shuffle; distribute (p1, 15); distribute (p2, 15); while(~( (p1.cards.length== 0)||(p2.cards.length==0) )) initRound; c1 = intend (p1); c2 = intend (p2); if(c1 < c2) remove(c2); else remove(c1); end if; end while; end Game; cond_stat ::= IF LPAR expr RPAR block END IF | IF LPAR expr RPAR block ELSE block END IF

Condition and Loop stat Game Player p1,p2; Card c1,c2; p1=|"Anyu"|; p2=|"Guo xiaoming"|; defaultpile; Defaultprior; shuffle; distribute (p1, 15); distribute (p2, 15); while(~( (p1.cards.length== 0)||(p2.cards.length==0) )) initRound; c1 = intend (p1); c2 = intend (p2); if(c1 < c2) remove(c2); else remove(c1); end if; end while; end Game; loop_stat ::= WHILE LPAR expr RPAR block END WHILE |FOR LPAR expr SEMI expr SEMI expr RPAR block END FOR

Java END LIBRARY

Game !a sample game! Player p1,p2; Card c1,c2; p1=|"Anyu"|;p1 = new Player(); p.g.setPlayer(p1,"Anyu"); p2=|"Guo xiaoming"|; defaultpile;p.g.defaultPile(); hasJoker;p.g.hasJoker(); suitPriority: Diamonds>Spades>Clubs>Hearts; p.g.pri.setSuitPriority("HEARTS;CLUBS;SPADES;DIAMONDS"); numPriority: 1>10>9>8>7>6>5>4>3>2>11>12>13; p.g.pri.setNumPriority("13;12;11;2;3;4;5;6;7;8;9;10;1"); shuffle;p.g.shuffle(); distribute (p1, 15);p.g.distribute(p1,15); distribute (p2, 15); initplayer(p1);p.g.nextPlayer(p1);

while(~( (p1.cards.length==0)||(p2.cards.length==0)))(p1.cards.size()==0) initRound;p.g.initRound(); c1 = intend (p1);c1=p.g.intend(p.g, p1); c2 = intend (p2); if(c1 < c2) p.g.pri.checkPrioritySingleCard(c1,c2))==0 remove(c2);p.g.removeCard(c2); display(p2.name);p.g.display(p2.name); display("is bigger");p.g.display("is bigger"); else remove(c1); display(p1.name); display("is bigger"); end if; end while; if(p1.cards.length==0) display(p1.name); else display(p2.name); end if; display("You Win"); end Game;

Java END LIBRARY details Global  defaultPile()  setPlayer(Player, String,)(Player, String, ArrayList )  setCard(Card, int, String)  shuffle()  distribute(Player, int)  returnCard(int)return Card  removeCard(Card)  showRoundInfo()  checkWin()return int  initialRound()  nextPlayer(int)(Player)  firstPlayer()  lastPlayer()  showWinner()  setRoundCards()  addRoundCards()  showNext(int, int)  display(int, String)(Card)(Player)  hasJoker()  play(Global, int)  Intend(Global, Player)return Card  initRound()

Java END LIBRARY details Card ◦showCard()return String ◦changeSuit(Card)return int ◦returnCard(String)return Card Player ◦addCards(Card) ◦showCards()return String ◦removeBtn(String) ◦removeCard(String)

Java END LIBRARY details Priority ◦checkPriority(Card[], Card[])return int ◦checkPrioritySingleCard(Card, Card)return int ◦setSuitPriority(Stirng) ◦getSuitPriority(String)return int ◦setNumPriority(String) ◦getNumPriority(String)return int ◦setJokers() ◦defaultPriority() ◦setPriority(String, String) ◦checkPriorityMultiPlayers(Vector )

Java END LIBRARY details SourceCards ◦defaultSourceVecs() ◦defaultSourceCards() ◦addJoker()

Test The testing was implemented in two parts. Testing only using the cup and lex file. Testing including the java library.

Part 1: 1. Assignment - Functionality of assignment of the basic types: String, int, Card, Player 2. Arithmetic - Functionality of +, -, *, /, ++, Boolean expression - Functionality of &&, ||, ~=, ~ 4. if - Functionality of if...end if, if...else...end if, if.... else if.....else....end if 5. while, for - Functionality of for and while loops. 6. Array - Functionality of int, Card, Player array, and array.length 7. Functions - Functionality of user defined function. Part 2: 1. Initialize - Functionality of defaulpile and shuffle; 2. priority - Functionality of defaultprior and user defined priority 3. distribute - Functionality of distribute cards to the users, the cards will display on the players’ panel after call this function 4. intend - Functionality of button click from the Players’ panel. 5. remove - Functionality of remove function which will remove a cards from the user panel.

Conclusion We finish the project in time. Our language is a strong typed language Our language has type checking. Our language can show the GUI.

Questions?

Thank you!