grammar

Troubles using Bison's recursive rules, and storing values using it

旧巷老猫 提交于 2021-01-29 20:02:40
问题 I am trying to make a flex+bison scanner and parser for Newick file format trees in order to do operations on them. The implemented grammar an explanation is based on a simplification of (labels and lengths are always of the same type, returned by flex) this example. This is esentially a parser for a file format which represents a tree with a series of (recursive) subtrees and/or leaves. The main tree will always end on ; and said tree and all subtrees within will contain a series of nodes

What is the NLTK FCFG grammar standard/specification?

无人久伴 提交于 2021-01-29 04:55:58
问题 NLTK (Natural Language Toolkit) lets you parse a FCFG grammar using nltk.FCFG.fromstring([grammar string here]). Where is the FCFG grammar format specification*? I googled it to death, but all I could find was this. *i.e. grammar language specification 回答1: From the demo: >>> from nltk import CFG >>> grammar = CFG.fromstring(""" ... S -> NP VP ... PP -> P NP ... NP -> Det N | NP PP ... VP -> V NP | VP PP ... Det -> 'a' | 'the' ... N -> 'dog' | 'cat' ... V -> 'chased' | 'sat' ... P -> 'on' |

How to reduce parser stack or 'unshift' the current token depending on what follows?

江枫思渺然 提交于 2021-01-28 17:43:30
问题 Given the following language described as: formally: (identifier operator identifier+)* in plain English: zero or more operations written as an identifier (the lvalue), then an operator, then one or more identifiers (the rvalue) An example of a sequence of operations in that language would be, given the arbitrary operator @ : A @ B C X @ Y Whitespace is not significant and it may also be written more clearly as: A @ B C X @ Y How would you parse this with a yacc-like LALR parser ? What I

Eliminating grammar ambiguity when a rule covers a subset of another

北城余情 提交于 2021-01-28 02:08:27
问题 I am trying to build a small bison grammar, but am having an issue with part of the definition. Functions can be called with any expression legal on the right side (expression_list in the grammar) as arguments. The issue arises because on the left side, functions can be defined by assigning to them (an identifier followed by a list of identifiers - assignment_expression and identifier_list in the grammar) My question is how I can eliminate the ambiguity in my grammar, since the statements

Grammar for json schema

て烟熏妆下的殇ゞ 提交于 2021-01-28 00:07:31
问题 I would like to write a validator for json files that conforms to the json schema paradigm. I've been looking for a grammar that describes json schema without any luck. Do you know if there is any formal description of the json schema specifications that I can use to write a parser? Thank you. f. 回答1: The meta-schema is at http://json-schema.org/schema The semantics are defined in http://json-schema.org/latest/json-schema-validation.html 来源: https://stackoverflow.com/questions/29435810

How do I create a DCG rule inverse to another in Prolog?

a 夏天 提交于 2021-01-04 06:40:43
问题 I am writing a Commodore BASIC interpreter in Prolog, and I am writing some DCGs to parse it. I have verified the DCGs below to work except for the variable one. My goal is this: for anything which isn't a boolean, integer, float, or a string, it's a variable. However, anything that I give it via phrase just results in no . bool --> [true]. bool --> [false]. integer --> [1]. % how to match nums? float --> [0.1]. string --> [Str], {atom_chars(Str, ['"' | Chars]), last(Chars, '"')}. literal -->

How do I create a DCG rule inverse to another in Prolog?

烈酒焚心 提交于 2021-01-04 06:39:29
问题 I am writing a Commodore BASIC interpreter in Prolog, and I am writing some DCGs to parse it. I have verified the DCGs below to work except for the variable one. My goal is this: for anything which isn't a boolean, integer, float, or a string, it's a variable. However, anything that I give it via phrase just results in no . bool --> [true]. bool --> [false]. integer --> [1]. % how to match nums? float --> [0.1]. string --> [Str], {atom_chars(Str, ['"' | Chars]), last(Chars, '"')}. literal -->

How do I create a DCG rule inverse to another in Prolog?

。_饼干妹妹 提交于 2021-01-04 06:39:26
问题 I am writing a Commodore BASIC interpreter in Prolog, and I am writing some DCGs to parse it. I have verified the DCGs below to work except for the variable one. My goal is this: for anything which isn't a boolean, integer, float, or a string, it's a variable. However, anything that I give it via phrase just results in no . bool --> [true]. bool --> [false]. integer --> [1]. % how to match nums? float --> [0.1]. string --> [Str], {atom_chars(Str, ['"' | Chars]), last(Chars, '"')}. literal -->