Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Antlr Error with grammar(Antlr Error with grammar)
Antlr Error with grammar [message #1732994] Mon, 23 May 2016 11:37 Go to next message
Eclipse UserFriend
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 11:50 Go to previous messageGo to next message
Eclipse UserFriend
Please share a minimal but complete grammar that reproduces your problem
Re: Antlr Error with grammar [message #1732997 is a reply to message #1732995] Mon, 23 May 2016 12:09 Go to previous messageGo to next message
Eclipse UserFriend
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 12:40 Go to previous messageGo to next message
Eclipse UserFriend
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');

Re: Antlr Error with grammar [message #1733002 is a reply to message #1733001] Mon, 23 May 2016 12:48 Go to previous messageGo to next message
Eclipse UserFriend
jplId+=JPLID should go in DbmsStmt
Re: Antlr Error with grammar [message #1733004 is a reply to message #1733002] Mon, 23 May 2016 12:47 Go to previous messageGo to next message
Eclipse UserFriend
my grammar should do that
Re: Antlr Error with grammar [message #1733016 is a reply to message #1733002] Mon, 23 May 2016 13:25 Go to previous messageGo to next message
Eclipse UserFriend
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 06:44 Go to previous messageGo to next message
Eclipse UserFriend
I still recommend you: solve your problems in small example grammar first
Re: Antlr Error with grammar [message #1733066 is a reply to message #1732994] Tue, 24 May 2016 03:56 Go to previous messageGo to next message
Eclipse UserFriend
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 04:05 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Antlr Error with grammar [message #1733069 is a reply to message #1733067] Tue, 24 May 2016 04:33 Go to previous messageGo to next message
Eclipse UserFriend
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 05:00 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Antlr Error with grammar [message #1733075 is a reply to message #1733073] Tue, 24 May 2016 05:14 Go to previous messageGo to next message
Eclipse UserFriend
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 05:21 Go to previous messageGo to next message
Eclipse UserFriend
then you have to analzye why.
Re: Antlr Error with grammar [message #1733228 is a reply to message #1733078] Wed, 25 May 2016 10:44 Go to previous messageGo to next message
Eclipse UserFriend
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 11:27 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Antlr Error with grammar [message #1733240 is a reply to message #1733232] Wed, 25 May 2016 12:04 Go to previous messageGo to next message
Eclipse UserFriend
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 12:34 Go to previous messageGo to next message
Eclipse UserFriend
Well it says after the start word all can come that is not \r\n - or a backslash followed by a newline
Re: Antlr Error with grammar [message #1733244 is a reply to message #1733242] Wed, 25 May 2016 12:35 Go to previous messageGo to next message
Eclipse UserFriend
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 12:44 Go to previous messageGo to next message
Eclipse UserFriend
Add it as well. To digg it out is your task sry
Re: Antlr Error with grammar [message #1733247 is a reply to message #1733245] Wed, 25 May 2016 12:47 Go to previous message
Eclipse UserFriend
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: Sun Mar 16 22:50:21 EDT 2025

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

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

Back to the top