Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Antlr Error with grammar(Antlr Error with grammar)
Antlr Error with grammar [message #1732994] Mon, 23 May 2016 15:37 Go to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

I have grammar like

Hello: 'def' name=id ('(' DataType ')');

DataType : (id+=id|num+=NUMBER|str+=STRING);

It is failing because 'id' is ambiguous. Could anyone please tell me how to overcome this?
Re: Antlr Error with grammar [message #1732995 is a reply to message #1732994] Mon, 23 May 2016 15:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
Please share a minimal but complete grammar that reproduces your problem

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Antlr Error with grammar [message #1732997 is a reply to message #1732995] Mon, 23 May 2016 16:09 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
DbmsStatement: 'dbms' DbmsStmt;

DbmsStmt: ( (DbmsKeys+=DbmsKeys)|
(DbmsAssign+=DbmsAssign)|
((jplId+=JPLID) (DbmsCommomn+=DbmsCommomn))|
((DbmsKeys+=DbmsKeys) (DbmsCommomn+=DbmsCommomn))
)+;

DbmsAssign: ((jplId+=(JPLID|DbmsKeys) (',' jplId+=(JPLID|DbmsKeys))*)
(('='|'==') (((DbmsDataTypes+=DbmsDataTypes)|(dbmsDecl+=DbmsDecl))|('(' DbmsStmt+=DbmsStmt ')')) (',')?)*
);
DbmsDecl: dbmsKeys+=DbmsKeys ('(' DbmsDataTypes+=DbmsDataTypes (','? DbmsDataTypes+=DbmsDataTypes)* ')')?;

DbmsCommomn: ('(' ((DbmsDataTypes+=DbmsDataTypes)|(dbmsDecl+=DbmsDecl)) (','? ((DbmsDataTypes+=DbmsDataTypes)|(dbmsDecl+=DbmsDecl)))* ')');

DbmsDataTypes: ((jplId+=JPLID)|(str+=STRING)|(num+=NUMBER)) ('[' (jplId+=JPLID) ']')?;

DbmsKeys: dbmsKeyWords+=(DBMS_KEYWORD1|DBMS_KEYWORD2|DBMS_KEYWORD3|DBMS_KEYWORD4|DBMS_KEYWORD5|DBMS_KEYWORD6|DBMS_KEYWORD7|DBMS_KEYWORD8|DBMS_KEYWORD9|
DBMS_KEYWORD10|DBMS_KEYWORD11|DBMS_KEYWORD12|DBMS_KEYWORD13|DBMS_KEYWORD14|DBMS_KEYWORD15|DBMS_KEYWORD16);

DBMS_KEYWORD1: ('sql'|'insert'|'into'|'values'|'execute'|'cursor'|'delete'|'case'|'update');

DBMS_KEYWORD2 : ('set'|'select'|'distinct'|'from'|'where'|'char'|'datetime'|'temp');

DBMS_KEYWORD3: ('group'|'by'|'having'|'like'|'exists'|'in'|'is'|'completion'|'run');

DBMS_KEYWORD4: ('any'|'all'|'some'|'and'|'or'|'left'|'right'|'inner'|'outer'|'join');

DBMS_KEYWORD5: ('float'|'int'|'long'|'create'|'table'|'database'|'drop'|'max'|'sum');

DBMS_KEYWORD6: ('between'| 'escape'|'order'|'asc'|'desc'|'not'|'null'|'avg'|'min');

DBMS_KEYWORD7: ('primary'|'foreign'|'key'|'references'|'like'|'escape'|'with'|'for');

DBMS_KEYWORD8: ('engine'|'close'|'column_names'| 'connection'|'close_all_connections');

DBMS_KEYWORD9: ('using'|'rpc'|'alias'|'binary'|'catquery'| 'to'|'separator'|'COUNT');

DBMS_KEYWORD10: ('heading'| 'on'|'off'|'column'|'names'|'format'|'occur'|'start');

DBMS_KEYWORD11: ('unique'|'connected'|'continue_bottom'|'continue_down'| 'onexit');

DBMS_KEYWORD12: ('continue_top'|'continue_up'|'store'|'file'|'onentry'|'onerror');

DBMS_KEYWORD13: ('application' |'autocommit'|'begin'|'browse'|'cancel'|'commit');

DBMS_KEYWORD14: ('rollback'|'user'|'database'|'datasource'|'server'|'procedure');

DBMS_KEYWORD15: ('declare'|'cursors'|'continue'|'stored_sub');

DBMS_KEYWORD16: ('save'|'flush'|'timeout'|'transaction');
Re: Antlr Error with grammar [message #1733001 is a reply to message #1732997] Mon, 23 May 2016 16:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
Hi,

this grammar has multiple problems.
first of all there are keywords that occurr more than once in a KEYWORDXX rule.
what should be parsed in that case.

then you have the problem that you have the pattern

list+=Element*

Element: parts+=Part+;

if you have part1 part2 part3 should hat give 1 element with 3 parts or 3 elements with 1 part?

another pattern you have is to have

plId+=JPLID in DbmsStmt and in DbmsAssign where should it go to?
you have to decide

DbmsStatement:
	'dbms' DbmsStmt;

DbmsStmt:
	(
	(DbmsAssign+=DbmsAssign) |
	((=>jplId+=JPLID) (DbmsCommomn+=DbmsCommomn)) |
	((=>DbmsKeys+=DbmsKeys) (DbmsCommomn+=DbmsCommomn)?)
	
	
	
	)+;

DbmsAssign:
	((jplId+=(JPLID | DbmsKeys) (',' jplId+=(JPLID | DbmsKeys))*)
	(('=' | '==') (((DbmsDataTypes+=DbmsDataTypes) | (dbmsDecl+=DbmsDecl)) | ('(' DbmsStmt+=DbmsStmt ')')) (',')?)*);

DbmsDecl:
	dbmsKeys+=DbmsKeys ('(' DbmsDataTypes+=DbmsDataTypes (','? DbmsDataTypes+=DbmsDataTypes)* ')')?;

DbmsCommomn:
	('(' ((DbmsDataTypes+=DbmsDataTypes) | (dbmsDecl+=DbmsDecl)) (','? ((DbmsDataTypes+=DbmsDataTypes) |
	(dbmsDecl+=DbmsDecl)))* ')');

DbmsDataTypes:
	((jplId+=JPLID) | (str+=STRING) | (num+=NUMBER)) ('[' (jplId+=JPLID) ']')?;

JPLID:
	name=ID;

NUMBER:
	INT;

DbmsKeys:
	dbmsKeyWords+=(DBMS_KEYWORD1 | DBMS_KEYWORD2 | DBMS_KEYWORD3 | DBMS_KEYWORD4 | DBMS_KEYWORD5 | DBMS_KEYWORD6 |
	DBMS_KEYWORD7 | DBMS_KEYWORD8 | DBMS_KEYWORD9 |
	DBMS_KEYWORD10 | DBMS_KEYWORD11 | DBMS_KEYWORD12 | DBMS_KEYWORD13 | DBMS_KEYWORD14 | DBMS_KEYWORD15 | DBMS_KEYWORD16);

DBMS_KEYWORD1: ('sql'|'insert'|'into'|'values'|'execute'|'cursor'|'delete'|'case'|'update');

DBMS_KEYWORD2 : ('set'|'select'|'distinct'|'from'|'where'|'char'|'datetime'|'temp');

DBMS_KEYWORD3: ('group'|'by'|'having'|'like'|'exists'|'in'|'is'|'completion'|'run');

DBMS_KEYWORD4: ('any'|'all'|'some'|'and'|'or'|'left'|'right'|'inner'|'outer'|'join');

DBMS_KEYWORD5: ('float'|'int'|'long'|'create'|'table'|'database'|'drop'|'max'|'sum');

DBMS_KEYWORD6: ('between'| 'escape'|'order'|'asc'|'desc'|'not'|'null'|'avg'|'min');

DBMS_KEYWORD7: ('primary'|'foreign'|'key'|'references'|'like'|'escape'|'with'|'for');

DBMS_KEYWORD8: ('engine'|'close'|'column_names'| 'connection'|'close_all_connections');

DBMS_KEYWORD9: ('using'|'rpc'|'alias'|'binary'|'catquery'| 'to'|'separator'|'COUNT');

DBMS_KEYWORD10: ('heading'| 'on'|'off'|'column'|'names'|'format'|'occur'|'start');

DBMS_KEYWORD11: ('unique'|'connected'|'continue_bottom'|'continue_down'| 'onexit');

DBMS_KEYWORD12: ('continue_top'|'continue_up'|'store'|'file'|'onentry'|'onerror');

DBMS_KEYWORD13: ('application' |'autocommit'|'begin'|'browse'|'cancel'|'commit');

DBMS_KEYWORD14: ('rollback'|'user'|'database'|'datasource'|'server'|'procedure');

DBMS_KEYWORD15: ('declare'|'cursors'|'continue'|'stored_sub');

DBMS_KEYWORD16: ('save'|'flush'|'timeout'|'transaction');



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Antlr Error with grammar [message #1733002 is a reply to message #1733001] Mon, 23 May 2016 16:48 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
jplId+=JPLID should go in DbmsStmt
Re: Antlr Error with grammar [message #1733004 is a reply to message #1733002] Mon, 23 May 2016 16:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
my grammar should do that

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Antlr Error with grammar [message #1733016 is a reply to message #1733002] Mon, 23 May 2016 17:25 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Still it is not working. Maybe my other parts of grammar causing error.
Re: Antlr Error with grammar [message #1733018 is a reply to message #1733016] Mon, 23 May 2016 10:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
I still recommend you: solve your problems in small example grammar first

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Antlr Error with grammar [message #1733066 is a reply to message #1732994] Tue, 24 May 2016 07:56 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Can we have multiple .xtext grammar in single project?

If so can I access like this?

grammar com.prolifics.jpl.JPLEditor with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

generate jPLEditor "http://www.prolifics.com/jpl/JPLEditor"

generate dBMSEditor "http://www.prolifics.com/jpl/DBMSEditor"
Re: Antlr Error with grammar [message #1733067 is a reply to message #1733066] Tue, 24 May 2016 08:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
no what i mean is:

create a new project
test the grammar for one concept there.
it it works fine then integrate it.

create a new project for the next concept.
when it works fine integrate it and test if the combination is still fine

(ususally everything backed by unit tests)

this is the only way to get a propper grammar if it gets big and you are not that experienced


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Antlr Error with grammar [message #1733069 is a reply to message #1733067] Tue, 24 May 2016 08:33 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Yes I have created new project. My grammar is working fine now. How to integrate both the editors?
Re: Antlr Error with grammar [message #1733073 is a reply to message #1733069] Tue, 24 May 2016 09:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
i thing you want to have one editor right?
then combine (copy) the grammars into a single grammar and make sure your tests still work


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Antlr Error with grammar [message #1733075 is a reply to message #1733073] Tue, 24 May 2016 09:14 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
I did it. If I combine both the grammar it is not working
Re: Antlr Error with grammar [message #1733078 is a reply to message #1733075] Tue, 24 May 2016 09:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
then you have to analzye why.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Antlr Error with grammar [message #1733228 is a reply to message #1733078] Wed, 25 May 2016 14:44 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

Can anybody tell any how to write a terminal rule starts with 'start' followed by any text but once a newline entered that should be end that rule?

terminal NOTE: 'NOTES' -> ('\r'? '\n')+

terminal WS : (' '|'\t'| ('\\'(' '* '\r'? '\n')))+;

NOTES hgajgjhfgjg fgsuakghjkbdfgh ngjdhgasj dgh

I have entered enter after 'dgh' then that should be end of that rule.

I can have continue of text in the next line like

NOTES hgajgjhfgjg fgsuakghjkbdfgh ngjdhgasj \
hegfhajkfhjdfgn fjohgkdslj dgh \
hfjdhjhf

Here in this case 'hfjdhjhf' is ending of the terminal rule.
Re: Antlr Error with grammar [message #1733232 is a reply to message #1733228] Wed, 25 May 2016 15:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
Hi,

i dont know if this will work with your other stuff or your ws rule.
but this works for me

terminal NOTE:
	'NOTES' (('\\\r\n') | ('\\\n') | !('\n' | '\r'))*;


the idea should be clear


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Antlr Error with grammar [message #1733240 is a reply to message #1733232] Wed, 25 May 2016 16:04 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Yes it is working. Excellent!!!!

Could you please explain how this terminal rule is working?
Re: Antlr Error with grammar [message #1733242 is a reply to message #1733240] Wed, 25 May 2016 16:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
Well it says after the start word all can come that is not \r\n - or a backslash followed by a newline

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Antlr Error with grammar [message #1733244 is a reply to message #1733242] Wed, 25 May 2016 16:35 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
But if I want allow space after \ character. what should I do?
Re: Antlr Error with grammar [message #1733245 is a reply to message #1733244] Wed, 25 May 2016 16:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
Add it as well. To digg it out is your task sry

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Antlr Error with grammar [message #1733247 is a reply to message #1733245] Wed, 25 May 2016 16:47 Go to previous message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi
This is the solution.

terminal NOTE:
'NOTES' (('\\'(' '* '\r'? '\n')) | !('\n' | '\r'))*
Previous Topic:Real business benefits of Xtext
Next Topic:Terminal rule keywords highlighting
Goto Forum:
  


Current Time: Sat Nov 09 03:18:10 GMT 2024

Powered by FUDForum. Page generated in 0.06701 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top