Пример #1
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!
#
# Beyond that, you will receive full credit for whatever you submit. Our
# 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.
</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!
Пример #3
0
<script type="text/javascript">
function tvtropes(tgwtg) {
    var theonion = "reddit" + "pennyarcade";
    var loadingreadyrun = function(extracredits) {
        write(tgwtg);
        write(" "); 
        write(extracredits);
    } ;    
    return loadingreadyrun; 
}
var yudkowsky = tvtropes(3); 
var tgwtg = 888;
var extracredits = 999;
yudkowsky(4); 
/* Shoutouts to a random sampling of Western Web Comedy,
 * Analysis and Literature circa 2012. Bonus points if you
 * can get any of them to return the favor. Udacity needs 
 * a tvtropes page. :-) */ 
</script>
</p> 
<hr> </hr> 
<img src="cs262.png"> </img> 
</html>
"""


htmlast = htmlparser.parse(webpage,lexer=htmllexer) 
graphics.initialize() # let's start rendering a webpage
htmlinterp.interpret(htmlast) 
graphics.finalize() # we're done rendering this webpage
    var loadingreadyrun = function(extracredits) {
        write(tgwtg);
        write(" ");
        write(extracredits);
    } ;
    return loadingreadyrun;
}
var yudkowsky = tvtropes(3);
var tgwtg = 888;
var extracredits = 999;
yudkowsky(4);
/* Shoutouts to a random sampling of Western Web Comedy,
 * Analysis and Literature circa 2012. Bonus points if you
 * can get any of them to return the favor. Udacity needs
 * a tvtropes page. :-) */
</script>
</p>
<hr> </hr>
<img src="cs262.png"> </img>
</html>
"""


htmlast = htmlparser.parse(webpage,lexer=htmllexer)
graphics.initialize() # let's start rendering a webpage
htmlinterp.interpret(htmlast)
graphics.finalize() # we're done rendering this webpage



Пример #5
0
import ply.lex as lex
import ply.yacc as yacc
import htmltokens
import htmlgrammar
import htmlinterp
import graphics

htmllexer = lex.lex(module=htmltokens)
htmlparser = yacc.yacc(module=htmlgrammar, tabmodule="parsetabhtml")

f = open("37_factorial.html")
contents = f.read()
parse_tree = htmlparser.parse(contents, lexer=htmllexer)

graphics.initialize()
htmlinterp.interpret(parse_tree)
graphics.finalize()


Пример #6
0
import ply.lex as lex
import ply.yacc as yacc
import htmltokens
import htmlgrammar
import htmlinterp
import graphics

htmllexer = lex.lex(module=htmltokens)
htmlparser = yacc.yacc(module=htmlgrammar, tabmodule="parsetabhtml")

f = open("37_factorial.html")
contents = f.read()
parse_tree = htmlparser.parse(contents, lexer=htmllexer)

graphics.initialize()
htmlinterp.interpret(parse_tree)
graphics.finalize()