recursive-descent

How to encode FIRST & FOLLOW sets inside a compiler

安稳与你 提交于 2019-12-24 10:47:50
问题 I am writing a compiler for a compiler design course that I am taking and I am currently at the Syntax Analysis where I need to write a parser. I need to have the FIRST and FOLLOW sets to handle any errors that may appear in the source text. I have precalculated the FIRST and FOLLOW sets for all of the non-terminals in my grammar but I am having trouble deciding where I should actually encode them inside of my program. Should I place them in a map where the key is the name of the non-terminal

Describe recursive grammar with type aliases

*爱你&永不变心* 提交于 2019-12-24 02:37:07
问题 How can I describe this recursive grammar with type aliases: type FieldValue = Seq[String] :+: String :+: Int :+: Long :+: CNil type FieldLeaf = FieldValue :+: SubField :+: CNil type SubField = Seq[Field] type Field = (String, FieldLeaf) As it stands, the Scala compiler (2.12.1) gives me: Error:(14, 25) illegal cyclic reference involving type FieldLeaf type Field = (String, FieldLeaf) PS the context of this is parsing a recursive grammar with fastparse. Edit (in response to

resolving logical operations - AND, OR, looping conditions dynamically

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 09:41:08
问题 I have an incoming records filter stored with the logical clause as given below. Acct1 = 'Y' AND Acct2 = 'N' AND Acct3 = 'N' AND Acct4 = 'N' AND Acct5 = 'N' AND ((Acct6 = 'N' OR Acct7 = 'N' AND Acct1 = 'Y') AND Formatted= 'N' AND Acct9 = 'N' AND (Acct10 = 'N' AND Acct11 = 'N') AND EditableField= 'N' ) My data input to this clause will be from Csv file as below. Country,Type,Usage,Acct1,Acct2,Acct3,Acct4,Acct5,Acct6,Acct7,Formatted,Acct9,Acct10,Acct11,EditableField USA,Premium,Corporate,Y,N,Y

Rename files to lowercase in Powershell

五迷三道 提交于 2019-12-20 09:49:52
问题 I am trying to rename a bunch of files recursively using Powershell 2.0. The directory structure looks like this: Leaflets + HTML - File1 - File2 ... + HTMLICONS + IMAGES - Image1 - Image2 - File1 - File2 ... + RTF - File1 - File2 ... + SGML - File1 - File2 ... I am using the following command: get-childitem Leaflets -recurse | rename -newname { $_.name.ToLower() } and it seems to rename the files, but complains about the subdirectories: Rename-Item : Source and destination path must be

Is there an easy way to chunk a text file into brace-balanced sections?

十年热恋 提交于 2019-12-20 03:06:51
问题 I'm trying to parse some data out of a file using Perl & Parse::RecDescent. I can't throw the full data file at the perl script because RecDescent will take days poring over it. So I split up the huge datafile into RD-sized chunks to reduce the runtime. However, I need to extract sections within balanced brackets and the routine I have now is not robust (it depends too much on the position of the final close-bracket from a newline). Example: cell ( identifier ) { keyword2 { }; ... keyword3 {

Recursive Descent precedence parsing missing prefix expression

寵の児 提交于 2019-12-11 08:18:55
问题 I'm building a simple language parser, and having an issue with lower precedence prefix expressions. Here's an example grammar: E = E5 E5 = E4 'OR' E4 | E4 E4 = E3 'AND' E3 | E3 E3 = 'NOT' E3 | E2 E2 = E1 '==' E1 | E1 E1 = '(' E ')' | 'true' | 'false' However, this grammar doesn't work correctly for the NOT , if it's used as the RHS of a higher precedence infix operator, i.e.: true == NOT false This is due to the == operator requiring E1 on the RHS, which cannot be a NOT operation. I'm unsure

Parser in Ruby: dealing with sticky comments and quotes

房东的猫 提交于 2019-12-11 04:19:42
问题 I am trying to make a recursive-descent parser in Ruby for a grammar, which is defined by the following rules Input consists of white-space separated Cards starting with a Stop-word , where white-space is regex /[ \n\t]+/ Card may consist of Keywords or/and Values also separated by white-space, which have card-specific order/pattern All Stop-words and Keywords are case-insensitive, i.e.: /^[a-z]+[a-z0-9]*$/i Value can be a double-quoted string , which may be not separated from other words by

Recursive Descent precedence parsing - matching lower precedence prefix expressions

我们两清 提交于 2019-12-11 03:06:54
问题 Note: this is a more detailed version of Recursive Descent precedence parsing missing prefix expression I'm building a simple language parser, and having an issue with lower precedence prefix expressions. Here's an example grammar: E = E8 E8 = E7 'OR' E8 | E7 E7 = E6 'XOR' E7 | E6 E6 = E5 'AND' E6 | E5 E5 = 'NOT' E5 | E4 E4 = E3 '==' E4 | E3 '!=' E4 | E3 E3 = E2 '<' E3 | E2 '>' E3 | E2 E2 = E1 '+' E2 | E1 '-' E2 | E1 '*' E2 | E1 '+' E2 | E1 E1 = '(' E ')' | 'true' | 'false' | '0'..'9' However

Evaluating a math expression with variables. (java 8)

…衆ロ難τιáo~ 提交于 2019-12-10 18:07:36
问题 I would like additional help on a answer to this question, Evaluating a math expression given in string form. The user @Boann answered the question with a very interesting algorithm that he also points out can be altered to accept variables. I've managed to alter it and get it to work, but dont know how he separates the compilation and evaluation . Here's my code: import java.util.HashMap; import java.util.Map; public class EvaluateExpressionWithVariabels { @FunctionalInterface interface

Recursive descent parser questions

若如初见. 提交于 2019-12-10 13:23:15
问题 I have two questions about how to write a recursive descent parser: The first is what when you have a nonterminal that can match one of a few different nonterminals? How do you check which way is correct? Second, how do you build an AST? Using YACC, I can just write a piece of code to execute for every instance of a nonterminal and it has special variables which refer to the "values" of the rules. How do you do a similar thing in a recursive descent parser? 回答1: You try them in order, then