lexical-analysis

How do i implement If statement in Flex/bison

蹲街弑〆低调 提交于 2019-12-29 11:41:11
问题 I dont get the error, please can you help me out, here is the .l and .y file.thanks. %{ #include "ifanw.tab.h" extern int yylval; %} %% "=" { return EQ; } "!=" { return NE; } "<" { return LT; } "<=" { return LE; } ">" { return GT; } ">=" { return GE; } "+" { return PLUS; } "-" { return MINUS; } "*" { return MULT; } "/" { return DIVIDE; } ")" { return RPAREN; } "(" { return LPAREN; } ":=" { return ASSIGN; } ";" { return SEMICOLON; } "IF" { return IF; } "THEN" { return THEN; } "ELSE" { return

In which situation stringLit in StandardTokenParsers doesn't work?

本小妞迷上赌 提交于 2019-12-25 04:43:31
问题 I am writing a parser in which an arithmetic operation is going to be parsed. this arithmetic operation contains variables as well for instance: var1+1 The parser is as follow: package org.pvamu.hadoop.image; import org.apache.spark.serializer.{KryoSerializer, KryoRegistrator} import java.nio.file.Files; import java.io.File; import scala.util.parsing.combinator.lexical._ import scala.util.parsing.combinator.token.StdTokens import scala.util.parsing.combinator.lexical.StdLexical import scala

How to solve an error related to creating parser from regex?

落爺英雄遲暮 提交于 2019-12-25 03:12:25
问题 I am writing a parser using StandardTokenParsers in Scala. Need to create a regex parser to parse a path. I have tested the regex works fine but sending it to a function to parse it, the program gives an error that I am not able to figure it out! a part of code that is related to this parser is as follow: class InfixToPostfix extends StandardTokenParsers { import scala.util.matching.Regex import lexical.StringLit //parsing the path def regexStringLit(r: Regex): Parser[String] = acceptMatch(

Attribute access on int literals

倖福魔咒の 提交于 2019-12-24 13:26:17
问题 >>> 1 .__hash__() 1 >>> 1.__hash__() File "<stdin>", line 1 1.__hash__() ^ SyntaxError: invalid syntax It has been covered here before that the second example doesn't work because the int literal is actually parsed as a float. My question is, why doesn't python parse this as attribute access on an int, when the interpretation as a float is a syntax error? The docs section on lexical analysis seem to suggest whitespace only required when other interpretations are ambiguous, but perhaps I'm

Excluding certain elements from a specified set in Parsing Expressive Grammar (PEG.js)?

廉价感情. 提交于 2019-12-24 12:11:20
问题 I am writing a lexer for Haskell using JavaScript and Parsing Expression Grammar, the implementation I use being PEG.js. I have a problem with making it work for reserved words, as demonstrated in a simplified form here: program = ( word / " " )+ word = ( reserved / id ) id = ( "a" / "b" )+ reserved = ( "aa" ) The point here is to get a series of tokens that are either arbitrary sequences of a:s and/or b:s or the sequence "aa", and they are separated by spaces. What I really get is either

PLY - return multiple tokens

旧街凉风 提交于 2019-12-24 03:34:34
问题 AFAIK the technique for lexing Python source code is: When current line's indentation level is less than previous line's, produce DEDENT. Produce multiple DEDENTs if it is closing multiple INDENTs. When end of input is reached, produce DEDENT(s) if there's unclosed INDENT(s). Now, using PLY: How do I return multiple tokens from a t_definition? How do I make a t_definition that's called when EOF is reached? Simple \Z doesn't work -- PLY complains that it matches empty string. 回答1: As far as I

Bison does not appear to recognize C string literals appropriately

杀马特。学长 韩版系。学妹 提交于 2019-12-23 02:46:09
问题 My problem is that I am trying to run a problem that I coded using a flex-bison scanner-parser. What my program is supposed to do is take user input (in my case, queries for a database system I'm designing), lex and parse, and then execute the corresponding actions. What actually happens is that my parser code is not correctly interpreting the string literals that I feed it. Here's my code: 130 insertexpr : "INSERT" expr '(' expr ')' 131 132 { 133 $$ = new QLInsert( $2, $4 ); 134 } 135 ; And

nlp - How to detect if a word in a sentence is pointing to a color/body part /vehicle

随声附和 提交于 2019-12-23 02:22:14
问题 So as the title suggests I would like to know if a certain word in a sentence is pointing to 1] A color The grass is green. Hence "green" is color 2] A body part Her hands are soft Hence "hands" is a body part 3] A vehicle I am driving my car on the causeway Hence "car" is a vehicle In similar problems, parsers are one of the possible effective solutions. Stanford parser for example was suggested to a similar question How to find if a word in a sentence is pointing to a city Now the problem

How do I lex this input?

六月ゝ 毕业季﹏ 提交于 2019-12-22 10:44:21
问题 I currently have a working, simple language implemented in Java using ANTLR. What I want to do is embed it in plain text, in a similar fashion to PHP. For example: Lorem ipsum dolor sit amet <% print('consectetur adipiscing elit'); %> Phasellus volutpat dignissim sapien. I anticipate that the resulting token stream would look something like: CDATA OPEN PRINT OPAREN APOS STRING APOS CPAREN SEMI CLOSE CDATA How can I achieve this, or is there a better way? There is no restriction on what might

How to turn a token stream into a parse tree [closed]

随声附和 提交于 2019-12-22 06:59:03
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I have a lexer built that streams out tokens from in input but I'm not sure how to build the next step in the process - the parse tree. Does anybody have any good resources or examples on how to accomplish this? 回答1: I would really recommend http://www.antlr.org/ and of course the classic Dragon Compilers book.