Bovid / Bovid.js

Bison in JavaScript
http://bovid.github.io/Bovid.js
16 stars 3 forks source link

hello world grammar mistake? #4

Open flip111 opened 9 years ago

flip111 commented 9 years ago

I have my test file like this

//option namespace:someNamespace
//option class:someClass
//option fileName:out.php
//option extends:someExtend
//option parserValue:someParser

//Lexical Grammar
%lex

HELLO            hello
WORLD            world

//Create tokens from lexical analysis
%%
HELLO {
  return 'hi';
}

WORLD {
  return 'planet';
}

/lex

%%

test
  : HELLO WORLD

When i run jison it returns:

Executing: jison test.jison
Failed: 8

Is this a mistake of the grammar or another thing that is going wrong entirely??

robertleeplummerjr commented 9 years ago

Try:

test : HELLO WORLD ;

On Wed, Oct 22, 2014 at 2:41 PM, flip111 notifications@github.com wrote:

I have my test file like this

//option namespace:someNamespace //option class:someClass //option fileName:out.php //option extends:someExtend //option parserValue:someParser

//Lexical Grammar %lex

HELLO hello WORLD world

//Create tokens from lexical analysis %% HELLO { return 'hi'; }

WORLD { return 'planet'; }

/lex

%%

test : HELLO WORLD

When i run jison it returns:

Executing: jison test.jison Failed: 8

Is this a mistake of the grammar or another thing that is going wrong entirely??

— Reply to this email directly or view it on GitHub https://github.com/robertleeplummerjr/jison/issues/4.

Robert Plummer

flip111 commented 9 years ago

this helped a little bit i guess ..

Executing: jison test.jison

Opening newly created jison js file: test.js
Something went bad

what does that mean?

robertleeplummerjr commented 9 years ago

just execute jison test.jison and ensure it is working before trying it with ports.

On Wed, Oct 22, 2014 at 2:52 PM, flip111 notifications@github.com wrote:

this helped a little bit i guess ..

Executing: jison test.jison

Opening newly created jison js file: test.js Something went bad

what does that mean?

— Reply to this email directly or view it on GitHub https://github.com/robertleeplummerjr/jison/issues/4#issuecomment-60135542 .

Robert Plummer

flip111 commented 9 years ago

That test file didn't work, i corrected it to this

test.jison

//option namespace:someNamespace
//option class:someClass
//option fileName:out.php
//option extends:someExtend
//option parserValue:someParser

//Lexical Grammar
%lex

//Create tokens from lexical analysis
%%
hello { return 'HELLO'; }
world { return 'WORLD'; }
\s+   {/* skip whitespace */}

/lex

%%

test
  : HELLO WORLD ;

input.txt

hello world

Executed commands:

jison test.jison
node test.js input.txt

This gave no error so i assume everything went succesful. However i don't know yet how i can access the generated AST.

Using those files like that and trying it with the php port:

D:\dev\console\jisonTest>node %APPDATA%\npm\node_modules\jison\ports\php\php.js test.jison
Executing: jison test.jison

Opening newly created jison js file: test.js
Something went bad
robertleeplummerjr commented 9 years ago

What happens when you execute jison test.jison?

On Fri, Oct 24, 2014 at 2:55 PM, flip111 notifications@github.com wrote:

That test file didn't work, i corrected it to this

test.jison

//option namespace:someNamespace //option class:someClass //option fileName:out.php //option extends:someExtend //option parserValue:someParser

//Lexical Grammar %lex

//Create tokens from lexical analysis %% hello { return 'HELLO'; } world { return 'WORLD'; } \s+ {/* skip whitespace */}

/lex

%%

test : HELLO WORLD ;

input.txt

hello world

Executed commands:

jison test.jison node test.js input.txt

This gave no error so i assume everything went succesful. However i don't know yet how i can access the generated AST.

Using those files like that and trying it with the php port:

D:\dev\console\jisonTest>node %APPDATA%\npm\node_modules\jison\ports\php\php.js test.jison Executing: jison test.jison

Opening newly created jison js file: test.js Something went bad

— Reply to this email directly or view it on GitHub https://github.com/robertleeplummerjr/jison/issues/4#issuecomment-60433080 .

Robert Plummer

flip111 commented 9 years ago

nothing visible in console (one empty line to be precise)

D:\dev\console\jisonTest>jison test.jison

D:\dev\console\jisonTest>
flip111 commented 9 years ago

I looked at the calculator example and i noticed it was using some extra commands typeof console !== 'undefined' ? console.log($1) : print($1); return $1;. So i added that into my file and now i get output hello. Ok not hello world .. so there is still something wrong but at least it's parsing it without errors and i get some result.

//option namespace:someNamespace
//option class:someClass
//option fileName:out.php
//option extends:someExtend
//option parserValue:someParser

//Lexical Grammar
%lex

//Create tokens from lexical analysis
%%
hello { return 'HELLO'; }
world { return 'WORLD'; }
\s+   {/* skip whitespace */}

/lex

%%

test
  : HELLO WORLD {
      typeof console !== 'undefined' ? console.log($1) : print($1);
      return $1;
    };

As for the PHP version it still doesn't work.

flip111 commented 9 years ago

Hi i found the bug. This line assumes that the input file lines are terminated by \n but in my case they are terminated by \r\n. Then later the filename out.php is replaced by out.php\r and windows can not write a filename like this so the error occurs.

robertleeplummerjr commented 9 years ago

Nice find, we should then handle both windows and linux lines.

On Sat, Nov 1, 2014 at 1:25 PM, flip111 notifications@github.com wrote:

Hi i found the bug. This line https://github.com/robertleeplummerjr/jison/blob/master/ports/php/php.js#L91 assumes that the input file lines are terminated by \n but in my case they are terminated by \r\n. Then later https://github.com/robertleeplummerjr/jison/blob/master/ports/php/php.js#L92-L98 the filename out.php is replaced by out.php\r and windows can not write a filename like this so the error occurs.

— Reply to this email directly or view it on GitHub https://github.com/robertleeplummerjr/jison/issues/4#issuecomment-61375715 .

Robert Plummer