jflex

JFLEX AND CUP, cannot make it work correctly

大兔子大兔子 提交于 2021-01-29 01:42:48
问题 I'm working with jflex and cup, trying to make a html parser, but can't make it work correctly, Netbeans, the compile process dont stop, always continues, Can't add more "tokens" correctly in the parse tree, Also can't add space in "TEXTO" , this break the entire tree lexicoh.jlex package compiladorhtml; import java_cup.runtime.*; %% %class Lexer %line %column %cup %{ private Symbol symbol(int type) { return new Symbol(type, yyline, yycolumn); } private Symbol symbol(int type, Object value) {

JFLEX AND CUP, cannot make it work correctly

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 01:42:07
问题 I'm working with jflex and cup, trying to make a html parser, but can't make it work correctly, Netbeans, the compile process dont stop, always continues, Can't add more "tokens" correctly in the parse tree, Also can't add space in "TEXTO" , this break the entire tree lexicoh.jlex package compiladorhtml; import java_cup.runtime.*; %% %class Lexer %line %column %cup %{ private Symbol symbol(int type) { return new Symbol(type, yyline, yycolumn); } private Symbol symbol(int type, Object value) {

How to match the empty case in CUP parser grammar

你说的曾经没有我的故事 提交于 2019-12-24 06:30:00
问题 I am using CUP to generate a parser, and I want an empty file to be an acceptable program. I have tried add the empty case to my start symbol, based off the response to a similar question here. start with prog; /* The grammar rules */ prog ::= class_block:cb | class_block:cb stmts:sb | stmts:sb | // desired empty case ; Including the desired empty case gives me the following error: parser.java:516: error: incompatible types: Object cannot be converted to Symbol CUP$parser$result = parser

Parse tree generation with Java CUP

大憨熊 提交于 2019-12-22 08:07:03
问题 I am using CUP with JFlex to validate expression syntax. I have the basic functionality working: I can tell if an expression is valid or not. Next step is to implement simple arithmetic operations, such as "add 1". For example, if my expression is "1 + a", the result should be "2 + a". I need access to parse tree to do that, because simply identifying a numeric term won't do it: the result of adding 1 to "(1 + a) * b" should be "(1 + a) * b + 1", not "(2 + a) * b". Does anyone have a CUP

Matching Lua's “Long bracket” string syntax

安稳与你 提交于 2019-12-14 03:21:27
问题 I'm writing a jFlex lexer for Lua, and I'm having problems designing a regular expression to match one particular part of the language specification: Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs followed by another opening square bracket. So, an opening long bracket of level 0 is written as [[, an opening long bracket of level 1 is written as [=[, and so on

Parse EOF token in CUP

≡放荡痞女 提交于 2019-12-13 04:29:19
问题 I'm having trouble making my CUP parser parse the EOF token. I read in the documentation that using the %cup flag in my Jflex code implies that there is something present like this: %eofval{ return new java_cup.runtime.Symbol(<CUPSYM>.EOF); %eofval} %eofclose This is all good and well, but when I try the following first rule in my grammar (CUP file): program ::= program declaration EOF | /* Empty */ ; I get the error message that EOF is not declared by CUP. Error : java_cup.runtime.Symbol

Regex in jFlex with hardcoded exceptions

家住魔仙堡 提交于 2019-12-13 03:19:14
问题 I need a regex in jFlex to match a string literal, containing some characters, followed by a hyphen which is followed by a word. However, there are a few hardcoded exceptions. My jFlex version is 1.6.1 My regexes are: SUFFIXES = labeled|deficient ALPHANUMERIC = [:letter:]|[:digit:] AVOID_SUFFIXES = {SUFFIXES} | !({ALPHANUMERIC}+) WORD = ({ALPHANUMERIC}+([\-\/\.]!{AVOID_SUFFIXES})*) String "MXs12-labeled" should be tokenized into 'MXs12', '-', 'labeled' (hyphen caught by different regex later)

How do I use regular expression capturing groups with JFlex?

佐手、 提交于 2019-12-12 14:10:30
问题 Although this question is about JFlex, it probably applies to other scanner generators such as lex, flex as well. If I have some rule, how can I create a capturing group in part of that rule and use the result of that captured group as an argument to the code that gets called upon the rule matching? For example, let's say I had a simple rule to match an SGML tag: "<"[a-zA-Z]+">" {return new Token(Type.OPEN_TAG);} How could I capture the inner character part([a-zA-Z]+) and use it as an

In CUP: How to make something optional to parse?

 ̄綄美尐妖づ 提交于 2019-12-10 15:27:18
问题 PROC_DECL -> "proc" [ "ret" TYPE ] NAME "(" [ PARAM_DECL { "," PARAM_DECL } ] ")" "{" { DECL } { STMT } "}" This is the grammar for a Procedure declaration. How do you say that the "ret" TYPE is optional without making multiple cases? 回答1: Use another production, say ret_stmt, which can be either empty or contain a single return statement so in your .cup file you will have this productions: ret_stmt ::= // empty {: /*your action for empty return statement*/ :} // Single return statement |

Create abstract tree problem from parser

人盡茶涼 提交于 2019-12-08 05:53:55
问题 I need big help, I have two simple classes Tree and Node ( I put just interface to use less space on forum, I can easy modify those classes ), I also have flex file and parser file and need to create AST ( abstract syntax tree - to put tokens in Node objects and fill Tree in right way ). public class Tree { Node root; public void AddNode(Node n){} public void Evaluate(){} } public class Node { public String value; public int type; Node left, right; } This is parser file import java_cup