do fifty- twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...need to spit out multiple ...
TRANSCRIPT
![Page 1: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/1.jpg)
Do Fifty-Two
![Page 2: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/2.jpg)
Motivation
▪▪▪
▪
▪▪
![Page 3: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/3.jpg)
Overview of the Language
▪
▪
▪▪▪▪▪
![Page 4: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/4.jpg)
Tutorial
![Page 5: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/5.jpg)
Tutorial
![Page 6: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/6.jpg)
Tutorial
![Page 7: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/7.jpg)
Tutorial
![Page 8: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/8.jpg)
Tutorial
![Page 9: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/9.jpg)
Tutorial
![Page 10: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/10.jpg)
//A Sample Program
configure numberOfPlayers: 2 configure highestCard: aceconfigure ascendingOrder: true
Player has Number called x // declare new field “x” for Player
new Number warCount: 0 // declare new variable “warCount”
setup:// deal cardsdo turn with player1do output with "The score of player1 before: " +
player1.xdo output with "The score of player1 after: " +
player1.xdo output with "warCount: " + x
round:do output with "number of players: " +
numberOfPlayersdo quit
turn with Player player:if p.x = 0:
p.x : p.x + 1do quit
![Page 11: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/11.jpg)
Behind-the-Scenes
![Page 12: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/12.jpg)
Implementation
![Page 13: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/13.jpg)
Implementation
do output with “Hello”
hello: do output with “Hello”
(vim) set: list
do output with “Hello”$$hello:$^Ido output with “Hello”$
![Page 14: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/14.jpg)
Implementation
Is this even Context-Free?
hello with Number nif n > 5:
if num > 10:do output with “Hello!”
else:do output with “Bye!”
hello with Number n$^Iif n > 5:$^I^Iif num > 10:$^I^I^Ido output with “Hello!”$^I^Ielse:$^I^I^Ido output with “Bye!”$
![Page 15: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/15.jpg)
Implementation
scanner.ml:let cur_depth = ref 0
If depth > cur_depth, <INDENT>else if depth < cur_depth, <DEDENT>else <NEWLINE>
hello:<INDENT>do output with “Hello”<DEDENT>
Just as if we had used braces!
hello:<LBRACE>do output with “Hello”<RBRACE>
![Page 16: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/16.jpg)
Implementation
But what about:
hello with Number n:<INDENT>if n > 2:
<INDENT>if n > 4:<DEDENT??>
Does not parse. Second “if” never closed!
Need to spit out multiple <DEDENT> tokens for a single regex in scanner.ml. Can we even do that in Ocamllex?
![Page 17: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/17.jpg)
Implementation
No. Parser takes one token at a time—we can’t just pass it several at once.
scanner.mlcache.mlparser.ml
<DEDENT_MULT(n)>
if cache is not emptyreturn front of cache
else get tokenif token is <DEDENT_MULT(n)>
cache n <DEDENT> tokensreturn front of cache
elsereturn token
![Page 18: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/18.jpg)
Implementation
What happens when someone uses one of our “standard” procedures?
do output with a
UndeclaredID(“The procedure output has not been declared.”)
It might be implemented in our runtime, but the semantic analyzer doesn’t know about it.
![Page 19: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/19.jpg)
Implementation
#include <stdlib.h>#include <stdio.h>
int main … etc.
Standard library inserted at the top of the file. All function and variable declarations added to environment before the rest of the program goes through the semantic analyzer.
How to do this without implementing a preprocessor?
![Page 20: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/20.jpg)
Implementation
Another thing to consider:
Do: Java:card.suit -> card.suitdeck.size -> deck.size()
How do we address what could be lots and lots of special cases?
![Page 21: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/21.jpg)
Implementation
stdlib.mlvars = [ (var_decl, java) … ]configs = [ config_decl … ]fields = [ (field_decl, java) … ]funcs = [ func_decl … ]
semantic.mlstarting scope includes varsstarting environment includes
configs, fields, funcs
compile.mllet java_of_var env var =
if var is in stdlib, use the java thereelse use the var_id
![Page 22: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/22.jpg)
Implementation
▪▪
▪▪
▪▪
▪▪▪
▪▪
![Page 23: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/23.jpg)
Implementation
▪
▪
▪▪
▪
▪ if player1_hand_top > player2_hand_top
▪
![Page 24: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/24.jpg)
Implementation
![Page 25: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/25.jpg)
Implementation
![Page 26: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/26.jpg)
Implementation
![Page 27: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/27.jpg)
Testing
▪▪▪
▪▪
![Page 28: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/28.jpg)
TestinG
Check() { error=0 basename=`echo $1 | sed 's/.*\\/// s/.do//'` reffile=`echo $1 | sed 's/.do$//'` basedir="`echo $1 | sed 's/\/[^\/]*$//'`/." javafile=`echo $basename |sed -e 's/^//g' -e 's/-/_/g'` ajavafile=`echo $javafile | perl -pe 's/\S+/\u$&/g'` newjavafile=`echo $ajavafile | perl -pe 's/([^ ])_([a-z])/\\1\\u\\2/g'` echo 1>&2 echo "###### Testing $basename" 1>&2 generatedfiles="$generatedfiles tests/${newjavafile}.java tests/${basename}.diff tests/${basename}.out" && Run "$DO_FIFTY_TWO" $1 && Run "mv Game.java MyPlayer.java $RUNTIME" && Run "cd runtime/" && CompileRunTime && Run "java -cp . $MAIN >" ../tests/${basename}.out && Run "make clean" && Run "cd .." && Compare tests/${basename}.out tests/${basename}.gold tests/${basename}.diff # Report the status and clean up the generated files}
![Page 29: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/29.jpg)
TestinG
CheckFail() { error=0 basename=`echo $1 | sed 's/.*\\/// s/.do//'` reffile=`echo $1 | sed 's/.do$//'` basedir="`echo $1 | sed 's/\/[^\/]*$//'`/." javafile=`echo $basename |sed -e 's/^//g' -e 's/-/_/g'` ajavafile=`echo $javafile | perl -pe 's/\S+/\u$&/g'` newjavafile=`echo $ajavafile | perl -pe 's/([^ ])_([a-z])/\\1\\u\\2/g'` echo 1>&2 echo "###### Testing $basename" 1>&2 generatedfiles="$generatedfiles tests/test_failure/${newjavafile}.java tests/test_failure/${basename}.diff tests/test_failure/${basename}.out" && RunFail "$DO_FIFTY_TWO" $1 ">" tests/test_failure/${basename}.out # Report the status and clean up the generated files}
![Page 30: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/30.jpg)
Testing
![Page 31: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/31.jpg)
Summary
![Page 32: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/32.jpg)
Summary
▪
▪
▪
▪
▪
▪
![Page 33: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/33.jpg)
Lessons Learned
![Page 34: Do Fifty- Twosedwards/classes/2014/w4115-fall/reports/do-fifty-two...Need to spit out multiple tokens for a single regex in scanner.ml. Can we even ... return front](https://reader034.vdocument.in/reader034/viewer/2022042909/5f3c613bc69a4526c33895b3/html5/thumbnails/34.jpg)
Credits