Skip to content

Commit

Permalink
Update par/calc.par Sample
Browse files Browse the repository at this point in the history
  • Loading branch information
badlee committed May 25, 2011
1 parent 5ba6f79 commit 7548938
Show file tree
Hide file tree
Showing 9 changed files with 3,954 additions and 161 deletions.
14 changes: 9 additions & 5 deletions driver_node.js_
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@


var ##PREFIX##_dbg_withtrace = false; var ##PREFIX##_dbg_withtrace = false;
var ##PREFIX##_dbg_string = new String(); var ##PREFIX##_dbg_string = new String();

if(##PREFIX##_dbg_withtrace){
var fd = require("fs").openSync("##PREFIX##_dbg_withtrace.log", "w+");
require('fs').writeSync(fd, new Date );
}
function __##PREFIX##dbg_print( text ) function __##PREFIX##dbg_print( text )
{ {
##PREFIX##_dbg_string += text + "\n"; ##PREFIX##_dbg_string += text + "\n";
Expand Down Expand Up @@ -100,7 +103,6 @@ function __##PREFIX##parse( src, err_off, err_la )
vstack.push( 0 ); vstack.push( 0 );


la = __##PREFIX##lex( info ); la = __##PREFIX##lex( info );

while( true ) while( true )
{ {
act = ##ERROR##; act = ##ERROR##;
Expand Down Expand Up @@ -263,16 +265,18 @@ function __##PREFIX##parse( src, err_off, err_la )
} }


if( ##PREFIX##_dbg_withtrace ) if( ##PREFIX##_dbg_withtrace )
{ {
alert( ##PREFIX##_dbg_string );
require('fs').writeSync(fd, ##PREFIX##_dbg_string );
##PREFIX##_dbg_string = new String(); ##PREFIX##_dbg_string = new String();
} }
} }


if( ##PREFIX##_dbg_withtrace ) if( ##PREFIX##_dbg_withtrace )
{ {
__##PREFIX##dbg_print( "\nParse complete." ); __##PREFIX##dbg_print( "\nParse complete." );
alert( ##PREFIX##_dbg_string ); require('fs').writeSync(fd, ##PREFIX##_dbg_string );
##PREFIX##_dbg_string = new String();
} }


return err_cnt; return err_cnt;
Expand Down
10 changes: 5 additions & 5 deletions jscc.js
Original file line number Original file line Diff line number Diff line change
@@ -1,13 +1,13 @@
print = require("sys").puts; print = require("sys").puts;
_print = function(str){console.log(str)}; _print = function(str){console.log("__PRINT__\n"+str);};
_error = function(str){console.log("___ ERROR ___\n"+str)}; _error = function(str){console.log("___ ERROR ___\n"+str);};
_warning = function(str){console.log("--- WARN ---\n"+str)}; _warning = function(str){console.log("--- WARN ---\n"+str);};
alert = function(str){console.log("=== ALERT ===\n"+str)}; alert = function(str){console.log("=== ALERT ===\n"+str);};
_quit = process.exit; _quit = process.exit;
read_file = function(str){return require("fs").readFileSync(str).toString("utf-8");}; read_file = function(str){return require("fs").readFileSync(str).toString("utf-8");};
write_file = require("fs").writeFileSync; write_file = require("fs").writeFileSync;
process.on('uncaughtException', function (err) { process.on('uncaughtException', function (err) {
console.log(err.stack); console.log("__ERROR__\n"+err.stack);
}); });


/* -HEADER---------------------------------------------------------------------- /* -HEADER----------------------------------------------------------------------
Expand Down
31 changes: 27 additions & 4 deletions par/calc.par
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/~ /~
Expression calculator written in JS/CC (Rhino/Spidermonkey/V8 version) Expression calculator written in JS/CC (nodejs)
~/ ~/


/~ /~
Expand All @@ -9,15 +9,27 @@


'\(' /~ Non-associative tokens ~/ '\(' /~ Non-associative tokens ~/
'\)' '\)'
'[0-9]+' INT [* %match = parseInt( %match ); *] '[0-9]+\.?[0-9]*' NUMBER [* %match = parseFloat( %match ); *]
'0x[0-9A-Fa-f]+' Hex [* %match = parseFloat( %match ); *]
'PI'
'SQRT'
'ABS'
'FLOOR'
'CEIL'
'RAND'
'ROUND'
'MAX'
'MIN'
; ;


< '\+' /~ Left-associative tokens, lowest precedence ~/ < '\+' /~ Left-associative tokens, lowest precedence ~/
'\-'; '\-'
'^';


< '\*' /~ Left-associative tokens, highest precedence ~/ < '\*' /~ Left-associative tokens, highest precedence ~/
'/'; '/';



## ##


/~ /~
Expand All @@ -34,11 +46,22 @@ p: e [* console.log( %1 ); *]
~/ ~/
e: e '+' e [* %% = %1 + %3; *] e: e '+' e [* %% = %1 + %3; *]
| e '-' e [* %% = %1 - %3; *] | e '-' e [* %% = %1 - %3; *]
| e '^' e [* %% = Math.pow(%1, %3); *]
| e '*' e [* %% = %1 * %3; *] | e '*' e [* %% = %1 * %3; *]
| e '/' e [* %% = %1 / %3; *] | e '/' e [* %% = %1 / %3; *]
| '-' e &'*' [* %% = %2 * -1; *] | '-' e &'*' [* %% = %2 * -1; *]
| PI [* %% = Math.PI; *]
| MAX e e [* %% = Math.max(%2,%3); *]
| MIN e e [* %% = Math.min(%2,%3); *]
| SQRT e [* %% = Math.sqrt(%2); *]
| FLOOR e [* %% = Math.floor(%2); *]
| CEIL e [* %% = Math.ceil(%2); *]
| ABS e [* %% = Math.abs(%2); *]
| ROUND e [* %% = Math.round(%2); *]
| RAND [* %% = Math.random(); *]
| '(' e ')' [* %% = %2; *] | '(' e ')' [* %% = %2; *]
| INT | NUMBER
| Hex
; ;


/~ /~
Expand Down
Loading

0 comments on commit 7548938

Please sign in to comment.