grammar

Build symbol table from grammar [closed]

ⅰ亾dé卋堺 提交于 2019-11-27 05:37:23
I am trying to build a symbol table from my grammar (done with antlr) by using eclipse. However I don't know by what to begin. I think I read somewhere that you would need the parser and lexer generated by antlr to do that. Does someone know an easy example so that I can understand how it works please ? A symbol table is just a versioned map of id's to values. This is one solution, using a push and pop of scopes as the versioning mechanism -- push a scope on entry of a scope defining rule and pop on exit. package net.certiv.metal.symbol; import java.util.ArrayList; import java.util

Is HTML a context-free language?

一个人想着一个人 提交于 2019-11-27 05:10:23
问题 Reading some related questions made me think about the theoretical nature of HTML. I'm not talking about XHTML-like code here. I'm talking about stuff like this crazy piece of markup, which is perfectly valid HTML(!) <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html<head> <title// <p ltr<span id=p></span</p> </> So given the enormous complexity that SGML injects here, is HTML a context-free language? Is it a formal language anyway? With a grammar? What about HTML5? I'm new to the

What is a Context Free Grammar?

左心房为你撑大大i 提交于 2019-11-27 04:59:06
问题 Can someone explain to me what a context free grammar is? After looking at the Wikipedia entry and then the Wikipedia entry on formal grammar, I am left utterly and totally befuddled. Would someone be so kind as to explain what these things are? I am wondering this because I wish to investigate parsing, and also on the side, the limitation of a regex engine. I'm not sure if these terms are directly programming related, or if they are related more to linguistics in general. If that is the case

What is the language of this deterministic finite automata?

时光怂恿深爱的人放手 提交于 2019-11-27 04:55:33
Given: I have no idea what the accepted language is. From looking at it you can get several end results: 1.) bb 2.) ab(a,b) 3.) bbab(a, b) 4.) bbaaa Grijesh Chauhan How to write regular expression for a DFA In any automata, the purpose of state is like memory element. A state stores some information in automate like ON-OFF fan switch. A Deterministic-Finite-Automata(DFA) called finite automata because finite amount of memory present in the form of states. For any Regular Language(RL) a DFA is always possible. Let's see what information stored in the DFA (refer my colorful figure). ( note: In

How to identify whether a grammar is LL(1), LR(0) or SLR(1)?

狂风中的少年 提交于 2019-11-27 04:09:43
问题 How do you identify whether a grammar is LL(1), LR(0), or SLR(1)? Can anyone please explain it using this example, or any other example? X → Yz | a Y → bZ | ε Z → ε 回答1: To check if a grammar is LL(1), one option is to construct the LL(1) parsing table and check for any conflicts. These conflicts can be FIRST/FIRST conflicts, where two different productions would have to be predicted for a nonterminal/terminal pair. FIRST/FOLLOW conflicts, where two different productions are predicted, one

Which type of quotes we should use in css background url (“…”)? Single, double or no quote needed? [duplicate]

馋奶兔 提交于 2019-11-27 04:06:24
问题 This question already has answers here : Is quoting the value of url() really necessary? (7 answers) Closed 5 years ago . this background:url(http://url); this background:url("http://url"); or this background:url('http://url'); 回答1: The URL bits of all three of your examples are valid CSS, according to the CSS specification. Note that the spec identifies some characters in a URL which will need to be escaped with a backslash if present in an unquoted URI, such as parentheses, commas, white

Testing ANTLR Grammar

点点圈 提交于 2019-11-27 03:31:15
问题 So I've been making a grammar in Eclipse with ANTLR v3.4 and I've made one that works and I want to make sure when I edit it everything still works. I can go into the interpretter everytime but that seems like a huge waste of time. Questions: I've read about gunit but the link it gives to download gUnit: ( http://antlr.org/hudson/job/gUnit/org.antlr$gunit/lastSuccessfulBuild/ ) doesn't work. How can I get gUnit. What is the best way to test grammars? Is it actually gUnit or should I just do

English grammar for parsing in NLTK

删除回忆录丶 提交于 2019-11-27 03:06:21
Is there a ready-to-use English grammar that I can just load it and use in NLTK? I've searched around examples of parsing with NLTK, but it seems like that I have to manually specify grammar before parsing a sentence. Thanks a lot! You can take a look at pyStatParser , a simple python statistical parser that returns NLTK parse Trees. It comes with public treebanks and it generates the grammar model only the first time you instantiate a Parser object (in about 8 seconds). It uses a CKY algorithm and it parses average length sentences (like the one below) in under a second. >>> from stat_parser

Why isn't this a syntax error in python?

强颜欢笑 提交于 2019-11-27 03:01:43
问题 Noticed a line in our codebase today which I thought surely would have failed the build with syntax error, but tests were passing so apparently it was actually valid python (in both 2.x and 3). Whitespace is sometimes not required in the conditional expression: >>> 1if True else 0 1 It doesn't work if the LHS is a variable: >>> x = 1 >>> xif True else 0 File "<stdin>", line 1 xif True else 0 ^ SyntaxError: invalid syntax But it does seem to still work with other types of literals: >>> {'hello

How to get all captures of subgroup matches with preg_match_all()? [duplicate]

空扰寡人 提交于 2019-11-27 01:49:50
This question already has an answer here: Get repeated matches with preg_match_all() 6 answers Update/Note: I think what I'm probably looking for is to get the captures of a group in PHP. Referenced: PCRE regular expressions using named pattern subroutines. (Read carefully:) I have a string that contains a variable number of segments (simplified): $subject = 'AA BB DD '; // could be 'AA BB DD CC EE ' as well I would like now to match the segments and return them via the matches array: $pattern = '/^(([a-z]+) )+$/i'; $result = preg_match_all($pattern, $subject, $matches); This will only return