Last active
December 13, 2015 04:59
-
-
Save dherman/4871805 to your computer and use it in GitHub Desktop.
demonstrating that lexing JavaScript requires a pushdown automaton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Looking at the preceding token when the lexer points to a '/' | |
character is insufficient to determine which context it's in. In | |
fact, you need to look at an arbitrary number of preceding tokens | |
to figure it out. This example demonstrates a case where we can | |
pump up the number of preceding tokens to an arbitrary size | |
before you can disambiguate your syntactic context. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.valueOf = function() { return 100; }; | |
Number.prototype.test = function() { return true; }; | |
var foo = 2, i = 5; | |
// ^ | |
// Have to look back to here to figure out | |
// that we're in an operand position. | |
function f() { /* arbitrary body */ } /foo/i.test('') && console.log("hello world!") | |
// ^ | |
// lexer is pointing here | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.valueOf = function() { return 100; }; | |
Number.prototype.test = function() { return true; }; | |
var foo = 2, i = 5; ( | |
// ^ | |
// Have to look back to here to figure out | |
// that we're in an operator position. | |
function f() { /* arbitrary body */ } /foo/i.test('') && console.log("hello world!") | |
// ^ | |
// lexer is pointing here | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment