Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello world grammar mistake? #4

Open
flip111 opened this issue Oct 22, 2014 · 9 comments
Open

hello world grammar mistake? #4

flip111 opened this issue Oct 22, 2014 · 9 comments

Comments

@flip111
Copy link

flip111 commented Oct 22, 2014

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
Copy link
Member

Try:

test
: HELLO WORLD ;

On Wed, Oct 22, 2014 at 2:41 PM, flip111 [email protected] 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
Copy link
Author

flip111 commented Oct 22, 2014

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
Copy link
Member

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 [email protected] 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
Copy link
Author

flip111 commented Oct 24, 2014

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
Copy link
Member

What happens when you execute jison test.jison?

On Fri, Oct 24, 2014 at 2:55 PM, flip111 [email protected] 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
Copy link
Author

flip111 commented Oct 24, 2014

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

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

D:\dev\console\jisonTest>

@flip111
Copy link
Author

flip111 commented Nov 1, 2014

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
Copy link
Author

flip111 commented Nov 1, 2014

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
Copy link
Member

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

On Sat, Nov 1, 2014 at 1:25 PM, flip111 [email protected] 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants