So far, I was able to use pyparsing to parse ebnf grammars.
However, I wanted to try the following code sample but could not come up with
a good grammar.
global radius = 5
DrawCircle(radius)
{
radius = 10
DrawCircle(radius)
}
DrawCircle(radius)
The value of radius with in the scope should be 10, 5 otherwise.
Any help would be appreciated ?
Regards
Praveen
I was able to get the parser for the above code by running:
enclosed = Forward()
curls = nestedExpr('{', '}', content=enclosed)
enclosed << (OneOrMore(commands | ',' | curls))
I have a follow up question. I am used to write ebnf grammar using http://pyparsing.wikispaces.com/file/view/ebnf.py
Can I get some help identifying the ebnf for forward or equivalent of the above code ? or should I do outside ebnf ?
Regards
Praveen
Related
If I use epar ccdproc in imred >> ccdred >> ccdproc, I can put [261:280,1:1032] in biassec, which is in a old iraf code by my teacher:
ccdproc #list.all o//#list.all ccdtype='' overscan+ biassec=[261:280,1:1032]
But if I use the terminal, it will say:
SyntaxError: Too many positional parameters for task ccdproc
And if I put (261:280,1:1032), (261:280;1:1032) or (261:280 1:1032), it will also pop out SyntaxError. It seems that pyraf syntax is slightly different from iraf. What is the right parameter syntax?
Solved, "[261:280,1:1032]".
Add quotation marks
ccdproc #list.all o//#list.all ccdtype='' overscan+ biassec="[261:280,1:1032]"
zsh version 5.2
I'm attempting an array assignment using filename generation like so:
files=(/some/path/*/dir/myfile)
Indeed this is the way the zshoptions manual recommends to achieve what I want.
When no matches exist I want the array to be empty. Instead it's producing
no matches found: /some/path/*/dir/file
and the script terminates.
I've tried setting NULL_GLOB, CSH_NULL_GLOB and ensured NOMATCH is not set.
When matches do exist it works as expected.
Any help is appreciated.
Thank you in advance,
Wayne
Well of course I found the solution after posting my question.
For this to work EXTENDED_GLOB needs to be set as well as NULL_GLOB. Or a glob qualifier can be used so that NULL_GLOB only effects this particular expansion.
This is how to set NULL_GLOB for a single operation:
files=(/some/path/*/dir/myfile(N))
Hope that can help someone else who encounters this.
Wayne
I am pretty new to JavaCC, and I can't figure out how to create a conditional in a JavaCC grammar.
I have two tokens which are an ARROW ("->") and a RATE ("[double]"). In my grammar a RATE can go before, or after an ARROW.
How do I write the grammar to do basically this:
if nextToken is RATE:
r = Rate()
else if nextToken is ARROW:
ARROW
r = Rate()
etc.
Thanks for your help.
I have figured out an answer. I don't know if this is the best solution, but it is working.
I have:
(R = Rate() <ARROW>
| <ARROW> R = Rate())
I am a intern trying to write my first Syntax using Rascal.
While programming i ran into an error that my tutor, Riemer van Rozen, had never seen before. At the moment i am still trying to see if the problem is my code or a Rascal bug but i felt like i should report the error here.
The syntax used to parse normally and even after putting the code back the way it was before I added new stuff it still gives the same error.
My Syntax file
module Syntax
lexical Natural = [0-9]+ !>> [0-9] ;
lexical ID = [a-zA-Z][a-z0-9A-Z]* !>> [a-z0-9A-Z];
lexical String = "\"" ![\"]* "\"";
lexical Sym = [a-zA-Z.!##$%^&*];
lexical Mp = Sym*;
layout WhiteSpace = [\t-\n \r]* ;
start syntax CreatorData
= title: "title " ID title
| author: "author " ID author
| homepage: "homepage " ID homepage;
Parser
module Parser
import Syntax;
import AST;
import ParseTree;
public CreatorData load(str txt) = parse(#CreatorData, txt);
The Error
I hope someone can tell me where i am breaking my program or that i pointed out an unknown Rascal bug.
Call failed means that the call of parse failed, since the arguments you supplied, did not match any of the possible overloads of parse.
For your code, it looks like you also have an ADT called CreatorData. This is overlapping with the CreatorData syntax definition. There is a pattern documented in the tutor how to work around this challenge.
Not sure about your case, but often you can skip the ADT form, and just work on the concrete trees, but that might be something to explore in the future.
I am reading the tutorial of implementing kaleidoscope language on LLVM using ocaml. However, the given code lexer.ml doesn't compile...
There is a syntax error in the second line of the code
let rec lex = parser
(* Skip any whitespace. *)
| [< ' (' ' | '\n' | '\r' | '\t'); stream >] -> lex stream
Why is this happening? Thank you.
This is an old stream syntax, provided by camlp4. See the tutorial. Enabling the syntax support highly depends on your build system. Please, provide more information on that, and I will update the posting.