glr

Additional syntax error message on GLR parser when syntax is ambiguous

南笙酒味 提交于 2020-01-06 20:53:29
问题 I am using Bison 2.7 to write a GLR parser and also turn on %error-verbose option. When I ran the parser, it gave me "syntax is ambiguous" error. Is there a way that Bison can give me more details on where/how the syntax is ambiguous? 回答1: If you are looking to produce meaningful error messages, you will probably need to craft your own function to report ambiguities. bison does give you a basic tool for this: the custom %merge function. As indicated in the manual (see the paragraphs at the

Bison: GLR-parsing of valid expression fails without error message

和自甴很熟 提交于 2020-01-04 06:12:40
问题 I'm working on a GLR-parser in GNU bison and I have the following problem: the language I'm trying to parse allows boolean expressions including relations (<,>,<=,...) and boolean composition (and, or, not). Now the problem is that the language also allows to have multiple arithmetic expressions on the right side of a relation... and they are composed using the same AND token that is used for boolean composition! This is a very dumb language-design, but I can't change it. So you can have a >

GLR_Lib.hs: Could not find module 'System'

烂漫一生 提交于 2019-12-25 02:53:40
问题 I am trying to generate a GLR parser from happy, but I am getting errors once the files are generated. Here is an example, ABC.y , so it's clear what I am trying: { module Main where } %name ps1 s1 %tokentype { ABC } %error { parseError } %token a { A } b { B } c { C } %% s1: a a a b {} | b s2 a {} s2: b a b s2 {} | c {} { data ABC = A | B | C parseError _ = error "bad" main = getContents >>= print . ps1 . lexer lexer ('a':xs) = A : lexer xs ETC } This example works just fine with happy ABC.y

Bison: distinguish variables by type / YYERROR in GLR-parsers

可紊 提交于 2019-12-24 21:17:46
问题 I'm working on a parser, using GNU bison, and I'm facing an interesting problem. My actual problem is a bit different and less interesting in general, so I will state it a bit differently, so that an answer would be more useful in general. I need to distinguish expressions depending on their type, like arithmetic expressions from string expressions. Their top-level nonterminals have some common ancestors, like statement : TOK_PRINT expression TOK_SEMICOLON {...} ; expression :

in Bison, how can I specity left associativity for a non-terminal?

人走茶凉 提交于 2019-12-11 09:28:36
问题 I have the following Bison grammar snippet: binary_op: BINARY_OP { ... } | '|' %prec BINARY_OP { ... } ; non_keyword_expr: non_keyword_expr binary_op non_keyword_expr %prec BINARY_SEND_PREC %dprec 2 { ... } ; | has overloaded meaning in my grammar, so I can't just return it as token BINARY_OP from my lexer. It could be a different token depending on context. If I use this as my input: 4 OR 5 OR 6 I can parse it successfully (OR is recognized as a BINARY_OP token by the lexer). If, however, my

why is `int test {}` a function definition in C language BNF

十年热恋 提交于 2019-12-07 03:37:13
问题 I'm interested in the famous The syntax of C in Backus-Naur Form and studied for a while, what confuse me is that some syntax looks wrong to me but is considered right according to the BNF. For example, int test {} , what's this? I think this is a ill syntax in C, but the truth is the BNF considered this a function definition: int -> type_const -> type_spec -> decl_specs test-> id -> direct_declarator -> declarator '{' '}' -> compound_stat decl_specs declarator compound_stat -> function

why is `int test {}` a function definition in C language BNF

依然范特西╮ 提交于 2019-12-05 06:52:44
I'm interested in the famous The syntax of C in Backus-Naur Form and studied for a while, what confuse me is that some syntax looks wrong to me but is considered right according to the BNF. For example, int test {} , what's this? I think this is a ill syntax in C, but the truth is the BNF considered this a function definition: int -> type_const -> type_spec -> decl_specs test-> id -> direct_declarator -> declarator '{' '}' -> compound_stat decl_specs declarator compound_stat -> function_definition I tried this with bison, it considered the input int test {} is a right form, but I tried this on