I've written a Lex program for identifying tokens but while I'm running it it's showing an error [closed] - flex-lexer

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
My Code:
%{
#include<stdio.h>
%}
%%
"int"|"char"|"double"|"void"|"main" {printf("\n%s is a keyword",yytext);}
^[a - z A - Z _][a - z A - Z 0 - 9 _] * {printf("\n%s is an identifier",yytext);}
^[-+]?[0-9]* {printf(}\n%s is an integer",yytext);}
^[-+]?[0-9]*[.][0-9]+$ {printf("\n%s is a floating number",yytext);}
"+"|"-"|"*"|"/"|"%"|"//" {printf("\n%s is an arithmetic operator",yytext);}
">"|"<"|">="|"<="|"="|"=="|"<>" {printf("\n%s is a relational operator",yytext);}
.;
%%
int yywrap()
{
return 1;
}
main()
{
printf("Enter a String:\n");
yylex();
}
This is the Code I've written. I'm getting an error while compiling it and I'm not sure what it is. Can you please take a look at it and say how to fix it. Thank you.

Your code doesn't compile because there is a missing " in line ^[-+]?[0-9]* {printf(}\n%s is an integer",yytext);} (at the beginning of the printf's argument).
Flex says it found an EOF which means "End Of File". It found an "opening" " and it was looking for a matching closing " but it encountered end of the file first.
You should also pay attention to whitespaces in lex patterns.
Those two are not two are not equivalent:
^[a - z A - Z _][a - z A - Z 0 - 9 _] *
^[a-zA-Z_][a-zA-Z0-9_]*

Related

Solidity Error :: ParserError: Expected ',' but got 'Number' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
Hiii, I need help
Getting parser error here in the line
require(msg.value > o.1 ether);
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Lottery{
address public manager;
address[] public players;
constructor(){
manager=msg.sender;
}
function enter() public payable{
require(msg.value > o.1 ether); //getting error here
players.push(msg.sender);
}
}
You have a typo, using the letter o instead of the number 0.
Corrected line:
require(msg.value > 0.1 ether);

Max intensity projection ImageJ from selected slices [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to write macro to pick up slices which I would like to include in my MIP. So far it looks like this:
LowerStack = getNumber("prompt", 10);
UpperStack = getNumber("prompt", 10);
run("Z Project...", "start=" + LowerStack) ("stop=" + UpperStack) ("projection=[Max Intensity]");
It recognizes the Lower slice which I want to pick up, but not the upper one.
Any suggestions on what do I do wrong?
The syntax of the third line is incorrect. This works:
LowerStack = getNumber("Lower", 10);
UpperStack = getNumber("Upper", 10);
run("Z Project...", "start=" + LowerStack + " stop=" + UpperStack + " projection=[Max Intensity]");
Note that I also changed the string in the two prompts because you would likely get an error by them not being unique.

Decimal value is not recognized by F# console [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm practicing F# for the first time and I thought I'd try to make a program that would calculate the areas of different kinds of shapes. However, the portion that finds the area of a circle is giving me a lot of trouble.enter code here
elif stringInput = "2" then
let PI = 3.14156
printfn "What is the circle's radius: "
let radiusString = System.Console.ReadLine()
let radiusInt = radiusString |> float
let cirlceArea = (radiusInt * radiusInt) * PI
printfn "The area of the circle is : %d" cirlceArea
I'm sure it has something to do with the radiusString |> float part of the code, but nothing I've tried works and I've had no luck in finding any examples that can help. What can I do?
Ok I just found out the problem was that I was using %d instead of %f

Why is this haskell function giving me a parse error? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to say if the desired location in the field is 1 return true otherwise return false. Why is this code not working?
fireShot :: Coordinate -> Field -> Bool
fireShot coord Shipfield
| nth ( fst(coord)((nth snd(coord)) ShipField) == 1 = True
| otherwise = False
The brackets in the guard are not balanced, you open five brackets, and you close four brackets. Furthermore variables start with a lowercase, so it should (probably) be shipfield, not Shipfield.
I think it might be better to use pattern matching to obtain the first and second coordinate, since this will make the code more clean. You furthermore do not need guards to return True and False. You can replace the function with:
fireShot :: Coordinate -> Field -> Bool
fireShot (x,y) shipfield = nth x (nth y shipfield) == 1

Exponential Moving Average - Ruby [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I've been using the simple_statistics gem, but im looking to calculate the EMA on the last x records. For example (when calculating WMA)
#stockticker.ema10 = s.stocktickers.last(10).map(&:current_price).map{|f| f.to_f}.wma
I was wondering if anyone can provide advise on how I got about calculating the EMA in rails?
It looks like the Moving Averages gem might be what you're looking for. Here is a copy of their exponential_moving_average method for reference as well.
class Array
def exponential_moving_average(idx=nil, tail=nil)
idx, tail = idx_and_tail_or_defaults(idx, tail)
valid_for_ma(idx, tail)
alpha = 2.0 / (tail + 1)
n = (1..tail).to_a.map{|tidx| (1 - alpha) ** (tidx - 1) * self[idx - tidx + 1]}.sum
d = (1..tail).to_a.map{|tidx| (1 - alpha) ** (tidx - 1)}.sum
n / d
end
alias_method :ema, :exponential_moving_average
end
I am the developer of Statsample-timeseries gem which is an extension of Statsample, an advance statistical suite in Ruby. It has quite many statistical methods (including EMA) which you can perform on your data.
If you need any assistance, I will be very happy to help out. :)

Resources