ridencww / goldengine

Java implementation of Devin Cook's GOLD Parser engine
Other
35 stars 14 forks source link

Problem with the new lines ? #9

Closed stefv closed 11 years ago

stefv commented 11 years ago

Hi,

I have a strange problem. At first it was with my grammar but I adapted the grammar of the sample2 to use a new line based grammar:

{WS} = {Whitespace} - {CR} - {LF} Whitespace = {WS}+

NewLine = {CR}{LF}|{CR}

<nl> ::= NewLine <nl> !One or more | NewLine

<Statements> ::= <Statement> <nl> <Statements> | <Statement> <nl>

Finally, here the kind of code I used with this grammar: assign n = 1 while n >= 1 do display n assign n = n - 1 end display 'Blast off!'

This code is working perfectly with Gold Parser Builder 5.2 but if I try it with the Iden Java Engine, I have this error:

2013-06-25 23:20:23 ERROR HtmlController:255 - Lexical error at line 1, column 13. Read (Error) 2013-06-25 23:20:23 ERROR HtmlController:256 - assign n = 1 while n >= 1 do display n assign n = n - 1 end display 'Blast off!'

I just have "(Error)" without a real reason of the error.

Is there a mistake in my grammar or one problem with the Iden Java Engine ?

Thank you for your help.

Regards, Stef

ridencww commented 11 years ago

It is hard to tell if the problem is in the grammar or the engine without the complete grammar. Can you provide a link to the complete grammar or email it to me? riden -at- creativewidgetworks -dot- com

stefv commented 11 years ago

Thank you for your quick reply.

Like I said, I just reused the grammar from the sample2 adapted for a line based grammar:

"Name" = 'Simple' "Author" = 'Devin Cook' "Version" = '2.0' "About" = 'This is a very simple grammar designed for use in examples'

"Case Sensitive" = False "Start Symbol" = <Statements>

Comment Block @= { Nesting = All, Advance = Character }

Comment Start = '/' Comment End = '/'

Comment Line = '//'

{String Ch 1} = {Printable} - [''] {String Ch 2} = {Printable} - ["]

Id = {Letter}{AlphaNumeric}*

! String allows either single or double quotes

StringLiteral = '' {String Ch 1}* '' | '"' {String Ch 2}* '"'

NumberLiteral = {Digit}+('.'{Digit}+)?

{WS} = {Whitespace} - {CR} - {LF} Whitespace = {WS}+

NewLine = {CR}{LF}|{CR}

<nl> ::= NewLine <nl> !One or more | NewLine

<Statements> ::= <Statement> <nl> <Statements> | <Statement> <nl>

<Statement> ::= display <Expression> | display <Expression> read ID | assign ID '=' <Expression> | while <Expression> do <Statements> end | if <Expression> then <Statements> end | if <Expression> then <Statements> else <Statements> end

<Expression> ::= <Expression> '>' <Add Exp> | <Expression> '<' <Add Exp> | <Expression> '<=' <Add Exp> | <Expression> '>=' <Add Exp> | <Expression> '==' <Add Exp> | <Expression> '<>' <Add Exp> | <Add Exp>

<Add Exp> ::= <Add Exp> '+' <Mult Exp> | <Add Exp> '-' <Mult Exp> | <Add Exp> '&' <Mult Exp> | <Mult Exp>

<Mult Exp> ::= <Mult Exp> '*' <Negate Exp> | <Mult Exp> '/' <Negate Exp> | <Negate Exp>

<Negate Exp> ::= '-' <Value> | <Value>

<Value> ::= ID
| StringLiteral | NumberLiteral | '(' <Expression> ')'

stefv commented 11 years ago

I'm sorry Ralph, I think I made a mistake somewhere because reusing exacly the skeleton program, it's working. I will start again from the skeleton.

stefv commented 11 years ago

I found the origin of the problem. I was using a source code to parse from a XML file (in one element). When I'm reading this code to put it in a String, the newlines are \n. The engine can't accept it because it's not the definition in the grammar for a newline.

But if I change the \n to become \r\n, it's working because the grammar accept it.

Finally, it's not a problem from the engine but from the grammar. I reused the example for the newline from the Gold website: http://goldparser.org/doc/grammars/example-line-based.htm

But I think it's a mistake and it must be: NewLine = {CR}{LF}|{CR}|{LF}

ridencww commented 11 years ago

Thank you for following up and I'm glad you're moving forward. I will close this issue, but don't hesitate to open a new one if you find or suspect defects in the engine. I ported Devin's reference engine as closely as possible, but I have run into a few defects that weren't caught by my tests.

I'd be interested in ways that the engine can provide more useful error messages. As a developer, I don't like cryptic or incomplete error messages. Any input or examples of unhelpful error messages are welcome.