예제 #1
0
                interpret(subtrees)
                graphics.endtag()
        elif nodetype == "javascript-element":
            jstext = node[1]
            jslexer = lex.lex(module=jstokens)
            jsparser = yacc.yacc(module=jsgrammar)
            jstree = jsparser.parse(jstext, lexer=jslexer)
            result = jsinterp.interpret(jstree)
            graphics.word(result)
            ##            if False:
            ##                print jstext
            ##            jslexer.input(jstext)
            ##            while True:
            ##                tok = jslexer.token()
            ##                if not tok: break
            ##                print tok

            jsparser = yacc.yacc(module=jsgrammar, tabmodule="parsetabjs")
            jsast = jsparser.parse(jstext, lexer=jslexer)
            result = jsinterp.interpret(jsast)
            graphics.word(result)
            ## WHAT'S HERE?


# Note that graphics.initialize and finalize will only work surrounding a call
# to interpret

graphics.initialize()  # Enables display of output.\
interpret([("word-element", "Hello")])
graphics.finalize()  # Enables display of output.
</p> 
<hr> </hr> <!-- draw a horizontal bar --> 
<p> 
Now we will use JavaScript to display even numbers in <i>italics</i> and
odd numbers in <b>bold</b>. <br> </br> 
<script type="text/javascript">
function tricky(i) {
  if (i <= 0) {
    return i; 
  } ; 
  if ((i % 2) == 1) {
    write("<b>");
    write(i); 
    write("</b>"); 
  } else {
    write("<i>");
    write(i); 
    write("</i>"); 
  }
  return tricky(i - 1); 
} 
tricky(10);
</script> 
</p> 
</html>"""

htmlast = htmlparser.parse(webpage,lexer=htmllexer) 
graphics.initialize() # let's start rendering a webpage
interpret(htmlast) 
graphics.finalize() # we're done rendering this webpage
예제 #3
0
</p> 
<hr> </hr> <!-- draw a horizontal bar --> 
<p> 
Now we will use JavaScript to display even numbers in <i>italics</i> and
odd numbers in <b>bold</b>. <br> </br> 
<script type="text/javascript">
function tricky(i) {
  if (i <= 0) {
    return i; 
  } ; 
  if ((i % 2) == 1) {
    write("<b>");
    write(i); 
    write("</b>"); 
  } else {
    write("<i>");
    write(i); 
    write("</i>"); 
  }
  return tricky(i - 1); 
} 
tricky(10);
</script> 
</p> 
</html>"""

htmlast = htmlparser.parse(webpage, lexer=htmllexer)
graphics.initialize()  # let's start rendering a webpage
interpret(htmlast)
graphics.finalize()  # we're done rendering this webpage
예제 #4
0
# web browser is not as "forgiving" as commercial browsers, but it is still
# possible to make interesting webpages with it. Use your creativity!

webpage = """<html>
Put something here. You must include embedded JavaScript for full credit,
but beyond that, do whatever you like.
<script type="text/javascript">write("In Javascript Land");</script>
<b>After javascript land</b>
</html>
"""

import ply.lex as lex
import ply.yacc as yacc
import htmltokens
import htmlgrammar
import htmlinterp
import graphics as graphics
import jstokens


htmllexer = lex.lex(module=htmltokens)
htmlparser = yacc.yacc(module=htmlgrammar,tabmodule="parsetabhtml")
ast = htmlparser.parse(webpage,lexer=htmllexer)
jslexer = lex.lex(module=jstokens)
graphics.initialize() # Enables display of output.
htmlinterp.interpret(ast)
graphics.finalize() # Enables display of output.

# We would also like to take this opportunity to thank everyone in Udacity for
# their support in making this class happen, especially those behind the scenes.
# Check out team.jpeg for a group photo!
예제 #5
0
#
from game import game
import graphics
import interface
import messaging

#-------------------------------------------------------------------------------
#Initialization
graphics.show_splash_screen()

clock = game.clock = pygame.time.Clock()
graphics.init()
interface.init()

time.sleep(2)  #More loading goes in this area!

graphics.finalize()
#-------------------------------------------------------------------------------

while game.running:
    game.frame_time = game.clock.tick(60)
    #Handle user input
    interface.handle_events()
    #Deal with any timed events (MAYBE THIS SHOULD BE DEALT WITH IN THE REACTOR.ITERATE BIT?)
    messaging.pump_messaging()
    #Handle internet events (and eventually game logic)
    reactor.iterate()
    #Draw pretty things
    graphics.render()
#GAME OVER MAN, GAME OVER
예제 #6
0
import interface
import messaging

#-------------------------------------------------------------------------------
#Initialization
graphics.show_splash_screen()

clock=game.clock=pygame.time.Clock()
graphics.init()
interface.init()

time.sleep(2) #More loading goes in this area!



graphics.finalize()
#-------------------------------------------------------------------------------

while game.running:
	game.frame_time=game.clock.tick(60)
	#Handle user input
	interface.handle_events()
	#Deal with any timed events (MAYBE THIS SHOULD BE DEALT WITH IN THE REACTOR.ITERATE BIT?)
	messaging.pump_messaging()
	#Handle internet events (and eventually game logic)
	reactor.iterate()
	#Draw pretty things
	graphics.render()
#GAME OVER MAN, GAME OVER