Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added include to BNF syntax for multi script type combinations, not f…
…inished though. Fixed calculator example.
- Loading branch information
1 parent
d2bfd96
commit 1deb96b
Showing
6 changed files
with
59 additions
and
33 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<syntax> ::= <expression> | <expression> <nextline> <syntax> | ||
<syntax> ::= <expression> | ||
<expression> ::= <number> <type> <number> | ||
<number> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ||
<type> ::= + | - | * | / | ||
<nextline> ::= "\r" "\n" | "\n" | ||
<number> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | ||
<type> ::= "+" | "-" | "*" | "/" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
1+1 | ||
1+1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
|
||
console.log( "This is a simple calculator language that looks at a file for basic math, and computes each line.") | ||
console.log( "This is a simple calculator language that looks at a file for basic math, and computes each line."); | ||
|
||
var i = require( "./calculator.bnf.js" ).interpreter; | ||
i.AddTokenEventByName( "expression", function( token ){ | ||
var left = i.SeekTokenByName( token, "number" ).text; | ||
var type = i.SeekTokenByName( token, "type" ).text; | ||
var right = i.SeekTokenByName( token, "number" ).text; | ||
var events = { "expression":function( token ){ | ||
var left = this.SeekNext( "number" ).text; | ||
var type = this.SeekNext( "type" ).text; | ||
var right = this.SeekNext( "number" ).text; | ||
|
||
//Equate | ||
var equate = -1; | ||
eval( "equate = " + left + type + right + ";" ); | ||
console.log( "File found syntax " + equate ); | ||
} ); | ||
} }; | ||
|
||
var parserObject = require( "../../lib/parser.js" ).parser; | ||
var parser = new parserObject( i ); | ||
|
||
parser.ParseScript( "calc.calc" ); | ||
|
||
//var interpreter = new require( "./parser.js" ).languageScript( "calc.bnf" ); | ||
var parser = null; | ||
var Compiler = require('../../lib/compiler.js').Compiler; | ||
var compiler = new Compiler(); | ||
compiler.CompileScript( __dirname + "/calc.bnf", "doq", function( interpreter ){ | ||
var parser = compiler.CreateParser( interpreter, events ); | ||
parser.ParseScript( __dirname + "/calc.calc" ); | ||
} ); |
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
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
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