Hi

As a thesis student , it is good to have some background knowledge on
parsers and compilers;
here is THE classic book on the subject:

 https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools
https://github.com/Jiantastic/c-to-mips-compiler/blob/master/Books/Dragon%20Book%20-%20Compilers%20Principles%20Techniques%20and%20Tools%20(2nd%20Edition).pdf


2018-02-07 11:51 GMT+01:00 Rob Vesse <[email protected]>:

> You run the grammar script directly at a shell prompt, this requires a
> *nix OS, it is not supported under Windows i.e.
>
> > ./grammar
>
> It then automatically applies the C pre-processor to the master.jj file to
> generate the other .jj files and then calls javacc over those to generate
> the Java parsers. I would suggest reading the script in the text editor of
> your choice to see what it is doing. You'll need both cpp and javacc
> present on your PATH for this to work.
>
> Note that USING is already a keyword in SPARQL Update which is part of the
> combined SPARQL 1.1 grammar so I would suggest that you avoid overloading
> existing keywords!
>
> Rob
>
> On 07/02/2018, 10:34, "Berkin Özdemir Bengisu" <
> [email protected]> wrote:
>
>     Thanks a lot for all the help! I am considering adding some decision
>     keywords such as USING or BASED ON, then define my functions according
> to
>     the tokens after those keywords.
>
>     Could you please explain the "preprocessing the master.jj using grammar
>     script" part a bit more detailed?  I was unable to run the grammar
> script
>     to create the other jj files. The basic cpp run over grammar fails
> since
>     the file doesn't have any extension.
>
>     Many Thanks
>
>     2018-02-06 11:53 GMT+02:00 Rob Vesse <[email protected]>:
>
>     > This is entirely possible but it is not at all trivial. We have been
> doing
>     > this for several years to add several extensions to the language. The
>     > extent of the necessary changes Will vary depending on what your
> extensions
>     > are intended to do.
>     >
>     > To start with the grammar. You can find the input files in a Grammer/
>     > sub-directory within the ARQ module.  master.jj is the main file and
> uses C
>     > style #ifdef to add/remove language features depending on the Target
>     > language. So the best approach is to modify master.jj and insert
> your own
>     > #ifdef sections with your grammar rules.
>     >
>     > The grammar script pre-processes this file into the other *.jj files
> as
>     > #ifdef's are not valid in JavaCC inputs. You will need to modify the
> script
>     > to be able to generate your newly defined grammar.
>     >
>     > What else you need to do will depend on the language features you are
>     > creating. If all the keywords you introduce are shorthand for
> existing
>     > language features then the grammar is the main piece you need.
>     >
>     > However in order for your new parser to be used you will need to
> register
>     > it as a language. Doing this requires you to implement the
>     > SPARQLParserFactory interface which has
>     > an accept(Syntax) and a create(Syntax) method. The former indicates
>     > whether your factory can parse a given syntax and the latter creates
> a
>     > parser for your language from which you can simply return the JavaCC
>     > generated SPARQLParserYourLang class. You'll probably want to define
> your
>     > own Syntax Constant so that you can create queries in your language
> by
>     > calling QueryFactory.create(query, YourSyntax), note that you will
> need to
>     > call SPARQLParserRegistry.addFactory(YourSyntax, YourParserFactory)
> for
>     > this to work.
>     >
>     > If your language extensions require new operators then you have
>     > significantly more work on your hands. I can go into everything
> required
>     > for that as well if desired in a future email?
>     >
>     > Another thing to consider is whether you want queries using your new
>     > language features to round trip i.e. string -> parsed query ->
> string? This
>     > can also require quite a bit of work depending upon how invasive your
>     > language features are. Again probably a separate email.
>     >
>     > Good luck, please send further questions to the list as you have
> them and
>     > we will do our best to answer them
>     >
>     > Rob
>     >
>     > On 05/02/2018, 20:42, "Berkin Özdemir Bengisu" <
>     > [email protected]> wrote:
>     >
>     >     Hello,
>     >
>     >     I am using jena 3.6.0 and I would like to extend the sparql 1.1
> grammar
>     >     with some new keywords. Could you please help me what would be
> the
>     > best way
>     >     to start with?
>     >
>     >     - As I understood, the grammar is generated by javaCC but I was
> unable
>     > to
>     >     find any documentation or any main classes that actually
> generate the
>     >     grammar. Are grammar classes generated as an out source and then
> added
>     > to
>     >     the project?
>     >
>     >     I would be really glad if you could guide me on this.
>     >
>     >     Best
>     >     Berkin
>     >
>     >
>     >
>     >
>     >
>     >
>
>
>
>
>
>


-- 
Jean-Marc Vanel
http://www.semantic-forms.cc:9111/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me#subject
<http://www.semantic-forms.cc:9111/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me>
Déductions SARL - Consulting, services, training,
Rule-based programming, Semantic Web
+33 (0)6 89 16 29 52
Twitter: @jmvanel , @jmvanel_fr ; chat: irc://irc.freenode.net#eulergui

Reply via email to