Created
September 1, 2014 08:53
-
-
Save vkz/f70a6a2b7bcfa68fc760 to your computer and use it in GitHub Desktop.
Breaking associativity in OMeta
This file contains hidden or 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
var ometajs = require('ometajs'), | |
Parser = ometajs.grammars.BSJSParser; | |
// Source: http://tratt.net/laurie/research/pubs/html/tratt__direct_left_recursive_parsing_expression_grammars/ | |
// '1-2-3' -> ((1-2)-3) | |
ometa a <: Parser { | |
Expr = Expr:l "-" Num:r -> [l, '-', r] | |
| Num:i -> [i], | |
Num = /[0-9]+/ | |
} | |
// '1-2-3' -> (1-(2-3)) | |
ometa arr <: Parser { | |
Expr = Expr:l "-" Expr:r -> [l, '-', r] | |
| Num:i -> [i], | |
Num = /[0-9]+/ | |
} |
This file contains hidden or 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
var ometajs = require('ometajs'), | |
grammars = require('./grammar'); | |
// Adding right-recursive invocation to a left-recurive rule changes | |
// parsing associativity | |
grammars.a.matchAll('1-2-3', 'Expr'); | |
grammars.arr.matchAll('1-2-3', 'Expr'); | |
grammars.b.matchAll('1+2-3', 'Expr'); | |
grammars.brr.matchAll('1+2-3', 'Expr'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment