PEGs
Apuntes de PEG.js
- Documentación del Módulo PEG.js
- Introducción a los PEGs
- 0.10.0
s/buildParser/generate/
- 0.10.0 Se necesita poner
--format
:pegjs --format globals -e pl0 -o public/pl0.js -e pl0 lib/pl0.pegjs
- 0.10.0
- PEGJS
- La Calculadora Simple
- Eliminación de la Recursividad por la Izquierda en PEGs
- Dangling else: Asociando un else con su if mas cercano
Repositorios
- Ejemplos en PEGjs
- Viejos Ejemplos en PEGjs
[~/local/src/javascript/PLgrado/pegjs/examples(master)]$ pwd -P /Users/casiano/local/src/javascript/PLgrado/pegjs/examples
Herramientas
Bactracking en los PEGs
!INCLUDE "pegjsbacktracking.md"
Ejemplos
> parser = PEG.buildParser(`d = 'c'\ns = ('a' / 'b')+\n`, {allowedStartRules: ['d', 's']})
{ SyntaxError: [Function: peg$SyntaxError],
parse: [Function: peg$parse] }
> r = parser.parse('c')
'c'
> r = parser.parse('aba', {startRule: "s"})
[ 'a', 'b', 'a' ]
> parser = PEG.buildParser(`d = 'c'\ns = ('a' / 'b')+\n`, {allowedStartRules: ['d', 's'], output: "source"}); typeof parser
'string'
[~/pegjs/examples(master)]$ cat initializer.js
"use strict";
const PEG = require("pegjs");
const grammar = `
{
const util = require("util");
var g = "visible variable";
console.log("Inside Initializer! options = "+util.inspect(options));
}
start = 'a' { console.log('g = '+g); return 1; }
/ & { console.log('inside predicate: g = '+g); return true; } 'b' { return 2; }
`;
console.log("GRAMMAR:\n"+grammar);
const parser = PEG.buildParser(grammar);
console.log("PARSING 'a'");
let r = parser.parse("a", { x: 'hello' });
console.log(r);
console.log("PARSING 'b'");
r = parser.parse("b");
console.log(r);
Patrick Dubroy: Parsing, Compiling, and Static Metaprogramming
- Patrick Dubroy: Parsing, Compiling, and Static Metaprogramming Video
- Patrick Dubroy: Parsing, Compiling, and Static Metaprogramming Slides
altjs.coffee
is the code for the "AltJS language in 5 minutes" section presented in the second half of the talk.idgrep.coffee
(andidgrep.js
) is another example of using Esprima to do static analysis on JavaScript code.
Tree Transformations
Borrador
- borrador (work in progress. Don't look here)