ANTLR named function arguments / parameters in any order -


I'm looking for a way to designated function arguments / standards appear in any sequence in ANTLR . Anyone know if there is syntax in an ANTLR parser expression to ignore the command

Say a function is in the foo language that can take two named parameters : X and y . Since they have been given the parameter name, so I want them to pass in the function in any order:

  foo (x = 1, y = 2)   should be statutory 

  foo (y = 2, x = 1)  

Both should be statutory.

I can only list all parameter permutations in ANTLR, but I would have expected there would be a more elegant solution, especially since I can take some functions that take 5 parameters.

Any help would be greatly appreciated!

I am absolutely sure that nothing has been made in the ATLR so that it can handle it. . But you can do simple sprinkle to rebuild some regular programming logic parameters in your grammar

Here is a small demo grammar:

  grammar NF; @ Pars :: header {package antillesmo; Import java.util.HashMap; Import java.util.HashSet; Import java.util.Arrays; } @llexor :: header {package antillesmo; } Paras: Concat +; Concat: 'concat' '(' k1 = key '=' v1 = value ',' k2 = key '=' v2 = value ',' k3 = key '=' v3 = value ')' {HashMap & LT; String, string & gt; Parameters = new Hashmap & lt; String, string & gt; (); Params.put ($ k1.text, $ v1.text); Params.put ($ k2.text, $ v2.text); Params.put ($ k3.text, $ v3.text); HashSet & LT; String & gt; Expected = New Hashet & lt; String & gt; (Arrays.asList (new string [] {"a", "b", "c"}))); If (! Params.keySet (.) Equals (expected)) {new runtime exception ("no soup for you!"); } System.out.println (params.get ("a") + params.get ("b") + params.get ("c")); }; Key: ('a' .. 'z') +; Value: ('a' .. 'z' | 'a' .. 'z' | '0' .. '9') +; Location: ('' '' \ t '|' \ r '|' '\ n') {$ channel = HIDDEN;};  

And a small class to test it:

  Package antidiDimo; Import org.antlr.runtime *; Public class NFDemo {Fixed zero test (string source) throws recognition recognition {ANTLRStringStream = new ANTLRStringStream (source); NFLX laser = new NFLX (in); Common Token Stream Token = New Common Token Stream (Lexer); NFPs parser = new NPPers (tokens); System.out.print (source + "- & gt;"); Parser.parse (); } Public static Zero main (string [] args) Recognition failure {test ("conat (A = 1, B = 2, C = 3)"); Test ("conat (b = 2, c = 3, a = 1)"); Test ("conat (c = 3, a = 1, b = 2)"); Test ("conat (c = 3, a = 1, x = 2)"); }}  

which produces the output:

  concat (a = 1, b = 2, c = 3) - & gt; 123 concat (B = 2, C = 3, A = 1) - & gt; 123 concat (c = 3, a = 1, b = 2) - & gt; 123 concat (c = 3, a = 1, x = 2) - & gt; Exception in thread "main" java.lang.RuntimeException: There is no soup for you! Antlrdemo.NFParser.concat (NFParser.java:137) at antlrdemo.NFParser.parse (NFParser.java:70) antlrdemo.NFDemo.test (NFDemo.java13) at antlrdemo.NFDemo.main on (at NFDemo.java: 20)  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -