ebnf

Rule precedence issue with grako

情到浓时终转凉″ 提交于 2019-12-01 09:23:22
I'm redoing a minilanguage I originally built on Perl (see Chessa# on github ), but I'm running into a number of issues when I go to apply semantics. Here is the grammar : (* integers *) DEC = /([1-9][0-9]*|0+)/; int = /(0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+)/ | DEC; (* floats *) pointfloat = /([0-9]*\.[0-9]+|[0-9]+\.)/; expfloat = /([0-9]+\.?|[0-9]*\.)[eE][+-]?[0-9]+/; float = pointfloat | expfloat; list = '[' @+:atom {',' @+:atom}* ']'; (* atoms *) identifier = /[_a-zA-Z][_a-zA-Z0-9]*/; symbol = int | float | identifier | list; (* functions *) arglist = @+:atom {',' @+:atom}*; function =

Is it easier to write a recursive-descent parser using an EBNF or a BNF?

自作多情 提交于 2019-12-01 08:29:07
I've got a BNF and EBNF for a grammar. The BNF is obviously more verbose. I have a fairly good idea as far as using the BNF to build a recursive-descent parser; there are many resources for this. I am having trouble finding resources to convert an EBNF to a recursive-descent parser. Is this because it's more difficult? I recall from my CS theory classes that we went over EBNFs, but we didn't go over converting them into a recursive-descent parser. We did go over converting BNF's into a recursive-descent parser. The reason I'm asking is because the EBNF is more compact. From looking at the EBNF

Is it easier to write a recursive-descent parser using an EBNF or a BNF?

心已入冬 提交于 2019-12-01 06:46:15
问题 I've got a BNF and EBNF for a grammar. The BNF is obviously more verbose. I have a fairly good idea as far as using the BNF to build a recursive-descent parser; there are many resources for this. I am having trouble finding resources to convert an EBNF to a recursive-descent parser. Is this because it's more difficult? I recall from my CS theory classes that we went over EBNFs, but we didn't go over converting them into a recursive-descent parser. We did go over converting BNF's into a

Rule precedence issue with grako

妖精的绣舞 提交于 2019-12-01 06:10:53
问题 I'm redoing a minilanguage I originally built on Perl (see Chessa# on github), but I'm running into a number of issues when I go to apply semantics. Here is the grammar: (* integers *) DEC = /([1-9][0-9]*|0+)/; int = /(0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+)/ | DEC; (* floats *) pointfloat = /([0-9]*\.[0-9]+|[0-9]+\.)/; expfloat = /([0-9]+\.?|[0-9]*\.)[eE][+-]?[0-9]+/; float = pointfloat | expfloat; list = '[' @+:atom {',' @+:atom}* ']'; (* atoms *) identifier = /[_a-zA-Z][_a-zA-Z0-9]*/; symbol =

Parsing of optionals with PEG (Grako) falling short?

北战南征 提交于 2019-12-01 03:52:54
问题 My colleague PaulS asked me the following: I'm writing a parser for an existing language (SystemVerilog - an IEEE standard), and the specification has a rule in it that is similar in structure to this: cover_point = [[data_type] identifier ':' ] 'coverpoint' identifier ';' ; data_type = 'int' | 'float' | identifier ; identifier = ?/\w+/? ; The problem is that when parsing the following legal string: anIdentifier: coverpoint another_identifier; anIdentifier matches with data_type (via its

Scala Parser Token Delimiter Problem

本秂侑毒 提交于 2019-11-30 19:20:34
I'm trying to define a grammar for the commands below. object ParserWorkshop { def main(args: Array[String]) = { ChoiceParser("todo link todo to database") ChoiceParser("todo link todo to database deadline: next tuesday context: app.model") } } The second command should be tokenized as: action = todo message = link todo to database properties = [deadline: next tuesday, context: app.model] When I run this input on the grammar defined below, I receive the following error message: [1.27] parsed: Command(todo,link todo to database,List()) [1.36] failure: string matching regex `\z' expected but `:'

Scala Parser Token Delimiter Problem

大城市里の小女人 提交于 2019-11-30 02:54:50
问题 I'm trying to define a grammar for the commands below. object ParserWorkshop { def main(args: Array[String]) = { ChoiceParser("todo link todo to database") ChoiceParser("todo link todo to database deadline: next tuesday context: app.model") } } The second command should be tokenized as: action = todo message = link todo to database properties = [deadline: next tuesday, context: app.model] When I run this input on the grammar defined below, I receive the following error message: [1.27] parsed:

How to write a parse for EBNF syntax?

只谈情不闲聊 提交于 2019-11-28 08:34:47
问题 I receive a task to parse a text which conforms to EBNF syntax. Is there any tool/library I can use? 回答1: ANTLR is the standard tool for parsing EBNF. See Good parser generator (think lex/yacc or antlr) for .NET? Build time only? here on SO. 来源: https://stackoverflow.com/questions/9645544/how-to-write-a-parse-for-ebnf-syntax

Converting EBNF to BNF

喜你入骨 提交于 2019-11-27 19:32:55
It's been a few years since my computer-language class and so I've forgotten the finer points of BNF's and EBNF's and I don't have a textbook next to me. Specifically, I've forgotten how to convert an EBNF into BNF. From what little I remember, I know that one of the main points is to convert { term } into <term> | <many-terms> . But I don't remember the other rules. I've tried to look this up online but I can only find links to either homework questions, or a small comment about converting terms with curly braces. I can't find an exhaustive list of rules that define the translation. 500 -

How to convert BNF to EBNF

心不动则不痛 提交于 2019-11-27 02:06:43
How can I convert this BNF to EBNF? <vardec> ::= var <vardeclist>; <vardeclist> ::= <varandtype> {;<varandtype>} <varandtype> ::= <ident> {,<ident>} : <typespec> <ident> ::= <letter> {<idchar>} <idchar> ::= <letter> | <digit> | _ EBNF or Extended Backus-Naur Form is ISO 14977:1996 , and is available in PDF from ISO for free * . It is not widely used by the computer language standards. There's also a paper that describes it, and that paper contains this table summarizing EBNF notation. Table 1: Extended BNF Extended BNF Operator Meaning ----------------------------------------------------------